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
Fixes order problem in client user code deployment #16610
Fixes order problem in client user code deployment #16610
Conversation
49dedfb
to
8716a86
Compare
@sancar But definition size doesn't correlate with inheritance. It depends only on amount of bytecode in the class. In your unit-tests, if we change
tests will fail. |
Yes, you are right. I assumed that child will always have the bytecode of its parent, and some more on top of it. Let me think another way to solve this. |
I think, the correct order of classes (hierarchy) can be determined via Reflection API. |
The issue is related to inheritance. If a a ChildClass is configured first, it was trying to be defined first. It was searching for its parent, and failing. The issue is fixed by sorting the class definitions by size in ascending order. This way, we will make sure that a parent class will be defined first. fixes hazelcast#16575 (cherry picked from commit c9b0bcc)
8716a86
to
cb371fc
Compare
@ihsandemir @galibey @galibey I have updated the pr for the inheritance order problem. |
for (String className : classNames) { | ||
classes.add(configClassLoader.loadClass(className)); | ||
} | ||
List<Class> sortedClasses = sortByInheritance(classes); |
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.
would this also do the same?
Collections.sort(classes, (c1, c2) -> c1.equals(c2) ? 0 : c1.isAssignableFrom(c2) ? -1 : 1);
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.
It is not a correct comparator implementation, because it does not give a total order. See this question and answer
https://stackoverflow.com/questions/50921813/how-to-sort-classes-according-to-their-inheritance-level#comment88888102_50922334
The fix doesn't cover classes loaded from jars. The issue is relevant for them as well. |
The issue is related to inheritance. If a a ChildClass is configured first, it was trying to be defined first. It was searching for its parent, and failing. The issue is fixed by loading the parent class definition when needed, from bundledClassDefinitions on the server. (these are the whole classes send together from the client) fixes hazelcast#16575 (cherry picked from commit 15fcc57)
@galibey I have checked the jars. Indeed, they are also causing the same problem. I changed my solution after realizing that. Can you review my solution in the last commit ? |
@sancar Good solution 👍 |
The issue is related to inheritance. If a a ChildClass is configured
first, it was trying to be defined first. It was searching for its
parent, and failing.
The issue is fixed by loading the parent class definition when needed,
from bundledClassDefinitions on the server.
(these are the whole classes send together from the client)
fixes #16575
(cherry picked from commit c9b0bcc)