Class AnnotationFileElementTypesTest
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidThe actual regression test:buildSigIndexmust 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.voidextractFqClassNamehandles both forms of the annotated JDK's layout -- a jar entry, which includes theannotated-jdkroot, 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 unguardedsubstring.voidextractModuleNamereturns the module directory segment of amodule-info.javaentry, for both forms of the layout, and null for anything else.voidfindAnnotatedJdkreturns 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.voidConfirms the reproduction: a method parameter whose type is unresolvable is attributed asTypeKind.ERROR, andTypesUtils.simpleTypeName(called byElementUtils.getSimpleSignature, whichbuildSigIndexuses) throws for it.
-
Constructor Details
-
AnnotationFileElementTypesTest
public AnnotationFileElementTypesTest()
-
-
Method Details
-
unresolvableParameterTypeIsErrorKind
Confirms the reproduction: a method parameter whose type is unresolvable is attributed asTypeKind.ERROR, andTypesUtils.simpleTypeName(called byElementUtils.getSimpleSignature, whichbuildSigIndexuses) throws for it. This documents whybuildSigIndexmust catch aRuntimeException, not just skip some narrower exception type.- Throws:
Exception- if the test compilation cannot be created
-
buildSigIndexSkipsUnresolvableParameterType
The actual regression test:buildSigIndexmust 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()extractFqClassNamehandles both forms of the annotated JDK's layout -- a jar entry, which includes theannotated-jdkroot, 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 unguardedsubstring. -
testExtractModuleName
public void testExtractModuleName()extractModuleNamereturns the module directory segment of amodule-info.javaentry, for both forms of the layout, and null for anything else. -
testFindAnnotatedJdk
findAnnotatedJdkreturns 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
-