mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-203697 Class.getClass() false-negative on Java 12 switch expression
This commit is contained in:
+2
-1
@@ -24,7 +24,8 @@ public class ClassGetClassInspection extends AbstractBaseJavaLocalInspectionTool
|
||||
if (!OBJECT_GET_CLASS.test(call)) return;
|
||||
// Sometimes people use xyz.getClass() for implicit NPE check. While it's a questionable code style
|
||||
// do not warn about such case
|
||||
if (call.getParent() instanceof PsiExpressionStatement) return;
|
||||
if (call.getParent() instanceof PsiExpressionStatement &&
|
||||
!(call.getParent().getParent() instanceof PsiSwitchLabeledRuleStatement)) return;
|
||||
PsiExpression qualifier = call.getMethodExpression().getQualifierExpression();
|
||||
if (qualifier == null) return;
|
||||
PsiType type = qualifier.getType();
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Remove 'getClass()' call" "true"
|
||||
public class Main {
|
||||
Class<?> test(Class<?> obj) {
|
||||
return switch(obj.hashCode()) {
|
||||
default -> obj;
|
||||
};
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Remove 'getClass()' call" "true"
|
||||
public class Main {
|
||||
Class<?> test(Class<?> obj) {
|
||||
return switch(obj.hashCode()) {
|
||||
default -> obj.<caret>getClass();
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user