Class BinaryStubDiffChecker

java.lang.Object
org.checkerframework.framework.stub.BinaryStubDiffChecker

public class BinaryStubDiffChecker extends Object
Test-only differential checker for the binary stub path. For every top-level class in the binary stub data — of the annotated JDK (run(org.checkerframework.framework.stub.AnnotationFileElementTypes, org.checkerframework.framework.stub.AnnotationFileElementTypes.BinaryStubDataCache, org.checkerframework.framework.type.AnnotatedTypeFactory)) and of each built-in checker stub file (diffBuiltinStub(java.lang.String, java.net.URL, org.checkerframework.framework.stub.BinaryStubData, org.checkerframework.framework.stub.AnnotationFileElementTypes, org.checkerframework.framework.type.AnnotatedTypeFactory)) — it loads the class's annotations twice, once through BinaryStubReader and once through the text-based AnnotationFileParser, into separate scratch AnnotationFileParser.AnnotationFileAnnotations containers, and reports any disagreement between the two as an error.

Because the binary writer and reader re-implement the text parser's semantics (TYPE_USE routing, array-component rules, type-parameter bounds, fake overrides, @FromStubFile marking, ...), a silent divergence between the two paths is the main correctness risk of the binary format. This check turns such a divergence into a loud test failure. It is activated by the -AbinaryStubDiffCheck option (used by the NullnessBinaryStubDiffTest JUnit test) and is never active in normal checker runs.

Comparison semantics:

  • Declaration annotations (AnnotationFileParser.AnnotationFileAnnotations.declAnnos) must have the same keys and, per key, the same set of annotations that some checker could act on, compared by class name and element values (see describe(javax.lang.model.element.AnnotationMirror)). Java platform annotations no checker consumes (@IntrinsicCandidate and other jdk.internal.* annotations the text parser resolves but the binary writer never keeps by design, java.lang.annotation.Retention/Target, @CFComment) are excluded; see comparedAnnotationNames(org.checkerframework.javacutil.AnnotationMirrorSet, org.checkerframework.framework.type.AnnotatedTypeFactory) for the full rationale.
  • Annotated types (AnnotationFileParser.AnnotationFileAnnotations.atypes) are compared per element key by a parallel, cycle-safe structural walk that compares the set of annotations (class names and element values) at every type component except some wildcard and type variable bounds (see compareAtm(org.checkerframework.framework.type.AnnotatedTypeMirror, org.checkerframework.framework.type.AnnotatedTypeMirror, java.lang.String, java.util.List<java.lang.String>, java.util.IdentityHashMap<org.checkerframework.framework.type.AnnotatedTypeMirror, java.util.Set<org.checkerframework.framework.type.AnnotatedTypeMirror>>) for which and why). An entry present on only one side is reported only if it carries an annotation outside wildcard and type variable bounds (see hasNonDerivedAnnotation(org.checkerframework.framework.type.AnnotatedTypeMirror, boolean, java.util.Set<org.checkerframework.framework.type.AnnotatedTypeMirror>)).
  • Fake overrides (AnnotationFileParser.AnnotationFileAnnotations.fakeOverrides) are compared by which (overridden method, subtype) entries exist, in both directions -- not by the stored types, whose baselines differ between the two loaders. Both directions are needed: the binary path resolves a fake override by a signature lookup and the text path by matching parameters structurally, so either can miss one the other applies. verifyRecordApplied(java.lang.String, org.checkerframework.framework.stub.BinaryStubData.ClassRecord, org.checkerframework.framework.stub.BinaryStubData, org.checkerframework.framework.stub.AnnotationFileParser.AnnotationFileAnnotations, org.checkerframework.framework.stub.AnnotationFileElementTypes, org.checkerframework.framework.type.AnnotatedTypeFactory, boolean, java.util.List<java.lang.String>) adds a record oracle on top, asserting that every binary record -- including a presence-only signature -- that matches an inherited method did produce an entry.
  • A type variable's primary annotation -- the shape written <@Nullable T> -- is compared by the structural walk wherever it appears, including on the type arguments of the declared type stored for a TypeElement.
  • A type variable's bounds -- the shape written <T extends @Nullable Object>, as on StackWalker.walk -- are covered by verifyTypeParamAnnosApplied(java.lang.String, java.lang.String, org.checkerframework.framework.stub.BinaryStubData.TypeParamRecord, org.checkerframework.framework.type.AnnotatedTypeMirror, org.checkerframework.framework.stub.BinaryStubData, org.checkerframework.framework.type.AnnotatedTypeFactory, java.util.List<java.lang.String>), an oracle against the binary record, rather than by the structural walk. The walk cannot compare them: the two loaders' bounds have different baselines, so a direct comparison reports defaults as mismatches (the text parser stores java.util.List's E with its upper bound already defaulted to @Initialized @NonNull @UnknownKeyFor, while the binary reader stores only what the stub wrote and lets the framework default the rest later). Asking instead whether everything the record promises was applied is immune to that, since defaulting only ever adds annotations.
  • Record stubs (AnnotationFileParser.AnnotationFileAnnotations.records) are compared structurally: same class keys and same component names in the same order. Annotation agreement is covered by the atypes and declAnnos checks above.