mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
[java-inspections] RawUseOfParameterizedTypeInspection: handle null expected type
Fixes EA-923716 - AE: BasicJavaParserUtil.parseFragment GitOrigin-RevId: 37fd5e8d2e6504ca924ac09f6316548530a4952c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ce933b41d7
commit
ea2e768ce2
@@ -115,7 +115,8 @@ public class RawUseOfParameterizedTypeInspection extends BaseInspection {
|
||||
if (!PsiUtil.isLanguageLevel7OrHigher(parent)) return null;
|
||||
if (newExpression.isArrayCreation() || newExpression.getAnonymousClass() != null) return null;
|
||||
PsiType expectedType = ExpectedTypeUtils.findExpectedType(newExpression, false);
|
||||
if (expectedType == null || (expectedType instanceof PsiClassType && ((PsiClassType)expectedType).isRaw())) return null;
|
||||
if (expectedType == null || expectedType.equals(PsiTypes.nullType()) ||
|
||||
(expectedType instanceof PsiClassType && ((PsiClassType)expectedType).isRaw())) return null;
|
||||
PsiNewExpression copy = (PsiNewExpression)LambdaUtil.copyWithExpectedType(parent, expectedType);
|
||||
PsiJavaCodeReferenceElement reference = copy.getClassReference();
|
||||
if (reference == null) return null;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
class TestNullType {
|
||||
void test() {
|
||||
<error descr="Cannot infer type: variable initializer is 'null'">var</error> x = null;
|
||||
x = new <warning descr="Raw use of parameterized class 'ArrayList'">ArrayList</warning>();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,10 @@ public class RawUseOfParameterizedTypeInspectionTest extends LightJavaInspection
|
||||
public void testRawUseOfParameterizedType() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInvalidType() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIgnoreWhenQuickFixNotAvailable() {
|
||||
final RawUseOfParameterizedTypeInspection inspection = (RawUseOfParameterizedTypeInspection)getInspection();
|
||||
|
||||
Reference in New Issue
Block a user