Remove virtual field interfaces from reflection results - #4722
Conversation
iNikem
left a comment
There was a problem hiding this comment.
I hope you know what you are doing :D Instrumenting java.lang.Class seems scary
|
@laurit do you think we could get rid of these interfaces and use method handles to access the generated methods? |
|
@trask Firstly we would need to figure out a new way to detect whether virtual fields have been added to a class which is currently handled by testing for |
| @@ -36,6 +38,7 @@ public static Method[] filterMethods(Class<?> containingClass, Method[] methods) | |||
| return methods; | |||
| } else if (containingClass.isInterface() | |||
There was a problem hiding this comment.
If filtering of the interfaces works then this branch shouldn't evaluate to true. Similarly I suspect that https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/internal/internal-proxy/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/proxy/ProxyHelper.java might not be necessary any more.
There was a problem hiding this comment.
nice, I'll open an issue to try this 👍
trask
left a comment
There was a problem hiding this comment.
presence of
<clinit>method also changes the default serial version uid.
😭
| @@ -36,6 +38,7 @@ public static Method[] filterMethods(Class<?> containingClass, Method[] methods) | |||
| return methods; | |||
| } else if (containingClass.isInterface() | |||
There was a problem hiding this comment.
nice, I'll open an issue to try this 👍
…ry#4722) * Remove virtual field interfaces from reflection results * fix java8 and openj9
Resolves #4370
I initially planned to use asm
SerialVersionUIDAdderto addserialVersionUIDfield to serializable classes that don't declare it. This is needed to make sure that instrumented version of class has the sameserialVersionUIDas uninstrumented version. This approach failed with one of spring-batch tests because inside spring there is code that copies instances of an internal spring class via reflection and fails because it can't write toserialVersionUIDwhich is a static final field. We can't use the same reflection filtering code as we use for fields & methods added by virtual field implementetion because that filtering completely removes these members from reflection results. ForserialVersionUIDwe'd need it to be visible fromgetDeclaredField, so thatObjectStreamClasscan read it, and hidden fromgetDeclaredFields, so that code that isn't explicitly looking for it wouldn't stumble upon it. Instead of attempting to removeserialVersionUIDfromgetDeclaredFieldsI chose to remove interfaces added by virtual field implementation from the result ofgetInterfaces. This makes the defaultserialVersionUIDcomputation algorithm return the correct result on instrumented classes and there is no need to precomputeserialVersionUIDfor them.