Class BinaryStubDiffChecker
java.lang.Object
org.checkerframework.framework.stub.BinaryStubDiffChecker
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 (seedescribe(javax.lang.model.element.AnnotationMirror)). Java platform annotations no checker consumes (@IntrinsicCandidateand otherjdk.internal.*annotations the text parser resolves but the binary writer never keeps by design,java.lang.annotation.Retention/Target,@CFComment) are excluded; seecomparedAnnotationNames(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 (seecompareAtm(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 (seehasNonDerivedAnnotation(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 aTypeElement. - A type variable's bounds -- the shape written
<T extends @Nullable Object>, as onStackWalker.walk-- are covered byverifyTypeParamAnnosApplied(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 storesjava.util.List'sEwith 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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voiddiffBuiltinStub(String description, URL textResourceURL, BinaryStubData data, AnnotationFileElementTypes elementTypes, AnnotatedTypeFactory atypeFactory) Differential check for one built-in checker stub file (e.g.static voidrun(AnnotationFileElementTypes elementTypes, org.checkerframework.framework.stub.AnnotationFileElementTypes.BinaryStubDataCache cache, AnnotatedTypeFactory atypeFactory) Runs the differential check over every top-level class in the binary stub data and reports mismatches as errors via the checker.
-
Method Details
-
run
public static void run(AnnotationFileElementTypes elementTypes, org.checkerframework.framework.stub.AnnotationFileElementTypes.BinaryStubDataCache cache, AnnotatedTypeFactory atypeFactory) Runs the differential check over every top-level class in the binary stub data and reports mismatches as errors via the checker.- Parameters:
elementTypes- the stub-types AFET whose factory and stub sources to usecache- the per-compilation binary stub cache; its data supplies the classes to checkatypeFactory- the factory used to create types and parse annotations
-
diffBuiltinStub
public static void diffBuiltinStub(String description, URL textResourceURL, BinaryStubData data, AnnotationFileElementTypes elementTypes, AnnotatedTypeFactory atypeFactory) Differential check for one built-in checker stub file (e.g.jdk.astub): text-parses the.astubresource and applies its binary form into separate scratch containers, then reports any disagreement as an error, exactly like the annotated-JDK check inrun(org.checkerframework.framework.stub.AnnotationFileElementTypes, org.checkerframework.framework.stub.AnnotationFileElementTypes.BinaryStubDataCache, org.checkerframework.framework.type.AnnotatedTypeFactory). Both sides include@FromStubFilemarking, so the marking parity is verified as well.- Parameters:
description- resource description, used in report messagestextResourceURL- the URL of the.astubresourcedata- the binary form of the stub fileelementTypes- the stub-types AFET whose factory to useatypeFactory- the factory used to create types and parse annotations
-