-
Notifications
You must be signed in to change notification settings - Fork 687
Exclude local & anonymous classes from type inspection #2746
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
Conversation
Also update the type filter that would not mach types directly present in the given package. Modify type contribution method to allow store specific override.
Java8 bytecode may contain synthetic constructors that refer to anonymous classes which should not be inspected. Eg. the following construct results in bytecode as listed further down below. public enum Outer { INSTANCE { @OverRide public Inner getInnerType() { return Inner.STANDALONE; } }, public abstract Inner getInnerType(); } synthetic Outer(java.lang.String arg0, int arg1, Inner$1 arg2)
@@ -125,6 +127,10 @@ Set<Type> visitConstructorsOfType(ResolvableType type) { | |||
} | |||
Set<Type> discoveredTypes = new LinkedHashSet<>(); | |||
for (Constructor<?> constructor : type.toClass().getDeclaredConstructors()) { | |||
|
|||
if (constructor.isSynthetic()) { |
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.
Kotlin likes to generate synthetic constructors for data classes. We should make sure to not break stuff. Likely, the field-based inspection is going to catch such cases.
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 108 in 6a23723
if (!candidate.isSynthetic()) { |
Java8 bytecode may contain synthetic constructors that refer to anonymous classes which should not be inspected. Eg. the following construct results in bytecode as listed further down below. public enum Outer { INSTANCE { @OverRide public Inner getInnerType() { return Inner.STANDALONE; } }, public abstract Inner getInnerType(); } synthetic Outer(java.lang.String arg0, int arg1, Inner$1 arg2) See: #2744 Original pull request: #2746
Java8 bytecode may contain synthetic constructors that refer to anonymous classes which should not be inspected. Eg. the following construct results in bytecode as listed further down below. public enum Outer { INSTANCE { @OverRide public Inner getInnerType() { return Inner.STANDALONE; } }, public abstract Inner getInnerType(); } synthetic Outer(java.lang.String arg0, int arg1, Inner$1 arg2) See: #2744 Original pull request: #2746
That's merged, polished, and backported now. |
Local and anonymous classes should not be picked up during reachable type collection, as those are not targets of the spring data reflection infrastructure.
We also updated the type filter so that it now matches types present in the very same package and modified method visibility for module specific contribution checks.
Last we excluded synthetic constructors from being inspected as those (in some cases) can contain references to anonymous classes as shown in the snippet below.