Parse byte/short/char/boolean/float array attributes#36917
Open
junhyeong9812 wants to merge 1 commit into
Open
Parse byte/short/char/boolean/float array attributes#36917junhyeong9812 wants to merge 1 commit into
junhyeong9812 wants to merge 1 commit into
Conversation
The java.lang.classfile based ClassFileAnnotationDelegate only converted int, long and double array attributes into primitive arrays; byte, short, char, boolean and float arrays fell through to the default branch and were boxed (Byte[], Short[], Character[], Boolean[], Float[]). On JDK 24+ this made TypeMappedAnnotation reject the value with an IllegalStateException when such an attribute was accessed, since the declared attribute type is the primitive array. Empty arrays returned an Object[0] and were unaffected, masking the issue. Convert these element types to primitive arrays as well, matching the ASM-based reader. Signed-off-by: junhyeong9812 <pickjog@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
On JDK 24+, annotation metadata is read through the
java.lang.classfilebasedClassFileAnnotationDelegate(selected byMetadataReaderFactoryDelegate).Problem
parseArrayValue()converted onlyint,longanddoublearray attributes into primitivearrays.
byte,short,char,booleanandfloatarrays fell through to the default branchand were boxed into
Byte[],Short[],Character[],Boolean[]andFloat[]. When such anattribute is later accessed,
TypeMappedAnnotationadapts the value against the declaredattribute type (e.g.
byte[]) and throws:Empty arrays returned
Object[0]and were handled separately, which masked the issue. TheASM-based reader returns genuine primitive arrays (see
MergedAnnotationMetadataVisitorTests),confirming the intended behavior; the ClassFile reader should match.
Fix
Add explicit cases for
OfByte/OfShort/OfChar/OfBoolean/OfFloatthat build thecorresponding primitive array. (
Streamoffers nomapToByte/mapToShort/mapToChar/mapToBoolean/mapToFloat, so a small loop is used, alongside the existingOfInt/OfLong/OfDoublecases.)A regression test is added under
src/test/java24(thejava24Testsource set); it fails onthe current code with the
IllegalStateExceptionabove and passes with the fix.