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
HHH-13343 : Bytecode enhancement using ByteBuddy fails when the class is not available from the provided ClassLoader #2825
Conversation
… is not available from the provided ClassLoader
@@ -143,8 +140,8 @@ public EnhancerImpl(final EnhancementContext enhancementContext, final ByteBuddy | |||
} |
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.
Should the Map<String,Resolution> in classFileLocator, be cleared after each enhance(String className, byte[] originalBytes) call to avoid keeping the 'originalBytes' in memory, for large deployments?
Does the transformation of entity classes involves following (class) references to other entity classes? If yes, then we probably cannot clear the Map<String,Resolution>, since they will be needed for the transformations that span multiple classes being referenced by ByteBuddy.
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.
@scottmarlow, good questions. I was wondering about your second point as well.
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.
IMO, if Hibernate is enhancing application entity class named 'A' that is associated with class 'B', regardless of which class is loaded/defined/enhanced first, when the other class is enhanced, the Map<String, Resolution> in ClassFileLocator, would be the (input) unenhanced class, instead of the enhanced (returned) class. I think it is likely that we can clear the Map after each call to enhance(), since we wouldn't want to use the (unenhanced) entity class. Also it is unlikely that enhancing more than the class that is passed to the enhance() method, at the same time, would work (instead we should only enhance each class separately.
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.
I think this change will be ready after we are clearing the Map contents, at the tail end of the enhance() call, as per my comments.
|
||
private class EnhancerClassFileLocator extends ClassFileLocator.ForClassLoader { | ||
|
||
private Map<String,Resolution> nameToResolutionMap = new HashMap<>(); |
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.
I suppose that instead of clearing the Map, we don't really need a map, but to instead just keep the name + bytes set during the ctor and create a new EnhancerClassFileLocator for each call to enhance(). The instead of nameToResultionMap.get(name), we could just see if saved name is equal to the name parameter, if yes, return new Resolution.Explicit( bytes).
So, I'm now having second thoughts about my comments from yesterday about not needing the Map collection. I think we would need to try that change against the WildFly tests to make sure they pass. |
@scottmarlow, IIUC, Assuming this is what is expected, I agree that there is no need for |
… is not available from the provided ClassLoader
@scottmarlow, I pushed a commit that removes the |
Travis failures are due to https://hibernate.atlassian.net/browse/HHH-13357. |
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.
Looks good, we are passing the https://issues.jboss.org/browse/WFLY-11891 tests now!
https://hibernate.atlassian.net/browse/HHH-13343