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

[BUG] @SuperBuilder/@Builder generates names(Collection<? extends String > names)-method, but String is final #3666

Open
henrykuijpers opened this issue May 15, 2024 · 3 comments

Comments

@henrykuijpers
Copy link

Describe the bug
When using

@Singular
private final Collection<String> names;

A builder method

B names(Collection<? extends String> names)

is generated.

However, String is final, therefore the ? extends is not needed.

The Java compiler generates a warning:

name clash: names(java.util.Collection<? extends java.lang.String>) in nl.DefaultItem.Builder and names(java.util.Collection<java.lang.String>) in nl.ItemBuilder have the same erasure, yet neither overrides the other

Expected fix
Add a case for final classes, to not generate the wildcard.

Expected behavior
Generate B names(Collection<String> names)

Version info (please complete the following information):

  • Latest Lombok

Additional context
Add any other context about the problem here.

@rspilker
Copy link
Collaborator

To determine if a class is final, we would need to use resolution. Although we have resolution in some places, as far as I know it's not reliable.

@henrykuijpers
Copy link
Author

@rspilker Okay, in what cases is resolution not reliable? And do you have any examples of resolution?
I tried to come up with a PR, but I was not able to properly set up the codebase, so I had no code completion etc.

I would like to continue on this soon and I could use more information about resolution. Maybe it is possible. Maybe not -- but I'd like to figure that out. :)

@janrieke
Copy link
Contributor

Have a look at the wiki:

If you have "package c; import a.b.*;" in your file, and class "c.Baz" exists, then a class reference to class "Baz" in this file is a reference to "c.Baz", but if you ask lombok's own resolver if this "Baz" reference is a reference to "a.b.Baz", lombok answers 'yes', eventhough it should have answered 'no'.

In this case it means that you could detect a class as final, but in fact the resolver was wrong and it is another class that is not final. In this case, you would generate wrong code.

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

3 participants