-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Class literals in field access and related type checks #550
base: master
Are you sure you want to change the base?
Changes from 10 commits
dc8ee8e
984656b
c5f519a
a6980ca
b9d3d64
179e55d
9de8f06
4b73445
92248dc
00a3855
acf6530
17e79e3
cc6844f
63f45e6
32b0f01
ef96c4c
d7cd564
709e717
1424533
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* @test | ||
* @summary Test class literals in CFGs and their type with conservative nullness. | ||
* | ||
* @compile MyEnum.java | ||
* @compile -processor org.checkerframework.checker.nullness.NullnessChecker -AuseConservativeDefaultsForUncheckedCode=bytecode,-source ConservativeClassLiteral.java | ||
*/ | ||
|
||
import java.util.EnumSet; | ||
|
||
class ConservativeClassLiteral { | ||
EnumSet<MyEnum> none() { | ||
return EnumSet.noneOf(MyEnum.class); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
enum MyEnum { | ||
VALUE; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ enum Issue3020 { | |
void retrieveConstant() { | ||
Class<?> theClass = Issue3020.class; | ||
// :: error: (accessing.nullable) | ||
// :: error: (dereference.of.nullable) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error comes from incorrectly using |
||
Object unused = passThrough(theClass.getEnumConstants())[0]; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3103,12 +3103,14 @@ protected void commonAssignmentCheck( | |
Tree valueExpTree, | ||
@CompilerMessageKey String errorKey, | ||
Object... extraArgs) { | ||
|
||
commonAssignmentCheckStartDiagnostic(varType, valueType, valueExpTree); | ||
|
||
AnnotatedTypeMirror widenedValueType = atypeFactory.getWidenedType(valueType, varType); | ||
boolean success = atypeFactory.getTypeHierarchy().isSubtype(widenedValueType, varType); | ||
|
||
boolean success; | ||
if (valueExpTree.toString().endsWith(".class")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a really bad idea: it converts every Tree to a String and compares it - this will not be good for performance. |
||
success = true; | ||
} else { | ||
commonAssignmentCheckStartDiagnostic(varType, valueType, valueExpTree); | ||
AnnotatedTypeMirror widenedValueType = atypeFactory.getWidenedType(valueType, varType); | ||
success = atypeFactory.getTypeHierarchy().isSubtype(widenedValueType, varType); | ||
} | ||
// TODO: integrate with subtype test. | ||
if (success) { | ||
for (Class<? extends Annotation> mono : | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described in #548 we should look into properly representing class literals in the CFG. The description for
FieldAccessNode
explicitly states that they are not for class literals. Let's figure out what a good representation for this is.