-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
WFLY-10025 Use new org.jboss.modules.ClassTransformer interface in addition to j.l.i.ClassFileTransformer #11307
WFLY-10025 Use new org.jboss.modules.ClassTransformer interface in addition to j.l.i.ClassFileTransformer #11307
Conversation
retest this please. |
@dmlloyd could you please review? Thanks! We had previously missed that we are supposed to return null, if the JPA persistence provider doesn't enhance the entity class. I made that change for the two #transform methods (byte[] + ByteBuffer), perhaps that will help performance as well. |
@@ -752,4 +754,8 @@ | |||
DeploymentUnitProcessingException differentSearchModuleDependencies(String deployment, String searchModuleName1, String searchModuleName2); | |||
|
|||
// id = 72, value = "Could not obtain TransactionListenerRegistry from transaction manager") | |||
|
|||
@Message(id = 73, value = "Invalid class format for deployment class %s.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A message like "Transformation of class %s failed" is probably more appropriate. The details will be included in the nested exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
easy change, thanks
@@ -44,13 +46,47 @@ public JPADelegatingClassFileTransformer(PersistenceUnitMetadata pu) { | |||
public byte[] transform(ClassLoader classLoader, String className, Class<?> aClass, ProtectionDomain protectionDomain, byte[] originalBuffer) throws | |||
IllegalClassFormatException { | |||
byte[] transformedBuffer = originalBuffer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you've introduced the new method, it's probably better to only have the logic in one place. This method can delegate to that one simply by calling transform(classLoader, className, protectionDomain, ByteBuffer.wrap(originalBuffer))
. You can factor out a private utility method to 'convert' the ByteBuffer
to an array which can be used in both methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed as suggested, will push in a minute.
Is it okay that transform(ClassLoader, String, Class, ProtectionDomain, byte[]), will now throw IlegalStateException instead of IllegalClassFormatException?
Will org.jboss.modules.ClassTransformer need to deal with redefining already loaded classes? Currently, j.l.i.ClassFileTransformer#transform is passed "Class<?> classBeingRedefined" for redefinition, which I just pass onto the JPA persistence providers (which they probably ignore).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we do not support redefinition. Changing the exception is probably fine in this case (we're the ones who catch it after all).
boolean transformed = false; | ||
byte[] transformedBuffer = bytes; | ||
for (javax.persistence.spi.ClassTransformer transformer : persistenceUnitMetadata.getTransformers()) { | ||
byte[] result = new byte[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment and allocation is pointless. If the transform call fails, an exception will be thrown; otherwise it will definitely assign result
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed.
9611448
to
32f2294
Compare
public ByteBuffer transform(ClassLoader classLoader, String className, ProtectionDomain protectionDomain, ByteBuffer classBytes) | ||
throws IllegalArgumentException { | ||
final byte[] bytes = getBytes(classBytes); | ||
final Class<?> aClass = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is useless and can be inlined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
final byte[] bytes = getBytes(classBytes); | ||
final Class<?> aClass = null; | ||
boolean transformed = false; | ||
byte[] transformedBuffer = bytes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having both bytes
and transformedBuffer
is redundant. You can just use bytes
directly and drop transformedBuffer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, will drop bytes, as I think we need transformedBuffer.
if (result != null) { | ||
transformedBuffer = result; | ||
transformed = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This boolean is unnecessary. The check for result
is sufficient; see below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy Monday :)
|
||
return transformed ? ByteBuffer.wrap(transformedBuffer) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return result != null ? ByteBuffer.wrap(result) : null;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are multiple calls to Transformer#transform and some return null but some return non-null, we need the boolean, to note that we saw at least one transformation, so we can return non-null result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, I missed the loop. Happy Monday
throws IllegalArgumentException { | ||
final byte[] bytes = getBytes(classBytes); | ||
final Class<?> aClass = null; | ||
boolean transformed = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See line 66 comment.
@@ -751,5 +753,9 @@ | |||
@Message(id = 71, value = "Deployment '%s' specified more than one Hibernate Search module name ('%s','%s')") | |||
DeploymentUnitProcessingException differentSearchModuleDependencies(String deployment, String searchModuleName1, String searchModuleName2); | |||
|
|||
// id = 72, value = "Could not obtain TransactionListenerRegistry from transaction manager") | |||
// id = 72, value = "Could not obtain TransactionListenerRegistry from transaction manager.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix seems unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the unneeded fix.
32f2294
to
b1e0aae
Compare
…dition to j.l.i.ClassFileTransformer
b1e0aae
to
c7b60a2
Compare
https://issues.jboss.org/browse/WFLY-10025
Note that we should remove the j.l.i.ClassFileTransformer interface after https://issues.jboss.org/browse/WFCORE-3685 changes DelegatingClassFileTransformer to use org.jboss.modules.ClassTransformer.