Skip to content

Commit

Permalink
Merge branch 'master' into haifeng-targetlocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ao-senXiong authored Jan 3, 2025
2 parents c165f4c + d93e807 commit 89e7093
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 11 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ jobs:
java: [{version: '8', experimental: false},
{version: '11', experimental: false},
{version: '17', experimental: false},
{version: '22', experimental: false},
{version: '23', experimental: false},
{version: '24-ea', experimental: true}]
env:
Expand Down
2 changes: 1 addition & 1 deletion checker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ dependencies {
testImplementation 'com.amazonaws:aws-java-sdk-ec2'
testImplementation 'com.amazonaws:aws-java-sdk-kms'
// The AWS SDK is used for testing the Called Methods Checker.
testImplementation platform('com.amazonaws:aws-java-sdk-bom:1.12.770')
testImplementation platform('com.amazonaws:aws-java-sdk-bom:1.12.780')
// For the Resource Leak Checker's support for JavaEE.
testImplementation 'javax.servlet:javax.servlet-api:4.0.1'
// For the Resource Leak Checker's support for IOUtils.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ protected boolean commonAssignmentCheck(
}
}

/// TODO: What does "take precedence over" mean? Both are issued, but the
/// "i18nformat.excess.arguments" appears first in the output. Is this meant to not call
/// super.commonAssignmentCheck() if `result` is already false?
// TODO: What does "take precedence over" mean? Both are issued, but the
// "i18nformat.excess.arguments" appears first in the output. Is this meant to not call
// super.commonAssignmentCheck() if `result` is already false?
// By calling super.commonAssignmentCheck() last, any "i18nformat.excess.arguments"
// message issued for a given line of code will take precedence over the
// "assignment.type.incompatible"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public AnnotatedForNullnessTest(List<File> testFiles) {
*/
@Parameters
public static String[] getTestDirs() {
return new String[] {"nulless-conservative-defaults/annotatedfornullness"};
return new String[] {
"nulless-conservative-defaults/annotatedfornullness",
"nulless-conservative-defaults/packageannotatedfornullness"
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package packageannotatedfornullness.annotated;

import org.checkerframework.checker.nullness.qual.Nullable;

public class Test {
void foo(@Nullable Object o) {
// :: error: (dereference.of.nullable)
o.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@AnnotatedFor("nullness")
package packageannotatedfornullness.annotated;

import org.checkerframework.framework.qual.AnnotatedFor;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package packageannotatedfornullness.notannotated;

import org.checkerframework.checker.nullness.qual.Nullable;

public class Test {
void foo(@Nullable Object o) {
// No error because this package is not annotated for nullness.
o.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package packageannotatedfornullness.notannotated;
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Version 3.42.0-eisop6 (January ??, 2025)

**Closed issues:**

eisop#1033.


Version 3.42.0-eisop5 (December 20, 2024)
-----------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/creating-a-checker.tex
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
repository \url{https://github.com/eisop/checker-framework}.
Another choice is to write it in a stand-alone repository. Here is a
template for a stand-alone repository:
\url{https://github.com/typetools/templatefora-checker}; at that URL,
\url{https://github.com/eisop/templatefora-checker}; at that URL,
click the ``Use this template'' button.

% You may also wish to consult Section~\ref{creating-testing-framework} for
Expand Down
4 changes: 2 additions & 2 deletions docs/manual/map-key-checker.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
\chapterAndLabel{Map Key Checker}{map-key-checker}

The Map Key Checker tracks which values are keys for which maps. If variable
\code{v} has type \code{@KeyFor("m")...}, then the value of \code{v} is a key
in Map \code{m}. That is, the expression \code{m.containsKey(v)} evaluates to
\code{k} has type \code{@KeyFor("m")...}, then the value of \code{k} is a key
in Map \code{m}. That is, the expression \code{m.containsKey(k)} evaluates to
\code{true}.

Section~\ref{map-key-qualifiers} describes how \code{@KeyFor} annotations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
Expand Down Expand Up @@ -2296,7 +2297,7 @@ public boolean shouldSuppressWarnings(@Nullable TreePath path, String errKey) {

if (isAnnotatedForThisCheckerOrUpstreamChecker(elt)) {
// Return false immediately. Do NOT check for AnnotatedFor in the enclosing
// elements, because they may not have an @AnnotatedFor.
// elements as the closest AnnotatedFor is already found.
return false;
}
} else if (TreeUtils.classTreeKinds().contains(decl.getKind())) {
Expand All @@ -2308,9 +2309,20 @@ public boolean shouldSuppressWarnings(@Nullable TreePath path, String errKey) {

if (isAnnotatedForThisCheckerOrUpstreamChecker(elt)) {
// Return false immediately. Do NOT check for AnnotatedFor in the enclosing
// elements, because they may not have an @AnnotatedFor.
// elements as the closest AnnotatedFor is already found.
return false;
}
Element packageElement = elt.getEnclosingElement();
if (packageElement != null && packageElement.getKind() == ElementKind.PACKAGE) {
if (shouldSuppressWarnings(packageElement, errKey)) {
return true;
}
if (isAnnotatedForThisCheckerOrUpstreamChecker(packageElement)) {
// Return false immediately. Do NOT check for AnnotatedFor in the enclosing
// elements as the closest AnnotatedFor is already found.
return false;
}
}
} else {
throw new BugInCF("Unexpected declaration kind: " + decl.getKind() + " " + decl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.NewArrayTree;
import com.sun.source.tree.NewClassTree;
import com.sun.source.tree.PackageTree;
import com.sun.source.tree.ParameterizedTypeTree;
import com.sun.source.tree.ParenthesizedTree;
import com.sun.source.tree.PrimitiveTypeTree;
Expand Down Expand Up @@ -93,6 +94,7 @@
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Name;
import javax.lang.model.element.NestingKind;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.ExecutableType;
Expand Down Expand Up @@ -285,6 +287,20 @@ public static boolean isSelfAccess(ExpressionTree tree) {
// This section of the file groups methods by their receiver type; that is, it puts all
// `elementFrom*(FooTree)` methods together.

/**
* Return the package element corresponding to the given package declaration.
*
* @param tree package declaration
* @return the package element for the given package
*/
public static PackageElement elementFromDeclaration(PackageTree tree) {
PackageElement result = (PackageElement) TreeInfo.symbolFor((JCTree) tree);
if (result == null) {
throw new BugInCF("null element for package tree %s", tree);
}
return result;
}

// TODO: Document when this may return null.
/**
* Returns the type element corresponding to the given class declaration.
Expand Down

0 comments on commit 89e7093

Please sign in to comment.