Class StubparserRecordTest

java.lang.Object
org.checkerframework.framework.test.CheckerFrameworkPerDirectoryTest
org.checkerframework.checker.test.junit.StubparserRecordTest

public class StubparserRecordTest extends CheckerFrameworkPerDirectoryTest
Tests for stub parsing with records.

The records these stub files annotate are compiled from source, in this same directory, so the test needs -AmergeStubsWithSource: that is what makes an annotation file apply to a class that is being compiled.

Without it the test passed, but only by accident, and it was order-dependent. AnnotatedTypeFactory.fromElement consults the stub files only when declarationFromElement finds no tree for the element, so whether a source-declared element gets its stub annotations depends on whether javac still has its tree at the moment of the element's first use -- and whichever type is computed first is frozen into elementCache for the rest of the compilation. Adding a file to this directory whose name sorts before PairRecord.java was enough to change the answer: new PairRecord(null) in RecordUsage.java began reporting argument.type.incompatible, because the constructor's type was cached from its source declaration, without the @Nullable its stub file gives it.

  • Constructor Details

    • StubparserRecordTest

      public StubparserRecordTest(List<File> testFiles)
      Create a StubparserRecordTest.
      Parameters:
      testFiles - the files containing test code, which will be type-checked
  • Method Details

    • getTestDirs

      public static String[] getTestDirs()
    • resolveTestDirectory

      protected File resolveTestDirectory()
      Resolves the test root directory from the optional TestRootDirectory annotation or falls back to the default of currentDir/tests.
      Returns:
      the resolved directory
    • checkResult

      public void checkResult(TypecheckResult typecheckResult)
      Check that the TypecheckResult did not fail.
      Parameters:
      typecheckResult - result to check