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

Java 21 throws warning with idiomatic Freebuilder usage #466

Open
rohlandm opened this issue Sep 27, 2023 · 5 comments
Open

Java 21 throws warning with idiomatic Freebuilder usage #466

rohlandm opened this issue Sep 27, 2023 · 5 comments

Comments

@rohlandm
Copy link

rohlandm commented Sep 27, 2023

Hello,

while preparing a codebase for the migration to Java 21, we noticed that when you use Freebuilder with default values as described in the README

public Builder() {
      // Set defaults in the builder constructor.
      description("Indescribable");
}

the Java 21 compiler now throws a warning, failing the compilation if the -Werror flag is set.

This can be suppressed with @SuppressWarnings("this-escape"), but having a cleaner solution would be preferable.

@alicederyn
Copy link
Collaborator

alicederyn commented Sep 27, 2023

What happens if you add an explicit super. before the method call?

@rohlandm
Copy link
Author

It still throws the warning, as it is still a call to a overwritable method from the constructor

@alicederyn
Copy link
Collaborator

That seems like a bug, since it's not overwriteable if you call the super method.

@rohlandm
Copy link
Author

🤔 strange. In the meantime, a workaround would be to not set the defaults in the constructor directly but in a static builder() method (subsequently decreasing the constructor's visibility)

@alicederyn
Copy link
Collaborator

I'll leave this open in case anyone has any other advice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants