diff --git a/java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java b/java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java index 6df6f2a5cfec..0fbfa4a059f9 100644 --- a/java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java @@ -373,7 +373,7 @@ public class RedundantCastUtil { PsiType castType = typeElement.getType(); final PsiExpression innerOperand = ((PsiTypeCastExpression)expr).getOperand(); final PsiType operandType = innerOperand != null ? innerOperand.getType() : null; - if (!(castType instanceof PsiPrimitiveType)) { + if (!(castType instanceof PsiPrimitiveType) && !(topCastType instanceof PsiPrimitiveType)) { if (operandType != null && topCastType != null && TypeConversionUtil.areTypesConvertible(operandType, topCastType)) { addToResults((PsiTypeCastExpression)expr); } diff --git a/java/java-tests/testData/inspection/redundantCast/generics/BoxingTopCast/expected.xml b/java/java-tests/testData/inspection/redundantCast/generics/BoxingTopCast/expected.xml new file mode 100644 index 000000000000..4704d91e891d --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/BoxingTopCast/expected.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/generics/BoxingTopCast/src/BoxingTopCast.java b/java/java-tests/testData/inspection/redundantCast/generics/BoxingTopCast/src/BoxingTopCast.java new file mode 100644 index 000000000000..148422b00588 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/generics/BoxingTopCast/src/BoxingTopCast.java @@ -0,0 +1,20 @@ +class TestCasting +{ + public void testRedundantCast() throws Exception + { + Object o = getObject(); + double d = 0.0; + + if( o instanceof Integer ) + { + d = (double) (Integer)o; + } + + System.out.println( "d = " + d ); + } + + private Object getObject() + { + return new Integer(42); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast15Test.java b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast15Test.java index ca3065d27d14..4dd29648e055 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast15Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast15Test.java @@ -57,6 +57,11 @@ public class RedundantCast15Test extends InspectionTestCase { doTest(); } + public void testBoxingTopCast() throws Exception { + IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_7, getModule(), getTestRootDisposable()); + doTest(); + } + public void testIgnore() throws Exception { final RedundantCastInspection castInspection = new RedundantCastInspection(); castInspection.IGNORE_ANNOTATED_METHODS = true;