Class JavaStubifierTest

java.lang.Object
org.checkerframework.framework.stubifier.JavaStubifierTest

public class JavaStubifierTest extends Object
Regression test for a bug where JavaStubifier's BinaryStubWriter was held in a private static final field: since main can process several directories in one invocation, and a BinaryStubWriter accumulates every class passed to process in instance fields with no reset between calls, reusing one writer across directories made each directory's own annotated-jdk.bin.gz also contain every earlier directory's classes.
  • Constructor Details

    • JavaStubifierTest

      public JavaStubifierTest()
  • Method Details

    • unwritableBinaryStubAbortsRatherThanLeavingAStaleFile

      public void unwritableBinaryStubAbortsRatherThanLeavingAStaleFile() throws IOException
      A binary stub that cannot be written must abort the run, not leave a stale or truncated file behind.

      process used to print the IOException to stderr and return. Whatever annotated-jdk.bin.gz an earlier run had left in the directory then shipped, and the checker prefers that file over the text stubs whenever it exists, so its (wrong) contents would be applied in place of the JDK's real annotations, silently. BinaryStubFileGenerator already treats the same file-level failure as fatal.

      The write is made to fail by putting a directory where the output file belongs.

      Throws:
      IOException
    • eachDirectoryGetsOnlyItsOwnClasses

      public void eachDirectoryGetsOnlyItsOwnClasses() throws IOException
      Verifies that processing two directories in one main() invocation does not leak classes from the first directory into the second one's binary stub output; see the class documentation for the underlying bug.
      Throws:
      IOException - if a temporary file or directory cannot be created, written, or read
    • recordOnlyFileIsKept

      public void recordOnlyFileIsKept() throws IOException
      Regression test for the "does this file have any interesting declaration" check. RecordDeclaration extends TypeDeclaration, so the simplified cu.findAll(TypeDeclaration.class).isEmpty() check correctly treats a record-only file as non-empty and keeps it. This test verifies that a file containing only a record declaration is not deleted (previously it was deleted because BinaryStubWriter did not support records, but now it does).
      Throws:
      IOException
    • unloadableAnnotationFailsWithFilePathInMessage

      public void unloadableAnnotationFailsWithFilePathInMessage() throws IOException
      By default, an unloadable annotation aborts the whole run, and the failure names both the annotation and the source file that was being processed -- the file path used to be missing, which made finding the offending file among thousands require grepping the whole tree.
      Throws:
      IOException
    • skipUnloadableAnnotationsFlagOmitsAnnotationAndSucceeds

      public void skipUnloadableAnnotationsFlagOmitsAnnotationAndSucceeds() throws IOException
      With JavaStubifier.SKIP_UNLOADABLE_ANNOTATIONS_FLAG, the same input succeeds instead: the unloadable annotation is dropped from the binary stub output (so the field ends up with no annotations, and the annotated-JDK writer then omits its record entirely, per BinaryStubWriterTest.jdkWriterDemotesUnannotatedMethodRecords()'s analogous case for methods), and a warning naming the annotation and the file is printed to stderr.
      Throws:
      IOException