checker-framework icon indicating copy to clipboard operation
checker-framework copied to clipboard

Bug for Defaulting Type Variable Upper Bounds

Open skehrli opened this issue 8 months ago • 1 comments

On my fork, I'm working on a checker, for which all defaults must be bottom (as a first step). The bottom type qualifier is annotated to be the default for upper bounds.

@DefaultFor({
 ...
  TypeUseLocation.UPPER_BOUND
...
})

However, running this checker on the cf results in an error. Specifically,

gradlew :framework:checkResourceLeak

fails because a type var upper bound wrongly defaults to TOP. The failure occurs in InitializedFieldsAnnotatedTypeFactory.java. Running the checker on this file alone cannot reproduce the error, but compiling it together with GenericAnnotatedTypeFactory.java does. I minimized both files while still being able to replicate the error.

How to reproduce:

  1. clone my cf fork: git clone https://github.com/skehrli/checker-framework
  2. cd into the fork directory: cd /path/to/my/fork
  3. checkout to feature branch: git checkout rlc-collections-redesign
  4. extract binaries for maven: gradlew publishToMavenLocal
  5. clone repo with test case: git clone https://github.com/skehrli/test
  6. cd into the dir: cd /path/to/skehrli/test
  7. run: mvn compile

This compiles the two files together. When GenericAnnotatedTypeFactory.java is removed from the src dir and only InitializedFieldsAnnotatedTypeFactory.java is compiled, it completes without errors.

skehrli avatar Apr 12 '25 14:04 skehrli

You need to remove the override of createQualifierHierarchy in CollectionOwnershipAnnotatedTypeFactory. The default implementation is correct for this hierarchy. CollectionOwnershipQualifierHierarchy is implemented incorrectly and should just be deleted.

CollectionOwnershipAnnotatedTypeFactory.this.TOP.getClass() returns the class of the AnnotationMirror, which is CheckerFrameworkAnnotationMirror (org.checkerframework.javacutil.AnnotationUtils#annotationName is return the fully qualified class name.)

smillst avatar May 15 '25 17:05 smillst

Thanks a lot! This resolved it.

skehrli avatar May 17 '25 15:05 skehrli