Skip to content
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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions checker/jtreg/nullness/EISOPissue548/ConservativeClassLiteral.java
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);
}
}
3 changes: 3 additions & 0 deletions checker/jtreg/nullness/EISOPissue548/MyEnum.java
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
Expand Up @@ -793,6 +793,10 @@ public Void visitNewArray(NewArrayTree tree, AnnotatedTypeMirror type) {
@Override
public Void visitMemberSelect(
MemberSelectTree tree, AnnotatedTypeMirror annotatedTypeMirror) {
Element elt = TreeUtils.elementFromUse(tree);
if (elt.toString().equals("class")) {
annotatedTypeMirror.replaceAnnotation(INITIALIZED);
}
if (TreeUtils.isArrayLengthAccess(tree)) {
annotatedTypeMirror.replaceAnnotation(INITIALIZED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ public Void visitMemberSelect(MemberSelectTree tree, AnnotatedTypeMirror type) {
type.replaceAnnotation(NONNULL);
}

if (elt.toString().equals("class")) {
type.replaceAnnotation(NONNULL);
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3663,7 +3663,7 @@ public Node visitMemberSelect(MemberSelectTree tree, Void p) {
if (!TreeUtils.isFieldAccess(tree)) {
// Could be a selector of a class or package
Element element = TreeUtils.elementFromUse(tree);
if (ElementUtils.isTypeElement(element)) {
if (ElementUtils.isTypeElement(element) || element.toString().equals("class")) {
ClassNameNode result = new ClassNameNode(tree, expr);
extendWithClassNameNode(result);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public ClassNameNode(MemberSelectTree tree, Node parent) {
this.tree = tree;
assert TreeUtils.isUseOfElement(tree) : "@AssumeAssertion(nullness): tree kind";
Element element = TreeUtils.elementFromUse(tree);
assert element instanceof TypeElement || element instanceof TypeParameterElement
assert element instanceof TypeElement
|| element instanceof TypeParameterElement
|| element.toString().equals("class")
: "@AssumeAssertion(nullness)";
this.element = element;
this.parent = parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ public static boolean isFieldAccess(Tree tree) {
MemberSelectTree memberSelect = (MemberSelectTree) tree;
assert isUseOfElement(memberSelect) : "@AssumeAssertion(nullness): tree kind";
Element el = TreeUtils.elementFromUse(memberSelect);
if (el.getKind().isField()) {
if (el.getKind().isField() && !el.toString().equals("class")) {
return (VariableElement) el;
}
} else if (tree.getKind() == Tree.Kind.IDENTIFIER) {
Expand Down
Loading