diff --git a/checker/jtreg/nullness/Issue347-con.out b/checker/jtreg/nullness/Issue347-con.out index 644fabd8dae..ba77aa40631 100644 --- a/checker/jtreg/nullness/Issue347-con.out +++ b/checker/jtreg/nullness/Issue347-con.out @@ -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 diff --git a/checker/src/main/java/org/checkerframework/checker/nullness/NullnessVisitor.java b/checker/src/main/java/org/checkerframework/checker/nullness/NullnessVisitor.java index 537783eae2b..ab872fe226a 100644 --- a/checker/src/main/java/org/checkerframework/checker/nullness/NullnessVisitor.java +++ b/checker/src/main/java/org/checkerframework/checker/nullness/NullnessVisitor.java @@ -279,7 +279,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); @@ -657,8 +658,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; @@ -751,7 +766,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(); diff --git a/docs/manual/contributors.tex b/docs/manual/contributors.tex index 2878bd28e4d..5a7d1e0dd88 100644 --- a/docs/manual/contributors.tex +++ b/docs/manual/contributors.tex @@ -137,4 +137,5 @@ Vlastimil Dort, Weitian Xing, Werner Dietl, +Wuyue (Tony) Sun, Zhiping Cai.