Class BinaryStubReaderTest
BinaryStubReader.classRecordKind(javax.lang.model.element.ElementKind).
Regression test for using the annotated JDK across JDK versions whose API can drift out from
under a fixed stub source: java.nio.ByteOrder became a real enum in JDK 26 after being a
plain class through JDK 25, while the annotated JDK's own ByteOrder.java stub still
declares it as a class. AnnotationFileParser.processTypeDecl has an existing, unrelated
defensive check for exactly this kind of drift on the text side (it warns and skips the whole
type when the real element's kind does not match the stub declaration's kind);
classRecordKind is the corresponding building block for the binary side, mapping a real
TypeElement's kind to the BinaryStubData.ClassRecord.KIND_* constant it must match.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidConfirms a real annotation type maps toKIND_ANNOTATION_TYPE, notKIND_CLASS_OR_INTERFACE.voidConfirms a real class and a real interface both map toKIND_CLASS_OR_INTERFACE, and so are treated as interchangeable with each other but not with an enum or annotation type.voidConfirmsBinaryStubReader.coerceToKind(java.lang.Object, javax.lang.model.type.TypeKind)narrows and widens between every numeric kind, and converts a character value for a numeric member through its code point, matching the text parser'sconvert((int) charValue, valueKind).voidConfirmsBinaryStubReader.coerceToKind(java.lang.Object, javax.lang.model.type.TypeKind)leaves a value alone when the member's kind is not a numeric primitive -- in particularTypeKind.NONE, whichaddValueToBuilderuses when the annotation member cannot be found at all.voidConfirms a real enum maps toKIND_ENUM, notKIND_CLASS_OR_INTERFACE-- exactly the distinction that a stub still declaringjava.nio.ByteOrderas a class must trip on JDK 26, where the real type is now an enum.voidConfirms thatAnnotationConstants.findField(javax.lang.model.element.TypeElement, java.lang.String, javax.lang.model.util.Elements, boolean)also finds an enum constant:TimeUnit.SECONDSis anENUM_CONSTANT, not aFIELD, and the same lookup resolves both kinds of'e'value.voidRegression test for the traversal order of the field lookup,AnnotationConstants.findField(javax.lang.model.element.TypeElement, java.lang.String, javax.lang.model.util.Elements, boolean): the binary reader's lookup used to exhaust the whole superclass chain before ever looking at an interface, whereas the text parser'sAnnotationFileParser#findFieldElementloops overElementUtils.getAllFieldsIn, which interleaves interfaces with superclasses (a type's directly-implemented interfaces are visited before its superclass's superclass).voidRegression test for the root cause of a bug inBinaryStubReader.resolveSingleValue(java.lang.Object, javax.lang.model.type.TypeKind, java.lang.String, org.checkerframework.framework.type.AnnotatedTypeFactory, org.checkerframework.framework.stub.BinaryStubData, org.checkerframework.framework.stub.AnnotationFileElementTypes): the writer tags everyFieldAccessExprannotation value with the same'e'tag (seeBinaryStubWriter#writeValue), regardless of whether the referenced member is an enum constant or a plain static final field, so the reader cannot tell which one it is from the tag alone.voidConfirmsElementUtils.getModuleElement(used byAnnotationFileParser#processModuleto resolve a stub-declared module name to a real element, mirroringprocessPackage'selements.getPackageElement) resolves a real module name to a non-null element, and returnsnullfor a nonexistent one.voidRegression test forBinaryStubReader.coerceToKind(java.lang.Object, javax.lang.model.type.TypeKind): an integral literal written for a floating-point annotation member must be converted to that member's kind.voidRegression test for the root cause of a bug inBinaryStubReader.applyRecordComponents: a record component'sRECORD_COMPONENT-kind element (returned byTypeElement.getRecordComponents()) is a distinctElementfrom its compiler-generated backingFIELD-kind element (returned byElementFilter.fieldsIn), even though both share the same simple name.voidConfirms a real record maps toKIND_RECORD, notKIND_CLASS_OR_INTERFACE.
-
Constructor Details
-
BinaryStubReaderTest
public BinaryStubReaderTest()
-
-
Method Details
-
classAndInterfaceMapToClassOrInterface
Confirms a real class and a real interface both map toKIND_CLASS_OR_INTERFACE, and so are treated as interchangeable with each other but not with an enum or annotation type.- Throws:
Exception- if a test compilation cannot be created
-
enumMapsToEnumNotClassOrInterface
Confirms a real enum maps toKIND_ENUM, notKIND_CLASS_OR_INTERFACE-- exactly the distinction that a stub still declaringjava.nio.ByteOrderas a class must trip on JDK 26, where the real type is now an enum.- Throws:
Exception- if the test compilation cannot be created
-
annotationTypeMapsToAnnotationType
Confirms a real annotation type maps toKIND_ANNOTATION_TYPE, notKIND_CLASS_OR_INTERFACE.- Throws:
Exception- if the test compilation cannot be created
-
getModuleElementResolvesRealModule
ConfirmsElementUtils.getModuleElement(used byAnnotationFileParser#processModuleto resolve a stub-declared module name to a real element, mirroringprocessPackage'selements.getPackageElement) resolves a real module name to a non-null element, and returnsnullfor a nonexistent one.Elements.getModuleElement(CharSequence)itself is JDK 9+ only, so this also exercises thatElementUtils's reflective wrapper works on the JDK actually running this test.- Throws:
Exception- if the test compilation cannot be created
-
findFieldResolvesANonEnumStaticConstant
public void findFieldResolvesANonEnumStaticConstant()Regression test for the root cause of a bug inBinaryStubReader.resolveSingleValue(java.lang.Object, javax.lang.model.type.TypeKind, java.lang.String, org.checkerframework.framework.type.AnnotatedTypeFactory, org.checkerframework.framework.stub.BinaryStubData, org.checkerframework.framework.stub.AnnotationFileElementTypes): the writer tags everyFieldAccessExprannotation value with the same'e'tag (seeBinaryStubWriter#writeValue), regardless of whether the referenced member is an enum constant or a plain static final field, so the reader cannot tell which one it is from the tag alone.resolveSingleValueused to only look for anENUM_CONSTANTmember and silently drop the value otherwise, so a stub value likeIntRange(to = Integer.MAX_VALUE)lost the member entirely. This test confirms that the lookup,AnnotationConstants.findField(javax.lang.model.element.TypeElement, java.lang.String, javax.lang.model.util.Elements, boolean), finds a real, non-enum constant field and thatBinaryStubReader.coerceToKind(java.lang.Object, javax.lang.model.type.TypeKind)then narrows its value to the annotation member's declared kind, matching whatAnnotationFileParser.getValueOfExpressionInAnnotationdoes for the text parser. -
findFieldMatchesAnEnumConstant
public void findFieldMatchesAnEnumConstant()Confirms thatAnnotationConstants.findField(javax.lang.model.element.TypeElement, java.lang.String, javax.lang.model.util.Elements, boolean)also finds an enum constant:TimeUnit.SECONDSis anENUM_CONSTANT, not aFIELD, and the same lookup resolves both kinds of'e'value. -
findFieldMatchesTextParserOrderForAmbiguousName
Regression test for the traversal order of the field lookup,AnnotationConstants.findField(javax.lang.model.element.TypeElement, java.lang.String, javax.lang.model.util.Elements, boolean): the binary reader's lookup used to exhaust the whole superclass chain before ever looking at an interface, whereas the text parser'sAnnotationFileParser#findFieldElementloops overElementUtils.getAllFieldsIn, which interleaves interfaces with superclasses (a type's directly-implemented interfaces are visited before its superclass's superclass). For an ambiguous simple name declared in bothIface(implemented directly byChild) andGrandparent(two levels upChild's superclass chain), the old recursion returned the superclass field;getAllFieldsIn-- and so the text parser -- returns the interface field first. This test pins the field-lookup order to match the text parser.- Throws:
Exception- if the test compilation cannot be created
-
recordMapsToRecordNotClassOrInterface
Confirms a real record maps toKIND_RECORD, notKIND_CLASS_OR_INTERFACE.- Throws:
Exception- if the test compilation cannot be created
-
integralValueIsWidenedToFloatingPointMember
public void integralValueIsWidenedToFloatingPointMember()Regression test forBinaryStubReader.coerceToKind(java.lang.Object, javax.lang.model.type.TypeKind): an integral literal written for a floating-point annotation member must be converted to that member's kind.The writer records every integral literal as a long, so
@DoubleExample(0)and@DoubleExample(0L)(both legal Java whenDoubleExample.value()is adouble; seechecker/jtreg/stubs/issue1542/Stub.astub) reach the reader as aLong. Returning anIntegerfor them, as the reader used to, makesAnnotationBuilder.setValuethrow and the whole annotation get silently dropped. The text parser'sAnnotationFileParser.converthas always had theFLOATandDOUBLEcases. -
coerceToKindConvertsBetweenNumericKinds
public void coerceToKindConvertsBetweenNumericKinds()ConfirmsBinaryStubReader.coerceToKind(java.lang.Object, javax.lang.model.type.TypeKind)narrows and widens between every numeric kind, and converts a character value for a numeric member through its code point, matching the text parser'sconvert((int) charValue, valueKind). -
coerceToKindLeavesNonNumericKindsAlone
public void coerceToKindLeavesNonNumericKindsAlone()ConfirmsBinaryStubReader.coerceToKind(java.lang.Object, javax.lang.model.type.TypeKind)leaves a value alone when the member's kind is not a numeric primitive -- in particularTypeKind.NONE, whichaddValueToBuilderuses when the annotation member cannot be found at all. -
recordComponentElementDiffersFromItsBackingField
Regression test for the root cause of a bug inBinaryStubReader.applyRecordComponents: a record component'sRECORD_COMPONENT-kind element (returned byTypeElement.getRecordComponents()) is a distinctElementfrom its compiler-generated backingFIELD-kind element (returned byElementFilter.fieldsIn), even though both share the same simple name.AnnotationFileParser.processRecordField(the text parser) stores a component's annotated type inatypeskeyed by theFIELDelement;applyRecordComponentspreviously keyed it by theRECORD_COMPONENTelement instead, which silently made a component's type-use annotations unreachable throughAnnotationFileElementTypes#getAnnotatedTypeMirror(a bareElement-keyed lookup with no name-based fallback). This test locks in the fact that motivated the fix, so a future change cannot reintroduce the mismatch without also breaking this test.- Throws:
Exception- if the test compilation cannot be created
-