Class AnnotationFileElementTypesTest

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

public class AnnotationFileElementTypesTest extends Object
Unit test for AnnotationFileElementTypes.buildSigIndex(java.util.List<javax.lang.model.element.ExecutableElement>) and AnnotationFileElementTypes.findAnnotatedJdk(java.lang.Class<?>).

Regression test for a crash: TypesUtils.simpleTypeName throws BugInCF (a RuntimeException) for a parameter whose type is TypeKind.ERROR -- which is exactly what happens for an unresolvable parameter type, e.g. a JDK-internal type not exported to the annotation processor's module (this crashed checkNullness/checkInterning on sun.util.locale.provider.LocaleResources while annotating a real JDK class's method). buildSigIndex must catch that exception and skip the method, not propagate it: a previous version of the surrounding catch block explicitly rethrew BugInCF under the mistaken assumption that it always signals an unrelated internal bug, which reintroduced the crash.

The JDK-internal trigger is specific to a particular JDK's module-export configuration and is not reliably reproducible from ordinary test source; this test instead constructs a portable, JDK-version-independent TypeKind.ERROR parameter directly, by compiling a method whose parameter type does not exist. javac's error recovery still produces a real ExecutableElement for such a method, with the unresolvable parameter's type attributed as TypeKind.ERROR.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    The actual regression test: buildSigIndex must not throw when a method has an unresolvable (ERROR-kind) parameter type; it must skip that method (it cannot be matched by any stub record anyway) and still index the other, resolvable methods of the class.
    void
    extractFqClassName handles both forms of the annotated JDK's layout -- a jar entry, which includes the annotated-jdk root, and a file path relative to that root -- and returns null for anything that does not follow the layout, so that the caller skips it instead of crashing on an unguarded substring.
    void
    extractModuleName returns the module directory segment of a module-info.java entry, for both forms of the layout, and null for anything else.
    void
    findAnnotatedJdk returns the annotated JDK in the jar or directory of the factory class if it has one, even when a jar earlier on the class path has an annotated JDK too, and otherwise the first one on the class path.
    void
    Confirms the reproduction: a method parameter whose type is unresolvable is attributed as TypeKind.ERROR, and TypesUtils.simpleTypeName (called by ElementUtils.getSimpleSignature, which buildSigIndex uses) throws for it.

    Methods inherited from class java.lang.Object

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

    • AnnotationFileElementTypesTest

      public AnnotationFileElementTypesTest()
  • Method Details

    • unresolvableParameterTypeIsErrorKind

      public void unresolvableParameterTypeIsErrorKind() throws Exception
      Confirms the reproduction: a method parameter whose type is unresolvable is attributed as TypeKind.ERROR, and TypesUtils.simpleTypeName (called by ElementUtils.getSimpleSignature, which buildSigIndex uses) throws for it. This documents why buildSigIndex must catch a RuntimeException, not just skip some narrower exception type.
      Throws:
      Exception - if the test compilation cannot be created
    • buildSigIndexSkipsUnresolvableParameterType

      public void buildSigIndexSkipsUnresolvableParameterType() throws Exception
      The actual regression test: buildSigIndex must not throw when a method has an unresolvable (ERROR-kind) parameter type; it must skip that method (it cannot be matched by any stub record anyway) and still index the other, resolvable methods of the class.
      Throws:
      Exception - if the test compilation cannot be created
    • testExtractFqClassName

      public void testExtractFqClassName()
      extractFqClassName handles both forms of the annotated JDK's layout -- a jar entry, which includes the annotated-jdk root, and a file path relative to that root -- and returns null for anything that does not follow the layout, so that the caller skips it instead of crashing on an unguarded substring.
    • testExtractModuleName

      public void testExtractModuleName()
      extractModuleName returns the module directory segment of a module-info.java entry, for both forms of the layout, and null for anything else.
    • testFindAnnotatedJdk

      public void testFindAnnotatedJdk() throws Exception
      findAnnotatedJdk returns the annotated JDK in the jar or directory of the factory class if it has one, even when a jar earlier on the class path has an annotated JDK too, and otherwise the first one on the class path.
      Throws:
      Exception