-
-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Signature parsing change with java.lang.classfile backend #1771
Comments
This code is creating a field with the same type as a method return type. The return type is erased, but calling `getGenericSignature()` turns the erased type back into a generic type. For methods with type parameters, this results in signatures that are invalid for field declarations, for example `<T:Ljava/lang/Object;>Ljava/lang/Object;Ljava/io/Serializable;`. Future versions of bytebuddy reject the invalid signature. See also raphw/byte-buddy#1771
This code is creating a field with the same type as a method return type. The return type is erased, but calling `getGenericSignature()` turns the erased type back into a generic type. For methods with type parameters, this results in signatures that are invalid for field declarations, for example `<T:Ljava/lang/Object;>Ljava/lang/Object;Ljava/io/Serializable;`. Future versions of bytebuddy reject the invalid signature. See also raphw/byte-buddy#1771
This is a misuse of Likely, this should just be ǹull In order to impose the same strictness as the Class File API, one would need to decompose any generic signature of a class file, what would be costly. Also, there are plenty of compilers (Scala, Kotlin) which have generated dozens of faulty signatures over the years that Byte Buddy needs to handle. There are even multiple explicit handlers in the code base, to fallback to a certain behaviour, if a faulty signature is discovered. Changing that default would be painful to many agents, so I'd rather not touch this. I think however it is a healthy approach to force in the Class File API to validate something. |
That all makes sense, thanks for taking a look. I'll fix that usage to pass
Out of curiosity do you know if that means that the Class File API is making a performance tradeoff to do that validation? Or is ASM doing similar but more lenient parsing, and the issue is that would have to be duplicated in bytebuddy if you wanted to stricter validation? |
Hi,
I've been experimenting with testing the new
java.lang.classfile
backend with JDK 25 EA builds. So far a lot of things seem to just work, but I ran into one regression that I think may be a usage error in the code using ByteBuddy, but that I was interested in input on.Running a test using apache beam with JDK 25 and bytebuddy at 6441732, I saw:
ByteBuddyDoFnInvokerFactory
is https://github.com/apache/beam/blob/48743e5c3ae4430a85e5ad6d8cd5e3a28a59417d/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyDoFnInvokerFactory.javaDebugging showed the bad signature is coming from here: https://github.com/apache/beam/blob/48743e5c3ae4430a85e5ad6d8cd5e3a28a59417d/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyDoFnInvokerFactory.java#L1314
The relevant bit is
Apparently
targetMethod.getReturnType().asErasure().getGenericSignature()
returns a generic method signature which include type variable declarations, which is illegal as a variable signature. I guess if you want an erased type you just shouldn't be passing a signature at all, so maybe the behaviour of.asErasure().getGenericSignature()
is working as intended? Updating it to passnull
instead of the bogus signature fixes the crash.The other noteworthy thing here is that
java.lang.classfile
is doing stricter validation of signatures, which is a good thing, but is also an incompatible change. I wondered if it's worth thinking about adding stricter signature validation to the other bytebuddy backends so the behaviour is consistent, and to help people catch these issues now and prepare for the switch?The text was updated successfully, but these errors were encountered: