Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

christophstrobl
Copy link
Member

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.

public enum Outer {

    INSTANCE {
        @Override
        public Inner getInnerType() {
            return Inner.VALUE;
        }
    },

    public abstract Inner getInnerType();
}
synthetic Outer(java.lang.String arg0, int arg1, Outer$1 arg2)
         <localVar:index=0 , name=this , desc=LOuter;, sig=null, start=L0, end=L1>
         <localVar:index=1 , name=x0 , desc=Ljava/lang/String;, sig=null, start=L0, end=L1>
         <localVar:index=2 , name=x1 , desc=I, sig=null, start=L0, end=L1>
         <localVar:index=3 , name=x2 , desc=LOuter$1;, sig=null, start=L0, end=L1>

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()) {
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mp911de pushed a commit that referenced this pull request Jan 11, 2023
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.

Closes: #2744
Original pull request: #2746
mp911de pushed a commit that referenced this pull request Jan 11, 2023
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
mp911de added a commit that referenced this pull request Jan 11, 2023
Introduce common exclusion rules for constructors.

See: #2744
Original pull request: #2746
mp911de pushed a commit that referenced this pull request Jan 11, 2023
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.

Closes: #2744
Original pull request: #2746
mp911de pushed a commit that referenced this pull request Jan 11, 2023
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
mp911de added a commit that referenced this pull request Jan 11, 2023
Introduce common exclusion rules for constructors.

See: #2744
Original pull request: #2746
@mp911de mp911de added this to the 3.0.1 (2022.0.1) milestone Jan 11, 2023
@mp911de mp911de added the type: bug A general bug label Jan 11, 2023
@mp911de
Copy link
Member

mp911de commented Jan 11, 2023

That's merged, polished, and backported now.

@mp911de mp911de closed this Jan 11, 2023
@mp911de mp911de deleted the issue/2744 branch January 11, 2023 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeCollector should ignore local and anonymous classes
2 participants