The ClassTransform
returned by ClassTransform.transformingMethods
is an instance of jdk.internal.classfile.impl.TransformImpl.ClassMethodTransform
. This class (well, record) overrides andThen
so that when the next
transform is also a ClassMethodTransform
, it will return a new ClassMethodTransform
with the MethodTransform
s chained and a predicate equivalent to first.and(second)
.
The documentation of ClassTransform.andThen
says “elements presented to the builder of this transform will become the input to the next transform”. Because ClassMethodTransform
will present non-matching elements to the builder, I believe the overridden implementation does not comply with the definition of ClassTransform.andThen
.
Example:
ClassTransform.transformingMethods(mm -> mm.methodName().equalsString("foo"), ...)
.andThen(ClassTransform.transformingMethods(mm -> mm.methodName().equalsString("bar"), ...))
With the override, neither transform will ever be applied, because mm.methodName().equalsString("foo") && mm.methodName().equalsString("bar")
is an impossible condition.
So I suppose I have two questions here:
- If this is unintended behaviour, how should I report this issue to the OpenJDK developers. https://github.com/openjdk/jdk does not accept issues, and https://bugs.openjdk.org seems to require login to open new issues, but I believe that is intended for members of the project.
- If this is intended behaviour, how are users of the API expected to chain such transforms “independently” (as they would be if this override did not exist)? I could create a wrapper class to foil the
instanceof
check, but that seems like a poor solution.