diff --git a/java/java-impl/src/com/intellij/codeInspection/miscGenerics/RedundantArrayForVarargsCallInspection.java b/java/java-impl/src/com/intellij/codeInspection/miscGenerics/RedundantArrayForVarargsCallInspection.java index 5c39405821d9..13f09cb8edd9 100644 --- a/java/java-impl/src/com/intellij/codeInspection/miscGenerics/RedundantArrayForVarargsCallInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/miscGenerics/RedundantArrayForVarargsCallInspection.java @@ -23,6 +23,7 @@ import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.util.TypeConversionUtil; import com.intellij.refactoring.util.InlineUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; @@ -108,8 +109,13 @@ public class RedundantArrayForVarargsCallInspection extends GenericsInspectionTo PsiParameter lastParameter = parameters[args.length - 1]; PsiType lastParamType = lastParameter.getType(); LOG.assertTrue(lastParamType instanceof PsiEllipsisType); - if (!(lastArg instanceof PsiNewExpression) || - !substitutor.substitute(((PsiEllipsisType)lastParamType).toArrayType()).equals(lastArg.getType())) { + if (!(lastArg instanceof PsiNewExpression)) { + return; + } + final PsiType substitutedLastParamType = substitutor.substitute(((PsiEllipsisType)lastParamType).toArrayType()); + final PsiType lastArgType = lastArg.getType(); + if (lastArgType == null || !lastArgType.equals(substitutedLastParamType) && + !lastArgType.equals(TypeConversionUtil.erasure(substitutedLastParamType))) { return; } PsiExpression[] initializers = getInitializers((PsiNewExpression)lastArg); diff --git a/java/java-tests/testData/inspection/redundantArrayForVarargs/rawArray/expected.xml b/java/java-tests/testData/inspection/redundantArrayForVarargs/rawArray/expected.xml new file mode 100644 index 000000000000..2b78f14a5517 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantArrayForVarargs/rawArray/expected.xml @@ -0,0 +1,9 @@ + + + + Test.java + 4 + Redundant array creation + Redundant array creation for calling varargs method + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantArrayForVarargs/rawArray/src/Test.java b/java/java-tests/testData/inspection/redundantArrayForVarargs/rawArray/src/Test.java new file mode 100644 index 000000000000..68e9a3f198c1 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantArrayForVarargs/rawArray/src/Test.java @@ -0,0 +1,9 @@ +public class Test { + { + try { + String.class.getConstructor(new Class[]{String.class}); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantArrayForVarargsCallInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantArrayForVarargsCallInspectionTest.java index aa4eef8703a4..2b961772e74a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantArrayForVarargsCallInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantArrayForVarargsCallInspectionTest.java @@ -23,4 +23,5 @@ public class RedundantArrayForVarargsCallInspectionTest extends InspectionTestCa public void testNestedArray() throws Exception { doTest(); } public void testCheckEnumConstant() throws Exception { doTest(); } public void testGeneric() throws Exception { doTest(); } + public void testRawArray() throws Exception { doTest(); } }