Class BinaryStubsCommandLineTest

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

public class BinaryStubsCommandLineTest extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    final org.junit.rules.TemporaryFolder
    A fresh directory per test, deleted afterwards along with everything under it -- including a bundle file, which --bundle writes as a sibling of the directory it covers rather than inside it.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    /** A method whose own @AnnotatedFor excludes the running checker is skipped by text parsing (AnnotationFileParser.processCallableDeclaration) and by the binary form alike, so its @Encrypted return type does not apply.
    void
    A nested class inside a class whose @AnnotatedFor excludes the running checker is skipped by text parsing (AnnotationFileParser.processTypeDecl never reaches the enclosing class's members) and by the binary form alike, although the binary form has a separate record for the nested class.
    void
    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.
    void
    A directory stubs passed to -Astubs can coincidentally share its bundle's target name (stubs.astub.bin.gz, beside it) with an unrelated top-level file stubs.astub's own per-file sibling (also named stubs.astub.bin.gz, since stubs.astub's sibling-naming rule appends the same suffix to a name that already ends in .astub).
    void
    Sets tempDir to this test's fresh directory.
    void
    A fresh --bundle covering the whole directory is read and applied.
    void
    A fresh bundle also passes the differential check; see freshPerFileBinaryPassesDiffCheck().
    void
    A fresh binary sibling entry inside a .jar passed to -Astubs is read and applied, the JAR-entry analogue of freshPerFileBinaryIsApplied().
    void
    A fresh jar entry binary also passes the differential check, exercising jarEntryToURL (the jar: URL construction -AbinaryStubDiffCheck needs to re-read the entry's text form); see freshPerFileBinaryPassesDiffCheck().
    void
    A fresh per-file binary sibling is read and applied, with no extra warnings.
    void
    A fresh per-file binary also passes the framework's own differential check ( -AbinaryStubDiffCheck, from BinaryStubDiffChecker in framework-test), which independently text-parses the same .astub file and compares every annotation it applies against what the binary form applied.
    void
    A directory with a bundle for only some of its .astub files (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.
    void
    A .jar with a binary sibling entry for only some of its .astub entries still applies the covered entry's binary form, text-parses the uncovered one, and warns about the incomplete setup -- the JAR-entry analogue of incompleteBundleSetupWarns().
    void
    A .jar entry whose only "sibling" at the expected binary name is a directory entry (e.g.
    void
    Under -AmergeStubsWithSource, text parsing of the annotated JDK applies the annotations of the private classes that the minimized JDK keeps (such as java.util.AbstractList.Itr), which the binary stub file omits.
    void
    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.
    void
    A bundle entry for a .astub file nested in a subdirectory of the bundled directory is found (by its slash-separated relative path) and applied.
    void
    A per-file binary sibling for a .astub file nested in a subdirectory of the -Astubs directory is found and applied, exercising the relative-path computation that a flat (single-level) -Astubs directory does not.
    void
    Sanity check: with no -Astubs at all, the mismatch is reported.
    void
    A per-file binary sibling that no longer matches its .astub file'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.
    void
    A binary sibling entry inside a .jar that no longer matches its .astub entry'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 of staleBinaryFallsBackToEditedText().
    void
    -AstubWarnIfNotFound forces text parsing even when a fresh binary is available (the gate in useBinaryForCommandLineStubs), so the diagnostics are identical to text parsing and neither binary-specific warning is ever reached.
    void
    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.
    void
    Like text parsing, applying the binary form of a -Astubs file warns about an annotation it skips because one of its values does not resolve.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • tempFolder

      public final org.junit.rules.TemporaryFolder tempFolder
      A fresh directory per test, deleted afterwards along with everything under it -- including a bundle file, which --bundle writes as a sibling of the directory it covers rather than inside it.
  • Constructor Details

    • BinaryStubsCommandLineTest

      public BinaryStubsCommandLineTest()
  • Method Details

    • createTempDir

      public void createTempDir()
      Sets tempDir to this test's fresh directory.
    • noStubGivesMismatch

      public void noStubGivesMismatch() throws IOException
      Sanity check: with no -Astubs at all, the mismatch is reported.
      Throws:
      IOException
    • unboundedWildcardTakesTypeParameterBound

      public void unboundedWildcardTakesTypeParameterBound() throws IOException
      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 give Lib.make().get() the unqualified type, so assigning it to an @Encrypted variable is an error.
      Throws:
      IOException
    • freshPerFileBinaryIsApplied

      public void freshPerFileBinaryIsApplied() throws IOException
      A fresh per-file binary sibling is read and applied, with no extra warnings.
      Throws:
      IOException
    • staleBinaryFallsBackToEditedText

      public void staleBinaryFallsBackToEditedText() throws IOException
      A per-file binary sibling that no longer matches its .astub file'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

      public void freshBundleIsApplied() throws IOException
      A fresh --bundle covering the whole directory is read and applied.
      Throws:
      IOException
    • incompleteBundleSetupWarns

      public void incompleteBundleSetupWarns() throws IOException
      A directory with a bundle for only some of its .astub files (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

      public void stubWarnIfNotFoundGateForcesTextParsing() throws IOException
      -AstubWarnIfNotFound forces text parsing even when a fresh binary is available (the gate in useBinaryForCommandLineStubs), so the diagnostics are identical to text parsing and neither binary-specific warning is ever reached.
      Throws:
      IOException
    • nestedPerFileBinaryIsApplied

      public void nestedPerFileBinaryIsApplied() throws IOException
      A per-file binary sibling for a .astub file nested in a subdirectory of the -Astubs directory is found and applied, exercising the relative-path computation that a flat (single-level) -Astubs directory does not.
      Throws:
      IOException
    • nestedBundleEntryIsApplied

      public void nestedBundleEntryIsApplied() throws IOException
      A bundle entry for a .astub file nested in a subdirectory of the bundled directory is found (by its slash-separated relative path) and applied.
      Throws:
      IOException
    • bundleNameCollisionWithPerFileSiblingIsIgnored

      public void bundleNameCollisionWithPerFileSiblingIsIgnored() throws IOException
      A directory stubs passed to -Astubs can coincidentally share its bundle's target name (stubs.astub.bin.gz, beside it) with an unrelated top-level file stubs.astub's own per-file sibling (also named stubs.astub.bin.gz, since stubs.astub's sibling-naming rule appends the same suffix to a name that already ends in .astub). binaryStubBundleFor must 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 inside stubs/.
      Throws:
      IOException
    • freshPerFileBinaryPassesDiffCheck

      public void freshPerFileBinaryPassesDiffCheck() throws IOException
      A fresh per-file binary also passes the framework's own differential check ( -AbinaryStubDiffCheck, from BinaryStubDiffChecker in framework-test), which independently text-parses the same .astub file 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 own has(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

      public void annotatedForOnMethodExcludingTheCheckerSkipsIt() throws IOException
      /** A method whose own @AnnotatedFor excludes the running checker is skipped by text parsing (AnnotationFileParser.processCallableDeclaration) and by the binary form alike, so its @Encrypted return type does not apply.
      Throws:
      IOException
    • annotatedForOnOuterClassExcludingTheCheckerSkipsNestedClass

      public void annotatedForOnOuterClassExcludingTheCheckerSkipsNestedClass() throws IOException
      A nested class inside a class whose @AnnotatedFor excludes the running checker is skipped by text parsing (AnnotationFileParser.processTypeDecl never 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

      public void annotationValuesMatchTextParsing() throws IOException
      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

      public void unresolvableValueIsWarnedAbout() throws IOException
      Like text parsing, applying the binary form of a -Astubs file warns about an annotation it skips because one of its values does not resolve.
      Throws:
      IOException
    • nestedAnnotationValueApplies

      public void nestedAnnotationValueApplies() throws IOException
      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

      public void mergeStubsWithSourceTextParsesTheAnnotatedJdk() throws IOException
      Under -AmergeStubsWithSource, text parsing of the annotated JDK applies the annotations of the private classes that the minimized JDK keeps (such as java.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

      public void freshBundlePassesDiffCheck() throws IOException
      A fresh bundle also passes the differential check; see freshPerFileBinaryPassesDiffCheck().
      Throws:
      IOException
    • freshJarBinaryIsApplied

      public void freshJarBinaryIsApplied() throws IOException
      A fresh binary sibling entry inside a .jar passed to -Astubs is read and applied, the JAR-entry analogue of freshPerFileBinaryIsApplied().
      Throws:
      IOException
    • freshJarBinaryPassesDiffCheck

      public void freshJarBinaryPassesDiffCheck() throws IOException
      A fresh jar entry binary also passes the differential check, exercising jarEntryToURL (the jar: URL construction -AbinaryStubDiffCheck needs to re-read the entry's text form); see freshPerFileBinaryPassesDiffCheck().
      Throws:
      IOException
    • staleJarBinaryFallsBackToEditedText

      public void staleJarBinaryFallsBackToEditedText() throws IOException
      A binary sibling entry inside a .jar that no longer matches its .astub entry'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 of staleBinaryFallsBackToEditedText().
      Throws:
      IOException
    • incompleteJarSetupWarns

      public void incompleteJarSetupWarns() throws IOException
      A .jar with a binary sibling entry for only some of its .astub entries still applies the covered entry's binary form, text-parses the uncovered one, and warns about the incomplete setup -- the JAR-entry analogue of incompleteBundleSetupWarns(). Also confirms that a JarEntryAnnotationFileResource, not just a FileAnnotationFileResource, participates in that accounting.
      Throws:
      IOException
    • jarBinarySiblingDirectoryEntryIsIgnored

      public void jarBinarySiblingDirectoryEntryIsIgnored() throws IOException
      A .jar entry 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 matching name + "/" when the exact name is absent, so parseCommandLineStubJarResource must 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