-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Plugin fails to delombok anonymous instance of inner class #1521
Comments
Edit: I am pretty sure that this code does work in the compiler annotation processor, but fails to be delomboked into compliable source. The code I am getting is similar to: public class C {
@Value public class D {
A a;
public B test(String s) {
return new B(a<*nullchk*>, s) {} // This is the part that won't compile
}
}
} Which its somewhat similar to the underlying bytecode but certainly not correct code! I am also quite surprised that the plugin seems to alter my generated source code files. |
Hmm, I cannot reproduce the problem. I used the following input file: class A {
@lombok.AllArgsConstructor
class B {
String s;
}
}
class C {
@lombok.Value
class D {
A a;
A.B test(String s) {
return a.new B(s);
}
}
} That gave me the following output (that compiles without any problems) // Generated by delombok at Wed Nov 29 21:26:16 CET 2017
class A {
class B {
String s;
@java.beans.ConstructorProperties({"s"})
@java.lang.SuppressWarnings("all")
public B(final String s) {
this.s = s;
}
}
}
class C {
final class D {
private final A a;
A.B test(String s) {
return a.new B(s);
}
@java.beans.ConstructorProperties({"a"})
@java.lang.SuppressWarnings("all")
public D(final A a) {
this.a = a;
}
@java.lang.SuppressWarnings("all")
public A getA() {
return this.a;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof C.D)) return false;
final C.D other = (C.D) o;
final java.lang.Object this$a = this.getA();
final java.lang.Object other$a = other.getA();
if (this$a == null ? other$a != null : !this$a.equals(other$a)) return false;
return true;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public int hashCode() {
final int PRIME = 59;
int result = 1;
final java.lang.Object $a = this.getA();
result = result * PRIME + ($a == null ? 43 : $a.hashCode());
return result;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "C.D(a=" + this.getA() + ")";
}
}
} |
Did you use an older version of lombok? |
I am using the latest release of Lombok (1.16.4 from the top of my head). Since it seems non reproducible, I’ll isolate the problem from my codebass and share the code here. |
Maybe worth noticing that A and C are in different files and not package protected. |
I also notice that you instantiate a normal instance (return a.new B(s);) and not an anonymous instance (return a.new B(s) {}). Ill post some reproduction code in a couple of hours. |
Thanks, the anonymous inner class is the culprit. |
Thanks for fixing this! 👍 |
I reported this in the Lombok Maven plugin initially (awhitford/lombok.maven#21) , but I think the problem lies in Lombok itself. What I am observing is that some construct passes the Lombok compiler enhancement, but does not delombok to compilable code.
The text was updated successfully, but these errors were encountered: