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] problem with setter when extending a class with the same simple name #2268
Comments
This is so interesting! I spent some time digging into this and wanted to share what I found. The tldr is that everything confirms what @mateidavid suggested with one addition. All outer classes need to be specified, not just the most immediate. Original IssueI debugged the interface A {
class Foo {}
}
interface B {
@Setter
@Accessors(fluent = true)
class Foo implements A, B {
private int n;
}
} which generates interface A {
class Foo {}
}
interface B {
class Foo implements A, B {
private int n;
public Foo n(int n) {
this.n = n;
return this;
}
}
} The compiler error wasn't obvious to me at first because I expected Other SymptomsI also found that by removing
Deeper Class NestingOne more, just because I believe it sheds a little more light on the fix. interface A {
class Bar {
class Foo {}
}
}
interface B {
class Bar {
class Foo implements A, B {
Bar.Foo b() {
return this;
}
}
}
} In the sample above, we apply the fix of specifying the outer type in the return type expression with the intent to disambiguate but it fails to do so. It seems the return type needs to be qualified by all outer classes in the nesting not just the nearest outer class. |
I suspected interface A {
class Foo {
public Foo(int i) {
System.out.println("This shouldn't be happening");
}
}
}
interface B {
@Builder
class Foo implements A{
private int variable;
}
}
public class LombokTest{
public static void main(String[] args) {
A.Foo obj = B.Foo.builder().variable(2).build();
}
} A few things I noticed attempting this
|
Describe the bug
Original report on the Google group:
https://groups.google.com/d/msg/project-lombok/YZ8CRFX8HFA/ZSZIa4c2BgAJ
When the Lombok annotation processor generates a chained setter for an inner class (e.g.
A.Inner
), it attempts to use as return type only the simple name of the inner class (Inner
), as opposed to the partially qualified name that includes the enclosing class (A.Inner
). In some contexts the simple name of the inner class might not be unique, leading to compilation error.To Reproduce
On build, this produces an error that in
B.Mutable
, the reference toMutable
is ambiguous. Most likely, that's because Lombok produces:... and in that context
Mutable
is ambiguous betweenA.Mutable
andB.Mutable
.Expected behavior
Have the setter return type use the partially qualified name that includes the enclosing class, elimintaing the ambiguity:
Version info (please complete the following information):
Additional context
B.Mutable
.The text was updated successfully, but these errors were encountered: