Class BinaryStubsCommandLineTest
java.lang.Object
org.checkerframework.framework.stub.BinaryStubsCommandLineTest
End-to-end tests for the reader side of binary
-Astubs support: AnnotationFileElementTypes's parseCommandLineStubLocation,
parseCommandLineStubResource, commandLineBinaryStub, and the
useBinaryForCommandLineStubs gate.
org.checkerframework.framework.stubifier.BinaryStubFileGeneratorTest covers only the writer
(round-tripping per-file and bundle output); this class drives real compilations through TypecheckExecutor, the same harness CheckerFrameworkPerDirectoryTest uses, so it
exercises the reader with dynamically generated fixtures that a checked-in jtreg test cannot have
(a checked-in .astub.bin.gz would defeat the point of a content digest).
Uses the SubtypingChecker with the test-only Encrypted qualifier (
org.checkerframework.framework.testchecker.util.Encrypted) rather than a real checker like
Nullness, so this test stays entirely within the framework module (Nullness lives in
checker, which depends on framework, not the other way around). A stub-annotated
Lib.maybeEncrypted() returns either @Encrypted Object (if its stub's annotation
took effect) or the default, unqualified Object (if it did not); passing the latter where
@Encrypted is required is an argument.type.incompatible error, so that error's
presence or absence is a direct, unambiguous signal of whether the stub was applied at all --
from either its text or its binary form.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal org.junit.rules.TemporaryFolderA fresh directory per test, deleted afterwards along with everything under it -- including a bundle file, which--bundlewrites as a sibling of the directory it covers rather than inside it. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid/** A method whose own@AnnotatedForexcludes the running checker is skipped by text parsing (AnnotationFileParser.processCallableDeclaration) and by the binary form alike, so its@Encryptedreturn type does not apply.voidA nested class inside a class whose@AnnotatedForexcludes the running checker is skipped by text parsing (AnnotationFileParser.processTypeDeclnever reaches the enclosing class's members) and by the binary form alike, although the binary form has a separate record for the nested class.voidThe binary form of a stub applies the same annotation element values as text parsing does, as the differential check (-AbinaryStubDiffCheck) verifies by comparing the annotations of both, with their values: a string value is unescaped, and an annotation with a value that the text parser rejects or cannot resolve is dropped as a whole, not kept with the value evaluated anyway, resolved against the enclosing class, or left out.voidA directorystubspassed to-Astubscan coincidentally share its bundle's target name (stubs.astub.bin.gz, beside it) with an unrelated top-level filestubs.astub's own per-file sibling (also namedstubs.astub.bin.gz, sincestubs.astub's sibling-naming rule appends the same suffix to a name that already ends in.astub).voidSetstempDirto this test's fresh directory.voidA fresh--bundlecovering the whole directory is read and applied.voidA fresh bundle also passes the differential check; seefreshPerFileBinaryPassesDiffCheck().voidA fresh binary sibling entry inside a.jarpassed to-Astubsis read and applied, the JAR-entry analogue offreshPerFileBinaryIsApplied().voidA fresh jar entry binary also passes the differential check, exercisingjarEntryToURL(thejar:URL construction-AbinaryStubDiffCheckneeds to re-read the entry's text form); seefreshPerFileBinaryPassesDiffCheck().voidA fresh per-file binary sibling is read and applied, with no extra warnings.voidA fresh per-file binary also passes the framework's own differential check (-AbinaryStubDiffCheck, fromBinaryStubDiffCheckerinframework-test), which independently text-parses the same.astubfile and compares every annotation it applies against what the binary form applied.voidA directory with a bundle for only some of its.astubfiles (a file was added after the bundle was generated) still applies the bundled file's binary form, text-parses the unbundled file, and warns about the incomplete setup.voidA.jarwith a binary sibling entry for only some of its.astubentries still applies the covered entry's binary form, text-parses the uncovered one, and warns about the incomplete setup -- the JAR-entry analogue ofincompleteBundleSetupWarns().voidA.jarentry whose only "sibling" at the expected binary name is a directory entry (e.g.voidUnder-AmergeStubsWithSource, text parsing of the annotated JDK applies the annotations of the private classes that the minimized JDK keeps (such asjava.util.AbstractList.Itr), which the binary stub file omits.voidA nested annotation as an annotation element value -- here in the array value of a container annotation -- applies both when the stub file is text-parsed and when it is read from its binary form.voidA bundle entry for a.astubfile nested in a subdirectory of the bundled directory is found (by its slash-separated relative path) and applied.voidA per-file binary sibling for a.astubfile nested in a subdirectory of the-Astubsdirectory is found and applied, exercising the relative-path computation that a flat (single-level)-Astubsdirectory does not.voidSanity check: with no-Astubsat all, the mismatch is reported.voidA per-file binary sibling that no longer matches its.astubfile's content (the file was edited after the binary was generated) is detected as stale, falls back to text-parsing the edited content, and warns -- never silently applies the stale annotation.voidA binary sibling entry inside a.jarthat no longer matches its.astubentry's content (the jar was rebuilt with an edited entry, keeping the old sibling from before) is detected as stale, falls back to text-parsing the edited content, and warns -- the JAR-entry analogue ofstaleBinaryFallsBackToEditedText().void-AstubWarnIfNotFoundforces text parsing even when a fresh binary is available (the gate inuseBinaryForCommandLineStubs), so the diagnostics are identical to text parsing and neither binary-specific warning is ever reached.voidA plain?in a stub takes the annotations of the type parameter's bound, replacing what the class file has on the wildcard's bound.voidLike text parsing, applying the binary form of a-Astubsfile warns about an annotation it skips because one of its values does not resolve.
-
Field Details
-
tempFolder
public final org.junit.rules.TemporaryFolder tempFolderA fresh directory per test, deleted afterwards along with everything under it -- including a bundle file, which--bundlewrites as a sibling of the directory it covers rather than inside it.
-
-
Constructor Details
-
BinaryStubsCommandLineTest
public BinaryStubsCommandLineTest()
-
-
Method Details
-
createTempDir
public void createTempDir()SetstempDirto this test's fresh directory. -
noStubGivesMismatch
Sanity check: with no-Astubsat all, the mismatch is reported.- Throws:
IOException
-
unboundedWildcardTakesTypeParameterBound
A plain?in a stub takes the annotations of the type parameter's bound, replacing what the class file has on the wildcard's bound. Text parsing and the binary form must agree: both giveLib.make().get()the unqualified type, so assigning it to an@Encryptedvariable is an error.- Throws:
IOException
-
freshPerFileBinaryIsApplied
A fresh per-file binary sibling is read and applied, with no extra warnings.- Throws:
IOException
-
staleBinaryFallsBackToEditedText
A per-file binary sibling that no longer matches its.astubfile's content (the file was edited after the binary was generated) is detected as stale, falls back to text-parsing the edited content, and warns -- never silently applies the stale annotation.- Throws:
IOException
-
freshBundleIsApplied
A fresh--bundlecovering the whole directory is read and applied.- Throws:
IOException
-
incompleteBundleSetupWarns
A directory with a bundle for only some of its.astubfiles (a file was added after the bundle was generated) still applies the bundled file's binary form, text-parses the unbundled file, and warns about the incomplete setup.- Throws:
IOException
-
stubWarnIfNotFoundGateForcesTextParsing
-AstubWarnIfNotFoundforces text parsing even when a fresh binary is available (the gate inuseBinaryForCommandLineStubs), so the diagnostics are identical to text parsing and neither binary-specific warning is ever reached.- Throws:
IOException
-
nestedPerFileBinaryIsApplied
A per-file binary sibling for a.astubfile nested in a subdirectory of the-Astubsdirectory is found and applied, exercising the relative-path computation that a flat (single-level)-Astubsdirectory does not.- Throws:
IOException
-
nestedBundleEntryIsApplied
A bundle entry for a.astubfile nested in a subdirectory of the bundled directory is found (by its slash-separated relative path) and applied.- Throws:
IOException
-
bundleNameCollisionWithPerFileSiblingIsIgnored
A directorystubspassed to-Astubscan coincidentally share its bundle's target name (stubs.astub.bin.gz, beside it) with an unrelated top-level filestubs.astub's own per-file sibling (also namedstubs.astub.bin.gz, sincestubs.astub's sibling-naming rule appends the same suffix to a name that already ends in.astub).binaryStubBundleFormust recognize, via the magic number, that the file at that path is not actually a bundle, and silently fall back -- without misapplying anything and without a spurious diagnostic -- to per-file siblings, which still work normally for files genuinely insidestubs/.- Throws:
IOException
-
freshPerFileBinaryPassesDiffCheck
A fresh per-file binary also passes the framework's own differential check (-AbinaryStubDiffCheck, fromBinaryStubDiffCheckerinframework-test), which independently text-parses the same.astubfile and compares every annotation it applies against what the binary form applied. This is a second, more exhaustive layer of verification than this test's ownhas(java.util.List<javax.tools.Diagnostic<? extends javax.tools.JavaFileObject>>, java.lang.String)assertions: it catches a binary whose annotation resolution is silently wrong, not merely absent.- Throws:
IOException
-
annotatedForOnMethodExcludingTheCheckerSkipsIt
/** A method whose own@AnnotatedForexcludes the running checker is skipped by text parsing (AnnotationFileParser.processCallableDeclaration) and by the binary form alike, so its@Encryptedreturn type does not apply.- Throws:
IOException
-
annotatedForOnOuterClassExcludingTheCheckerSkipsNestedClass
A nested class inside a class whose@AnnotatedForexcludes the running checker is skipped by text parsing (AnnotationFileParser.processTypeDeclnever reaches the enclosing class's members) and by the binary form alike, although the binary form has a separate record for the nested class.- Throws:
IOException
-
annotationValuesMatchTextParsing
The binary form of a stub applies the same annotation element values as text parsing does, as the differential check (-AbinaryStubDiffCheck) verifies by comparing the annotations of both, with their values: a string value is unescaped, and an annotation with a value that the text parser rejects or cannot resolve is dropped as a whole, not kept with the value evaluated anyway, resolved against the enclosing class, or left out.- Throws:
IOException
-
unresolvableValueIsWarnedAbout
Like text parsing, applying the binary form of a-Astubsfile warns about an annotation it skips because one of its values does not resolve.- Throws:
IOException
-
nestedAnnotationValueApplies
A nested annotation as an annotation element value -- here in the array value of a container annotation -- applies both when the stub file is text-parsed and when it is read from its binary form.- Throws:
IOException
-
mergeStubsWithSourceTextParsesTheAnnotatedJdk
Under-AmergeStubsWithSource, text parsing of the annotated JDK applies the annotations of the private classes that the minimized JDK keeps (such asjava.util.AbstractList.Itr), which the binary stub file omits. The annotated JDK is then text-parsed, so the differential check, which compares the two whenever the binary is read, finds no mismatch.- Throws:
IOException
-
freshBundlePassesDiffCheck
A fresh bundle also passes the differential check; seefreshPerFileBinaryPassesDiffCheck().- Throws:
IOException
-
freshJarBinaryIsApplied
A fresh binary sibling entry inside a.jarpassed to-Astubsis read and applied, the JAR-entry analogue offreshPerFileBinaryIsApplied().- Throws:
IOException
-
freshJarBinaryPassesDiffCheck
A fresh jar entry binary also passes the differential check, exercisingjarEntryToURL(thejar:URL construction-AbinaryStubDiffCheckneeds to re-read the entry's text form); seefreshPerFileBinaryPassesDiffCheck().- Throws:
IOException
-
staleJarBinaryFallsBackToEditedText
A binary sibling entry inside a.jarthat no longer matches its.astubentry's content (the jar was rebuilt with an edited entry, keeping the old sibling from before) is detected as stale, falls back to text-parsing the edited content, and warns -- the JAR-entry analogue ofstaleBinaryFallsBackToEditedText().- Throws:
IOException
-
incompleteJarSetupWarns
A.jarwith a binary sibling entry for only some of its.astubentries still applies the covered entry's binary form, text-parses the uncovered one, and warns about the incomplete setup -- the JAR-entry analogue ofincompleteBundleSetupWarns(). Also confirms that aJarEntryAnnotationFileResource, not just aFileAnnotationFileResource, participates in that accounting.- Throws:
IOException
-
jarBinarySiblingDirectoryEntryIsIgnored
A.jarentry whose only "sibling" at the expected binary name is a directory entry (e.g.Lib.astub.bin.gz/, not a real file) is treated as having no binary form at all, not misread:JarFile.getJarEntry(java.lang.String)silently falls back to matchingname + "/"when the exact name is absent, soparseCommandLineStubJarResourcemust reject a directory match explicitly. Also confirms this falls back to text parsing rather than throwing, since a real archive with a stray directory entry at that path (e.g. from a mis-packaged build) must still compile successfully.- Throws:
IOException
-