Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants