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 position of marker for dereference of nullable errors #439

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion checker/jtreg/nullness/Issue347-con.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Issue347.java:32:9: compiler.err.proc.messager: [dereference.of.nullable] dereference of possibly-null reference nble
Issue347.java:32:13: compiler.err.proc.messager: [dereference.of.nullable] dereference of possibly-null reference nble
1 error
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ public Void visitMemberSelect(MemberSelectTree tree, Void p) {
|| tree.getExpression().getKind() == Tree.Kind.PARAMETERIZED_TYPE
// case 8. static member access
|| ElementUtils.isStatic(e))) {
checkForNullability(tree.getExpression(), DEREFERENCE_OF_NULLABLE);
AnnotatedTypeMirror type = atypeFactory.getAnnotatedType(tree.getExpression());
checkForNullability(type, tree, DEREFERENCE_OF_NULLABLE, tree.getExpression());
}

return super.visitMemberSelect(tree, p);
Expand Down Expand Up @@ -649,8 +650,22 @@ private boolean checkForNullability(ExpressionTree tree, @CompilerMessageKey Str
*/
private boolean checkForNullability(
AnnotatedTypeMirror type, Tree tree, @CompilerMessageKey String errMsg) {
return checkForNullability(type, tree, errMsg, tree);
}

/**
* Issues the error message if an expression with this type may be null.
*
* @param type annotated type
* @param tree the tree where the error is to reported
* @param errMsg the error message (must be {@link CompilerMessageKey})
* @param errTree the tree to be used in the error message
* @return whether or not the check succeeded
*/
private boolean checkForNullability(
AnnotatedTypeMirror type, Tree tree, @CompilerMessageKey String errMsg, Tree errTree) {
if (!type.hasEffectiveAnnotation(NONNULL)) {
checker.reportError(tree, errMsg, tree);
checker.reportError(tree, errMsg, errTree);
return false;
}
return true;
Expand Down Expand Up @@ -743,7 +758,8 @@ public Void visitForLoop(ForLoopTree tree, Void p) {
public Void visitNewClass(NewClassTree tree, Void p) {
ExpressionTree enclosingExpr = tree.getEnclosingExpression();
if (enclosingExpr != null) {
checkForNullability(enclosingExpr, DEREFERENCE_OF_NULLABLE);
AnnotatedTypeMirror type = atypeFactory.getAnnotatedType(enclosingExpr);
checkForNullability(type, tree, DEREFERENCE_OF_NULLABLE, enclosingExpr);
}
AnnotatedDeclaredType type = atypeFactory.getAnnotatedType(tree);
ExpressionTree identifier = tree.getIdentifier();
Expand Down
1 change: 1 addition & 0 deletions docs/manual/contributors.tex
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@
Vlastimil Dort,
Weitian Xing,
Werner Dietl,
Wuyue (Tony) Sun,
Zhiping Cai.