From 5a64e25a7bb3aa55fd6027bb15be32684d87ba5d Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Wed, 3 Sep 2025 21:51:15 -0700 Subject: [PATCH 1/9] Initial commit to introduce optimistic default --- .../onlyannotatedfor/AnnotatedForWithUse.java | 10 +- ...AnnotatedForWithUseConservativeDefault.out | 10 +- .../AnnotatedForWithUseNoFlag.out | 8 +- .../AnnotatedForWithUseOnlyAnnotatedFor.out | 4 +- .../AnnotatedForWithUseOptimisticDefault.out | 18 ++ ...thUseOptimisticDefaultOnlyAnnotatedFor.out | 7 + .../framework/source/SourceChecker.java | 28 +++ .../type/GenericAnnotatedTypeFactory.java | 9 +- .../util/defaults/QualifierDefaults.java | 192 +++++++++++++++--- 9 files changed, 237 insertions(+), 49 deletions(-) create mode 100644 checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefault.out create mode 100644 checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUse.java b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUse.java index 7e837f5789f0..7fbc26102b1d 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUse.java +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUse.java @@ -5,6 +5,8 @@ * @compile/fail/ref=AnnotatedForWithUseNoFlag.out -XDrawDiagnostics -Xlint:unchecked -processor org.checkerframework.checker.nullness.NullnessChecker AnnotatedForWithUse.java * @compile/fail/ref=AnnotatedForWithUseOnlyAnnotatedFor.out -XDrawDiagnostics -Xlint:unchecked -processor org.checkerframework.checker.nullness.NullnessChecker -AonlyAnnotatedFor AnnotatedForWithUse.java * @compile/fail/ref=AnnotatedForWithUseConservativeDefault.out -XDrawDiagnostics -Xlint:unchecked -processor org.checkerframework.checker.nullness.NullnessChecker -AuseConservativeDefaultsForUncheckedCode=source AnnotatedForWithUse.java + * @compile/fail/ref=AnnotatedForWithUseOptimisticDefault.out -XDrawDiagnostics -Xlint:unchecked -processor org.checkerframework.checker.nullness.NullnessChecker -AuseOptimisticDefaultsForUncheckedCode=source AnnotatedForWithUse.java + * @compile/fail/ref=AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out -XDrawDiagnostics -Xlint:unchecked -processor org.checkerframework.checker.nullness.NullnessChecker -AuseOptimisticDefaultsForUncheckedCode=source -AonlyAnnotatedFor AnnotatedForWithUse.java */ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.framework.qual.AnnotatedFor; @@ -19,13 +21,13 @@ void set(Object of) {} @AnnotatedFor("nullness") class AnnotatedUse { void use(Unannotated u) { - // 1: OK, 2: OK, 3: Err + // 1: OK, 2: OK, 3: Err. 4: OK @NonNull Object obj = u.o; - // 1. Err, 2: Err, TODO want OK, 3: OK, TODO want Err + // 1. Err, 2: Err, TODO want OK, 3: OK, TODO want Err, 4: Err, TODO want OK u.o = null; - // 1: OK, 2: OK, 3: Err + // 1: OK, 2: OK, 3: Err, 4: OK u.get().toString(); - // 1: Err, 2: Err TODO want OK, 3: Err + // 1: Err, 2: Err TODO want OK, 3: Err, 4: OK u.set(null); } } diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseConservativeDefault.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseConservativeDefault.out index e7eed24e1eda..22e9d7a57c9a 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseConservativeDefault.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseConservativeDefault.out @@ -1,14 +1,14 @@ -AnnotatedForWithUse.java:23:37: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:26:37: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable Object required: @NonNull Object -AnnotatedForWithUse.java:27:18: compiler.err.proc.messager: [dereference.of.nullable] dereference of possibly-null reference u.get() -AnnotatedForWithUse.java:27:29: compiler.err.proc.messager: [method.invocation.invalid] call to toString() not allowed on the given receiver. +AnnotatedForWithUse.java:30:18: compiler.err.proc.messager: [dereference.of.nullable] dereference of possibly-null reference u.get() +AnnotatedForWithUse.java:30:29: compiler.err.proc.messager: [method.invocation.invalid] call to toString() not allowed on the given receiver. found : @UnknownInitialization Object required: @Initialized Object -AnnotatedForWithUse.java:29:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:32:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @UnknownKeyFor NullType required: @KeyForBottom Object -AnnotatedForWithUse.java:29:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:32:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @Nullable NullType required: @NonNull Object 5 errors diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out index 9d06996fc842..110c714f3e60 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out @@ -1,11 +1,11 @@ -AnnotatedForWithUse.java:14:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o -AnnotatedForWithUse.java:15:31: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. +AnnotatedForWithUse.java:17:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o +AnnotatedForWithUse.java:18:31: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. type of expression: @Nullable NullType method return type: @NonNull Object -AnnotatedForWithUse.java:25:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:28:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable NullType required: @NonNull Object -AnnotatedForWithUse.java:29:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:32:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @Nullable NullType required: @NonNull Object 4 errors diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out index b7adfaaebd3d..ed6a8a108419 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out @@ -1,7 +1,7 @@ -AnnotatedForWithUse.java:25:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:28:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable NullType required: @NonNull Object -AnnotatedForWithUse.java:29:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:32:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @Nullable NullType required: @NonNull Object 2 errors diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefault.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefault.out new file mode 100644 index 000000000000..f66d60b4122f --- /dev/null +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefault.out @@ -0,0 +1,18 @@ +AnnotatedForWithUse.java:17:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.nullness.qual.KeyForBottom used on prohibited locations FIELD +AnnotatedForWithUse.java:17:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o +AnnotatedForWithUse.java:17:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.initialization.qual.FBCBottom used on prohibited locations FIELD +AnnotatedForWithUse.java:18:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.nullness.qual.KeyForBottom used on prohibited locations RETURN +AnnotatedForWithUse.java:18:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.initialization.qual.FBCBottom used on prohibited locations RETURN +AnnotatedForWithUse.java:18:31: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. +type of expression: @UnknownKeyFor NullType +method return type: @KeyForBottom Object +AnnotatedForWithUse.java:18:31: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. +type of expression: @Nullable NullType +method return type: @NonNull Object +AnnotatedForWithUse.java:28:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +found : @UnknownKeyFor NullType +required: @KeyForBottom Object +AnnotatedForWithUse.java:28:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +found : @Nullable NullType +required: @NonNull Object +9 errors diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out new file mode 100644 index 000000000000..3609f47cbb88 --- /dev/null +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out @@ -0,0 +1,7 @@ +AnnotatedForWithUse.java:28:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +found : @UnknownKeyFor NullType +required: @KeyForBottom Object +AnnotatedForWithUse.java:28:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +found : @Nullable NullType +required: @NonNull Object +2 errors diff --git a/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java b/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java index 0c0c9a37d1a2..1242e7c6f90a 100644 --- a/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java +++ b/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java @@ -205,6 +205,14 @@ // Whether to type check the enclosing expression of an inner class instantiation. "checkEnclosingExpr", + // Whether to use optimistic defaults for bytecode and/or source code. + // The option takes same arguments as "useConservativeDefaultsForUncheckedCode". + // Optimistic default will only apply the code is not in the scope of an @AnnotatedFor. + // Note using this option will not suppress the warning for source code not in the scope of an + // @AnnotatedFor, user can use -AonlyAnnotatedFor together with this option. + // Optimistic and conservative defaults should apply to source or/and bytecode at the same time. + "useOptimisticDefaultsForUncheckedCode", + // Whether to use conservative defaults for bytecode and/or source code. // This option takes arguments "source" and/or "bytecode". // The default is "-source,-bytecode" (eventually this will be changed to "-source,bytecode"). @@ -2820,6 +2828,26 @@ public boolean shouldSuppressWarnings(@Nullable TreePath path, String errKey) { return false; } + public boolean useOptimisticDefault(String kindOfCode) { + boolean useUncheckedDefaultsForSource = false; + boolean useUncheckedDefaultsForByteCode = false; + for (String arg : this.getStringsOption("useOptimisticDefaultsForUncheckedCode", ',')) { + boolean value = arg.indexOf("-") != 0; + arg = value ? arg : arg.substring(1); + if (arg.equals(kindOfCode)) { + return value; + } + } + if (kindOfCode.equals("source")) { + return useUncheckedDefaultsForSource; + } else if (kindOfCode.equals("bytecode")) { + return useUncheckedDefaultsForByteCode; + } else { + throw new UserError( + "SourceChecker: unexpected argument to useOptimisticDefault: " + kindOfCode); + } + } + /** * Should conservative defaults be used for the kind of unchecked code indicated by the * parameter? diff --git a/framework/src/main/java/org/checkerframework/framework/type/GenericAnnotatedTypeFactory.java b/framework/src/main/java/org/checkerframework/framework/type/GenericAnnotatedTypeFactory.java index 0190a850401c..a768cd9809a7 100644 --- a/framework/src/main/java/org/checkerframework/framework/type/GenericAnnotatedTypeFactory.java +++ b/framework/src/main/java/org/checkerframework/framework/type/GenericAnnotatedTypeFactory.java @@ -789,7 +789,7 @@ protected final QualifierDefaults createAndInitQualifierDefaults() { QualifierDefaults defs = createQualifierDefaults(); addCheckedCodeDefaults(defs); addCheckedStandardDefaults(defs); - addUncheckedStandardDefaults(defs); + addUncheckedDefaults(defs); checkForDefaultQualifierInHierarchy(defs); return defs; @@ -868,12 +868,13 @@ protected void addCheckedStandardDefaults(QualifierDefaults defs) { } /** - * Adds standard unchecked defaults that do not conflict with previously added defaults. + * Adds both optimistic and conservative unchecked defaults that do not conflict with previously + * added defaults. * * @param defs {@link QualifierDefaults} object to which defaults are added */ - protected void addUncheckedStandardDefaults(QualifierDefaults defs) { - defs.addUncheckedStandardDefaults(); + protected void addUncheckedDefaults(QualifierDefaults defs) { + defs.addUncheckedDefaults(); } /** diff --git a/framework/src/main/java/org/checkerframework/framework/util/defaults/QualifierDefaults.java b/framework/src/main/java/org/checkerframework/framework/util/defaults/QualifierDefaults.java index 080d1cec1429..def9970d7ac6 100644 --- a/framework/src/main/java/org/checkerframework/framework/util/defaults/QualifierDefaults.java +++ b/framework/src/main/java/org/checkerframework/framework/util/defaults/QualifierDefaults.java @@ -104,8 +104,11 @@ public class QualifierDefaults { /** Defaults for checked code. */ private final DefaultSet checkedCodeDefaults = new DefaultSet(); - /** Defaults for unchecked code. */ - private final DefaultSet uncheckedCodeDefaults = new DefaultSet(); + /** Optimistic defaults for unchecked code. */ + private final DefaultSet optimisticUncheckedCodeDefaults = new DefaultSet(); + + /** Conservative defaults for unchecked code. */ + private final DefaultSet conservativeUncheckedCodeDefaults = new DefaultSet(); /** Size for caches. */ private static final int CACHE_SIZE = 300; @@ -150,22 +153,41 @@ public class QualifierDefaults { TypeUseLocation.OTHERWISE, TypeUseLocation.ALL)); - /** Standard unchecked default locations that should be top. */ + /** Optimistic unchecked default locations that should be top. */ + public static final List OPTIMISTIC_UNCHECKED_DEFAULTS_TOP = + Collections.unmodifiableList( + Arrays.asList(TypeUseLocation.PARAMETER, TypeUseLocation.UPPER_BOUND)); + + /** Optimistic unchecked default locations that should be bottom. */ + public static final List OPTIMISTIC_UNCHECKED_DEFAULTS_BOTTOM = + Collections.unmodifiableList( + Arrays.asList( + TypeUseLocation.RETURN, + TypeUseLocation.FIELD, + TypeUseLocation.LOWER_BOUND)); + + /** Conservative unchecked default locations that should be top. */ // Fields are defaulted to top so that warnings are issued at field reads, which we believe are // more common than field writes. Future work is to specify different defaults for field reads // and field writes. (When a field is written to, its type should be bottom.) - public static final List STANDARD_UNCHECKED_DEFAULTS_TOP = + public static final List CONSERVATIVE_UNCHECKED_DEFAULTS_TOP = Collections.unmodifiableList( Arrays.asList( TypeUseLocation.RETURN, TypeUseLocation.FIELD, TypeUseLocation.UPPER_BOUND)); - /** Standard unchecked default locations that should be bottom. */ - public static final List STANDARD_UNCHECKED_DEFAULTS_BOTTOM = + /** Conservative unchecked default locations that should be bottom. */ + public static final List CONSERVATIVE_UNCHECKED_DEFAULTS_BOTTOM = Collections.unmodifiableList( Arrays.asList(TypeUseLocation.PARAMETER, TypeUseLocation.LOWER_BOUND)); + /** True if optimistic defaults should be used in unannotated source code. */ + private final boolean useOptimisticDefaultSource; + + /** True if optimistic defaults should be used in unannotated bytecode. */ + private final boolean useOptimisticDefaultBytecode; + /** True if conservative defaults should be used in unannotated source code. */ private final boolean useConservativeDefaultsSource; @@ -188,10 +210,18 @@ public static List validLocationsForUncheckedCodeDefaults() { public QualifierDefaults(Elements elements, AnnotatedTypeFactory atypeFactory) { this.elements = elements; this.atypeFactory = atypeFactory; - this.useConservativeDefaultsBytecode = - atypeFactory.getChecker().useConservativeDefault("bytecode"); + this.useOptimisticDefaultSource = atypeFactory.getChecker().useOptimisticDefault("source"); + this.useOptimisticDefaultBytecode = + atypeFactory.getChecker().useOptimisticDefault("bytecode"); this.useConservativeDefaultsSource = atypeFactory.getChecker().useConservativeDefault("source"); + this.useConservativeDefaultsBytecode = + atypeFactory.getChecker().useConservativeDefault("bytecode"); + // Check if conservative default and optimistic default are applied at the same time + assert !(useOptimisticDefaultSource && useConservativeDefaultsSource) + : "source default are applied both optimistically and conservatively"; + assert !(useOptimisticDefaultBytecode && useConservativeDefaultsBytecode) + : "source default are applied both optimistically and conservatively"; ProcessingEnvironment processingEnv = atypeFactory.getProcessingEnv(); this.defaultQualifierValueElement = TreeUtils.getMethod(DefaultQualifier.class, "value", 0, processingEnv); @@ -209,8 +239,12 @@ public String toString() { return StringsPlume.joinLines( "Checked code defaults: ", StringsPlume.joinLines(checkedCodeDefaults), - "Unchecked code defaults: ", - StringsPlume.joinLines(uncheckedCodeDefaults), + "Optimistic unchecked code defaults: ", + StringsPlume.joinLines(optimisticUncheckedCodeDefaults), + "Conservative unchecked code defaults: ", + StringsPlume.joinLines(conservativeUncheckedCodeDefaults), + "useOptimisticDefaultSource: " + useOptimisticDefaultSource, + "useOptimisticDefaultBytecode: " + useOptimisticDefaultBytecode, "useConservativeDefaultsSource: " + useConservativeDefaultsSource, "useConservativeDefaultsBytecode: " + useConservativeDefaultsBytecode); } @@ -229,26 +263,45 @@ public boolean hasDefaultsForCheckedCode() { return false; } - /** Add standard unchecked defaults that do not conflict with previously added defaults. */ - public void addUncheckedStandardDefaults() { + /** Add unchecked defaults that do not conflict with previously added defaults. */ + public void addUncheckedDefaults() { QualifierHierarchy qualHierarchy = this.atypeFactory.getQualifierHierarchy(); AnnotationMirrorSet tops = qualHierarchy.getTopAnnotations(); AnnotationMirrorSet bottoms = qualHierarchy.getBottomAnnotations(); - for (TypeUseLocation loc : STANDARD_UNCHECKED_DEFAULTS_TOP) { - // Only add standard defaults in locations where a default has not be specified. + for (TypeUseLocation loc : OPTIMISTIC_UNCHECKED_DEFAULTS_TOP) { + // Add optimistic defaults in locations where a default has not be specified. for (AnnotationMirror top : tops) { - if (!conflictsWithExistingDefaults(uncheckedCodeDefaults, top, loc)) { - addUncheckedCodeDefault(top, loc); + if (!conflictsWithExistingDefaults(optimisticUncheckedCodeDefaults, top, loc)) { + addOptimisticUncheckedCodeDefault(top, loc); } } } - for (TypeUseLocation loc : STANDARD_UNCHECKED_DEFAULTS_BOTTOM) { + for (TypeUseLocation loc : OPTIMISTIC_UNCHECKED_DEFAULTS_BOTTOM) { for (AnnotationMirror bottom : bottoms) { - // Only add standard defaults in locations where a default has not be specified. - if (!conflictsWithExistingDefaults(uncheckedCodeDefaults, bottom, loc)) { - addUncheckedCodeDefault(bottom, loc); + // Add optimistic defaults in locations where a default has not be specified. + if (!conflictsWithExistingDefaults(optimisticUncheckedCodeDefaults, bottom, loc)) { + addOptimisticUncheckedCodeDefault(bottom, loc); + } + } + } + + for (TypeUseLocation loc : CONSERVATIVE_UNCHECKED_DEFAULTS_TOP) { + // Add conservative defaults in locations where a default has not be specified. + for (AnnotationMirror top : tops) { + if (!conflictsWithExistingDefaults(conservativeUncheckedCodeDefaults, top, loc)) { + addConservativeUncheckedCodeDefault(top, loc); + } + } + } + + for (TypeUseLocation loc : CONSERVATIVE_UNCHECKED_DEFAULTS_BOTTOM) { + for (AnnotationMirror bottom : bottoms) { + // Add conservative defaults in locations where a default has not be specified. + if (!conflictsWithExistingDefaults( + conservativeUncheckedCodeDefaults, bottom, loc)) { + addConservativeUncheckedCodeDefault(bottom, loc); } } } @@ -310,39 +363,70 @@ public void addCheckedCodeDefault( } /** - * Add a default annotation for unchecked elements. + * Add optimistic default annotation for unchecked elements. * * @param uncheckedDefaultAnno the default annotation mirror * @param location the type use location * @param applyToSubpackages whether the default should be inherited by subpackages */ - public void addUncheckedCodeDefault( + public void addOptimisticUncheckedCodeDefault( AnnotationMirror uncheckedDefaultAnno, TypeUseLocation location, boolean applyToSubpackages) { - checkDuplicates(uncheckedCodeDefaults, uncheckedDefaultAnno, location); + checkDuplicates(optimisticUncheckedCodeDefaults, uncheckedDefaultAnno, location); checkIsValidUncheckedCodeLocation(uncheckedDefaultAnno, location); - uncheckedCodeDefaults.add(new Default(uncheckedDefaultAnno, location, applyToSubpackages)); + optimisticUncheckedCodeDefaults.add( + new Default(uncheckedDefaultAnno, location, applyToSubpackages)); } /** - * Add a default annotation for unchecked elements that also applies to subpackages, if + * Add conservative default annotation for unchecked elements. + * + * @param uncheckedDefaultAnno the default annotation mirror + * @param location the type use location + * @param applyToSubpackages whether the default should be inherited by subpackages + */ + public void addConservativeUncheckedCodeDefault( + AnnotationMirror uncheckedDefaultAnno, + TypeUseLocation location, + boolean applyToSubpackages) { + checkDuplicates(conservativeUncheckedCodeDefaults, uncheckedDefaultAnno, location); + checkIsValidUncheckedCodeLocation(uncheckedDefaultAnno, location); + + conservativeUncheckedCodeDefaults.add( + new Default(uncheckedDefaultAnno, location, applyToSubpackages)); + } + + /** + * Add optimistic default annotation for unchecked elements that also applies to subpackages, if * applicable. * * @param uncheckedDefaultAnno the default annotation mirror * @param location the type use location */ - public void addUncheckedCodeDefault( + public void addOptimisticUncheckedCodeDefault( + AnnotationMirror uncheckedDefaultAnno, TypeUseLocation location) { + addOptimisticUncheckedCodeDefault(uncheckedDefaultAnno, location, true); + } + + /** + * Add conservative default annotation for unchecked elements that also applies to subpackages, + * if applicable. + * + * @param uncheckedDefaultAnno the default annotation mirror + * @param location the type use location + */ + public void addConservativeUncheckedCodeDefault( AnnotationMirror uncheckedDefaultAnno, TypeUseLocation location) { - addUncheckedCodeDefault(uncheckedDefaultAnno, location, true); + addConservativeUncheckedCodeDefault(uncheckedDefaultAnno, location, true); } /** Sets the default annotation for unchecked elements, with specific locations. */ public void addUncheckedCodeDefaults( AnnotationMirror absoluteDefaultAnno, TypeUseLocation[] locations) { for (TypeUseLocation location : locations) { - addUncheckedCodeDefault(absoluteDefaultAnno, location); + addConservativeUncheckedCodeDefault(absoluteDefaultAnno, location); } } @@ -781,6 +865,48 @@ private DefaultSet defaultsAtDirect(Element elt) { return qualifiers; } + /** + * Given an element, returns whether the optimistic default should be applied for it. Handles + * elements from bytecode or source code. + * + * @param annotationScope the element that the conservative default might apply to + * @return whether the conservative default applies to the given element + */ + public boolean applyOptimisticDefaults(Element annotationScope) { + if (annotationScope == null) { + return false; + } + + if (optimisticUncheckedCodeDefaults.isEmpty()) { + return false; + } + + // TODO: I would expect this: + // atypeFactory.isFromByteCode(annotationScope)) { + // to work instead of the + // isElementFromByteCode/declarationFromElement/isFromStubFile calls, + // but it doesn't work correctly and tests fail. + + boolean isFromStubFile = atypeFactory.isFromStubFile(annotationScope); + boolean isBytecode = + ElementUtils.isElementFromByteCode(annotationScope) + && atypeFactory.declarationFromElement(annotationScope) == null + && !isFromStubFile; + if (isBytecode) { + return useOptimisticDefaultSource && !isElementAnnotatedForThisChecker(annotationScope); + } else if (isFromStubFile) { + // TODO: Types in stub files not annotated for a particular checker should be + // treated as unchecked bytecode. For now, all types in stub files are treated as + // checked code. Eventually, @AnnotatedFor("checker") will be programmatically added + // to methods in stub files supplied via the @StubFiles annotation. Stub files will + // be treated like unchecked code except for methods in the scope of an @AnnotatedFor. + return false; + } else if (useOptimisticDefaultSource) { + return !isElementAnnotatedForThisChecker(annotationScope); + } + return false; + } + /** * Given an element, returns whether the conservative default should be applied for it. Handles * elements from bytecode or source code. @@ -793,7 +919,7 @@ public boolean applyConservativeDefaults(Element annotationScope) { return false; } - if (uncheckedCodeDefaults.isEmpty()) { + if (conservativeUncheckedCodeDefaults.isEmpty()) { return false; } @@ -860,7 +986,13 @@ private void applyDefaultsElement( } if (applyConservativeDefaults(annotationScope)) { - for (Default def : uncheckedCodeDefaults) { + for (Default def : conservativeUncheckedCodeDefaults) { + if (!typeVarUseDef || def.location != TypeUseLocation.TYPE_VARIABLE_USE) { + applier.applyDefault(def); + } + } + } else if (applyOptimisticDefaults(annotationScope)) { + for (Default def : optimisticUncheckedCodeDefaults) { if (!typeVarUseDef || def.location != TypeUseLocation.TYPE_VARIABLE_USE) { applier.applyDefault(def); } From 964b9b50ef7941d5b5446aaacda9729513171ec1 Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Wed, 3 Sep 2025 21:59:51 -0700 Subject: [PATCH 2/9] Disable JSpecify reference checker first to test other suite --- .../test-jspecify-reference-checker.sh | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/checker/bin-devel/test-jspecify-reference-checker.sh b/checker/bin-devel/test-jspecify-reference-checker.sh index 72511c4ee4c4..23c33c2ffb1c 100755 --- a/checker/bin-devel/test-jspecify-reference-checker.sh +++ b/checker/bin-devel/test-jspecify-reference-checker.sh @@ -1,24 +1,24 @@ -#!/bin/bash - -set -e -# set -o verbose -set -o xtrace -export SHELLOPTS -echo "SHELLOPTS=${SHELLOPTS}" - -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" -source "$SCRIPT_DIR"/clone-related.sh - -./gradlew assembleForJavac --console=plain -Dorg.gradle.internal.http.socketTimeout=60000 -Dorg.gradle.internal.http.connectionTimeout=60000 - -# TODO: remove uses of `main-eisop` once that becomes `main`. -"$SCRIPT_DIR/.git-scripts/git-clone-related" --upstream-branch main-eisop eisop jspecify-reference-checker - -cd ../jspecify-reference-checker - -# Delete the eisop/jdk that was already cloned... -rm -r ../jdk -# instead clone the jspecify/jdk. -"$SCRIPT_DIR/.git-scripts/git-clone-related" jspecify jdk - -JSPECIFY_CONFORMANCE_TEST_MODE=details ./gradlew build conformanceTests demoTest --console=plain --include-build "$CHECKERFRAMEWORK" +##!/bin/bash +# +#set -e +## set -o verbose +#set -o xtrace +#export SHELLOPTS +#echo "SHELLOPTS=${SHELLOPTS}" +# +#SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" +#source "$SCRIPT_DIR"/clone-related.sh +# +#./gradlew assembleForJavac --console=plain -Dorg.gradle.internal.http.socketTimeout=60000 -Dorg.gradle.internal.http.connectionTimeout=60000 +# +## TODO: remove uses of `main-eisop` once that becomes `main`. +#"$SCRIPT_DIR/.git-scripts/git-clone-related" --upstream-branch main-eisop eisop jspecify-reference-checker +# +#cd ../jspecify-reference-checker +# +## Delete the eisop/jdk that was already cloned... +#rm -r ../jdk +## instead clone the jspecify/jdk. +#"$SCRIPT_DIR/.git-scripts/git-clone-related" jspecify jdk +# +#JSPECIFY_CONFORMANCE_TEST_MODE=details ./gradlew build conformanceTests demoTest --console=plain --include-build "$CHECKERFRAMEWORK" From 6ed19a1146a9c116e18cda36d9b01ad2376d3137 Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Wed, 3 Sep 2025 22:12:45 -0700 Subject: [PATCH 3/9] Line number --- .../AnnotatedForWithUseConservativeDefault.out | 10 +++++----- .../AnnotatedForWithUseNoFlag.out | 8 ++++---- .../AnnotatedForWithUseOnlyAnnotatedFor.out | 4 ++-- .../AnnotatedForWithUseOptimisticDefault.out | 18 +++++++++--------- ...ithUseOptimisticDefaultOnlyAnnotatedFor.out | 4 ++-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseConservativeDefault.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseConservativeDefault.out index 22e9d7a57c9a..be51d02d80be 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseConservativeDefault.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseConservativeDefault.out @@ -1,14 +1,14 @@ -AnnotatedForWithUse.java:26:37: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:25:37: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable Object required: @NonNull Object -AnnotatedForWithUse.java:30:18: compiler.err.proc.messager: [dereference.of.nullable] dereference of possibly-null reference u.get() -AnnotatedForWithUse.java:30:29: compiler.err.proc.messager: [method.invocation.invalid] call to toString() not allowed on the given receiver. +AnnotatedForWithUse.java:29:18: compiler.err.proc.messager: [dereference.of.nullable] dereference of possibly-null reference u.get() +AnnotatedForWithUse.java:29:29: compiler.err.proc.messager: [method.invocation.invalid] call to toString() not allowed on the given receiver. found : @UnknownInitialization Object required: @Initialized Object -AnnotatedForWithUse.java:32:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:31:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @UnknownKeyFor NullType required: @KeyForBottom Object -AnnotatedForWithUse.java:32:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:31:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @Nullable NullType required: @NonNull Object 5 errors diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out index 110c714f3e60..772f23b46491 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out @@ -1,11 +1,11 @@ -AnnotatedForWithUse.java:17:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o -AnnotatedForWithUse.java:18:31: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. +AnnotatedForWithUse.java:16:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o +AnnotatedForWithUse.java:17:31: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. type of expression: @Nullable NullType method return type: @NonNull Object -AnnotatedForWithUse.java:28:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:27:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable NullType required: @NonNull Object -AnnotatedForWithUse.java:32:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:31:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @Nullable NullType required: @NonNull Object 4 errors diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out index ed6a8a108419..a24200b03470 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out @@ -1,7 +1,7 @@ -AnnotatedForWithUse.java:28:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:27:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable NullType required: @NonNull Object -AnnotatedForWithUse.java:32:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:31:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @Nullable NullType required: @NonNull Object 2 errors diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefault.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefault.out index f66d60b4122f..4b831e7ac2b4 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefault.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefault.out @@ -1,18 +1,18 @@ -AnnotatedForWithUse.java:17:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.nullness.qual.KeyForBottom used on prohibited locations FIELD -AnnotatedForWithUse.java:17:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o -AnnotatedForWithUse.java:17:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.initialization.qual.FBCBottom used on prohibited locations FIELD -AnnotatedForWithUse.java:18:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.nullness.qual.KeyForBottom used on prohibited locations RETURN -AnnotatedForWithUse.java:18:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.initialization.qual.FBCBottom used on prohibited locations RETURN -AnnotatedForWithUse.java:18:31: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. +AnnotatedForWithUse.java:16:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.nullness.qual.KeyForBottom used on prohibited locations FIELD +AnnotatedForWithUse.java:16:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o +AnnotatedForWithUse.java:16:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.initialization.qual.FBCBottom used on prohibited locations FIELD +AnnotatedForWithUse.java:17:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.nullness.qual.KeyForBottom used on prohibited locations RETURN +AnnotatedForWithUse.java:17:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.initialization.qual.FBCBottom used on prohibited locations RETURN +AnnotatedForWithUse.java:17:31: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. type of expression: @UnknownKeyFor NullType method return type: @KeyForBottom Object -AnnotatedForWithUse.java:18:31: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. +AnnotatedForWithUse.java:17:31: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. type of expression: @Nullable NullType method return type: @NonNull Object -AnnotatedForWithUse.java:28:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:27:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @UnknownKeyFor NullType required: @KeyForBottom Object -AnnotatedForWithUse.java:28:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:27:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable NullType required: @NonNull Object 9 errors diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out index 3609f47cbb88..402fc9aabcd0 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out @@ -1,7 +1,7 @@ -AnnotatedForWithUse.java:28:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:27:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @UnknownKeyFor NullType required: @KeyForBottom Object -AnnotatedForWithUse.java:28:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:27:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable NullType required: @NonNull Object 2 errors From 465a585ed26013874cbb118392d18f5756a61571 Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Wed, 3 Sep 2025 22:16:59 -0700 Subject: [PATCH 4/9] Changelog --- docs/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3b0ab018c221..05abc4ff9cd2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -3,6 +3,10 @@ Version 3.49.5-eisop1 (July ??, 2025) **User-visible changes:** +The new command-line option `-AuseOptimisticDefaultsForUncheckedCode` takes `source` and `bytecode` argument, similar to +`-AuseConservativeDefaultsForUnCheckedCode` but apply to optimistic default, that is, Top for method parameter type and +Bottom for method return and field type. + The new command-line option `-AonlyAnnotatedFor` suppresses all type-checking errors and warnings outside the scope of a corresponding `@AnnotatedFor` annotation. Note that the `@AnnotatedFor` annotation must include the checker's name to enable warnings from that checker. From 4e84cfe28ec35b521592a6e0b1eb202849f87249 Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Wed, 3 Sep 2025 22:30:40 -0700 Subject: [PATCH 5/9] Javadoc --- .../framework/source/SourceChecker.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java b/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java index 1242e7c6f90a..7931b5f5de35 100644 --- a/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java +++ b/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java @@ -2828,6 +2828,13 @@ public boolean shouldSuppressWarnings(@Nullable TreePath path, String errKey) { return false; } + /** + * Determine whether optimistic defaults should be used for the kind of unchecked code indicated + * by the command line arguments. + * + * @param kindOfCode source or bytecode + * @return whether optimistic defaults should be used + */ public boolean useOptimisticDefault(String kindOfCode) { boolean useUncheckedDefaultsForSource = false; boolean useUncheckedDefaultsForByteCode = false; @@ -2849,8 +2856,8 @@ public boolean useOptimisticDefault(String kindOfCode) { } /** - * Should conservative defaults be used for the kind of unchecked code indicated by the - * parameter? + * Determine whether conservative defaults should be used for the kind of unchecked code + * indicated by the command line arguments. * * @param kindOfCode source or bytecode * @return whether conservative defaults should be used From c6131d194584e1b4d5b771aac400214ac97e4f49 Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Thu, 4 Sep 2025 08:56:35 -0700 Subject: [PATCH 6/9] CI From 254b05ea2efba7ede931046655a30de97362292c Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Mon, 20 Oct 2025 23:44:07 -0400 Subject: [PATCH 7/9] Format and line number --- .../nullness/onlyannotatedfor/AnnotatedForWithUse.java | 2 +- .../onlyannotatedfor/AnnotatedForWithUseNoFlag.out | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUse.java b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUse.java index 99e20e392c8a..474b6e19bb72 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUse.java +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUse.java @@ -26,7 +26,7 @@ void set(Object of) {} class AnnotatedUse { void use(Unannotated u) { // 1: OK, 2: OK, 3: Err. 4: OK - @NonNull Object obj = u.o; + @NonNull Object obj = u.o; // 1. Err, 2: Err, TODO want OK, 3: OK, TODO want Err, 4: Err, TODO want OK u.o = null; // 1: OK, 2: OK, 3: Err, 4: OK diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out index 9ec3ea936b49..d42716cce36e 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out @@ -1,11 +1,11 @@ -AnnotatedForWithUse.java:14:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o -AnnotatedForWithUse.java:17:20: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. +AnnotatedForWithUse.java:16:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o +AnnotatedForWithUse.java:19:20: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. type of expression: @Nullable NullType method return type: @NonNull Object -AnnotatedForWithUse.java:29:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:31:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable NullType required: @NonNull Object -AnnotatedForWithUse.java:33:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:35:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @Nullable NullType required: @NonNull Object 4 errors From 958a714189cd9e19e094f62f930aa597b005d3a7 Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Tue, 21 Oct 2025 00:15:48 -0400 Subject: [PATCH 8/9] Line number --- .../onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out index ba4a2a114c55..31bfab3d78d0 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out @@ -1,7 +1,7 @@ -AnnotatedForWithUse.java:29:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:31:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable NullType required: @NonNull Object -AnnotatedForWithUse.java:33:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:35:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @Nullable NullType required: @NonNull Object 2 errors From 0e1e7510051f12d5471791a280ea5114bdc4276c Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Tue, 21 Oct 2025 00:27:10 -0400 Subject: [PATCH 9/9] Clean up --- .../onlyannotatedfor/AnnotatedForWithUse.java | 1 - .../AnnotatedForWithUseConservativeDefault.out | 10 +++++----- .../onlyannotatedfor/AnnotatedForWithUseNoFlag.out | 8 ++++---- .../AnnotatedForWithUseOnlyAnnotatedFor.out | 4 ++-- .../AnnotatedForWithUseOptimisticDefault.out | 14 +++++++------- ...ForWithUseOptimisticDefaultOnlyAnnotatedFor.out | 7 ------- 6 files changed, 18 insertions(+), 26 deletions(-) delete mode 100644 checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUse.java b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUse.java index 474b6e19bb72..0b9613e7013b 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUse.java +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUse.java @@ -6,7 +6,6 @@ * @compile/fail/ref=AnnotatedForWithUseOnlyAnnotatedFor.out -XDrawDiagnostics -Xlint:unchecked -processor org.checkerframework.checker.nullness.NullnessChecker -AonlyAnnotatedFor AnnotatedForWithUse.java * @compile/fail/ref=AnnotatedForWithUseConservativeDefault.out -XDrawDiagnostics -Xlint:unchecked -processor org.checkerframework.checker.nullness.NullnessChecker -AuseConservativeDefaultsForUncheckedCode=source AnnotatedForWithUse.java * @compile/fail/ref=AnnotatedForWithUseOptimisticDefault.out -XDrawDiagnostics -Xlint:unchecked -processor org.checkerframework.checker.nullness.NullnessChecker -AuseOptimisticDefaultsForUncheckedCode=source AnnotatedForWithUse.java - * @compile/fail/ref=AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out -XDrawDiagnostics -Xlint:unchecked -processor org.checkerframework.checker.nullness.NullnessChecker -AuseOptimisticDefaultsForUncheckedCode=source -AonlyAnnotatedFor AnnotatedForWithUse.java */ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseConservativeDefault.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseConservativeDefault.out index 1b82f40b27a8..0ff3b92abb99 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseConservativeDefault.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseConservativeDefault.out @@ -1,14 +1,14 @@ -AnnotatedForWithUse.java:27:36: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:28:36: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable Object required: @NonNull Object -AnnotatedForWithUse.java:31:18: compiler.err.proc.messager: [dereference.of.nullable] dereference of possibly-null reference u.get() -AnnotatedForWithUse.java:31:29: compiler.err.proc.messager: [method.invocation.invalid] call to toString() not allowed on the given receiver. +AnnotatedForWithUse.java:32:18: compiler.err.proc.messager: [dereference.of.nullable] dereference of possibly-null reference u.get() +AnnotatedForWithUse.java:32:29: compiler.err.proc.messager: [method.invocation.invalid] call to toString() not allowed on the given receiver. found : @UnknownInitialization Object required: @Initialized Object -AnnotatedForWithUse.java:33:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:34:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @UnknownKeyFor NullType required: @KeyForBottom Object -AnnotatedForWithUse.java:33:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:34:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @Nullable NullType required: @NonNull Object 5 errors diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out index d42716cce36e..5dc0af9d12e4 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseNoFlag.out @@ -1,11 +1,11 @@ -AnnotatedForWithUse.java:16:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o -AnnotatedForWithUse.java:19:20: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. +AnnotatedForWithUse.java:15:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o +AnnotatedForWithUse.java:18:20: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. type of expression: @Nullable NullType method return type: @NonNull Object -AnnotatedForWithUse.java:31:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:30:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable NullType required: @NonNull Object -AnnotatedForWithUse.java:35:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:34:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @Nullable NullType required: @NonNull Object 4 errors diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out index 31bfab3d78d0..c6d970780d61 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOnlyAnnotatedFor.out @@ -1,7 +1,7 @@ -AnnotatedForWithUse.java:31:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:30:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable NullType required: @NonNull Object -AnnotatedForWithUse.java:35:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. +AnnotatedForWithUse.java:34:19: compiler.err.proc.messager: [argument.type.incompatible] incompatible argument for parameter of of Unannotated.set. found : @Nullable NullType required: @NonNull Object 2 errors diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefault.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefault.out index 4b831e7ac2b4..492199e4871d 100644 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefault.out +++ b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefault.out @@ -1,18 +1,18 @@ -AnnotatedForWithUse.java:16:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.nullness.qual.KeyForBottom used on prohibited locations FIELD -AnnotatedForWithUse.java:16:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o -AnnotatedForWithUse.java:16:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.initialization.qual.FBCBottom used on prohibited locations FIELD +AnnotatedForWithUse.java:15:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.nullness.qual.KeyForBottom used on prohibited locations FIELD +AnnotatedForWithUse.java:15:16: compiler.err.proc.messager: [initialization.field.uninitialized] the default constructor does not initialize field o +AnnotatedForWithUse.java:15:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.initialization.qual.FBCBottom used on prohibited locations FIELD AnnotatedForWithUse.java:17:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.nullness.qual.KeyForBottom used on prohibited locations RETURN AnnotatedForWithUse.java:17:16: compiler.err.proc.messager: [type.invalid.annotations.on.location] annotation @org.checkerframework.checker.initialization.qual.FBCBottom used on prohibited locations RETURN -AnnotatedForWithUse.java:17:31: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. +AnnotatedForWithUse.java:18:20: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. type of expression: @UnknownKeyFor NullType method return type: @KeyForBottom Object -AnnotatedForWithUse.java:17:31: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. +AnnotatedForWithUse.java:18:20: compiler.err.proc.messager: [return.type.incompatible] incompatible types in return. type of expression: @Nullable NullType method return type: @NonNull Object -AnnotatedForWithUse.java:27:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:30:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @UnknownKeyFor NullType required: @KeyForBottom Object -AnnotatedForWithUse.java:27:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. +AnnotatedForWithUse.java:30:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. found : @Nullable NullType required: @NonNull Object 9 errors diff --git a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out b/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out deleted file mode 100644 index 402fc9aabcd0..000000000000 --- a/checker/jtreg/nullness/onlyannotatedfor/AnnotatedForWithUseOptimisticDefaultOnlyAnnotatedFor.out +++ /dev/null @@ -1,7 +0,0 @@ -AnnotatedForWithUse.java:27:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. -found : @UnknownKeyFor NullType -required: @KeyForBottom Object -AnnotatedForWithUse.java:27:19: compiler.err.proc.messager: [assignment.type.incompatible] incompatible types in assignment. -found : @Nullable NullType -required: @NonNull Object -2 errors