Skip to content
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

Fieldgenerator should not accept private getter #348

Closed
julgus opened this issue Jun 20, 2023 · 2 comments
Closed

Fieldgenerator should not accept private getter #348

julgus opened this issue Jun 20, 2023 · 2 comments
Assignees
Labels
bug Something isn't working
Projects
Milestone

Comments

@julgus
Copy link
Member

julgus commented Jun 20, 2023

Describe the bug
Under certain conditions, the fieldgenerator accepts private getters and generates code that won't compile.

Expected behavior
If the getter is private the fieldgenerator should issue a warning at runtime and generate a reference getter that throws an exception.

The field films has a private getter:

    @Getter(value = AccessLevel.PRIVATE)
    @ManyToMany(mappedBy = "actors")
    private List<Film> films = new ArrayList<>();

Should generate (whether this is an optimal solution is up for discussion but this is the way it is designed to work at this point) :

    /**
     * This Field corresponds to the {@link Actor} field "films".
     */
    public static final ReferenceField<Actor, List<Film>> films = ReferenceField.create(
        Actor.class,
        "films",
        actor -> {throw new IllegalJavaBeanException(Actor.class, "films");},
        false
    );

Actual behavior
The generated ReferenceField references Actor::getFilms which is unavailable to the compiler of that class:

    /**
     * This Field corresponds to the {@link Actor} field "films".
     */
    public static final ReferenceField<Actor, List<Film>> films = ReferenceField.create(
        Actor.class,
        "films",
        Actor::getFilms,
        false
    );

How To Reproduce
Build the fieldgenerator-test module with IntelliJ (error does not occur when building with Maven).

Build tool
IntelliJ

JPAStreamer version
3.0.2

JPA Provider
Hibernate 6.0.2.Final

Java Version
11.0.27

@julgus julgus added the bug Something isn't working label Jun 20, 2023
@julgus julgus added this to the 3.0.3 milestone Jun 20, 2023
@julgus julgus self-assigned this Jun 20, 2023
@julgus julgus added this to Prio 1 in 3.0.4 Jun 20, 2023
@julgus
Copy link
Member Author

julgus commented Jun 20, 2023

Building with IntelliJ:
image

Building with Maven:
image

@julgus
Copy link
Member Author

julgus commented Jun 20, 2023

I think the difference arises because the accessors Lombok generates are available at build time with IntelliJ and are erroneously detected as standard getters.

@julgus julgus moved this from Prio 1 to Done in 3.0.4 Jun 20, 2023
@julgus julgus closed this as completed in b711410 Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
3.0.4
Done
Development

No branches or pull requests

1 participant