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

Plugin fails to delombok anonymous instance of inner class #1521

Closed
jwgmeligmeyling opened this issue Nov 20, 2017 · 8 comments
Closed

Plugin fails to delombok anonymous instance of inner class #1521

jwgmeligmeyling opened this issue Nov 20, 2017 · 8 comments
Labels
parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these.

Comments

@jwgmeligmeyling
Copy link

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.

Code example is roughly as follows:

public class A {
    @AllArgsConstructor public class B {
            String s;
    }
}
public class C {
    @Value public class D {
           A a;

           public B test(String s) {
                  return a.new B(s) {} // This is the part that won't compile
           }
    }
}

The generated code fails to compile. This case works in the Lombok compiler. I am on the newest version of the plugin .

@jwgmeligmeyling
Copy link
Author

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.

@rspilker
Copy link
Collaborator

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() + ")";
		}
	}
}

@rspilker
Copy link
Collaborator

Did you use an older version of lombok?

@rspilker rspilker added the parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these. label Nov 29, 2017
@jwgmeligmeyling
Copy link
Author

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.

@jwgmeligmeyling
Copy link
Author

Maybe worth noticing that A and C are in different files and not package protected.

@jwgmeligmeyling
Copy link
Author

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.

@rspilker
Copy link
Collaborator

rspilker commented Dec 4, 2017

Thanks, the anonymous inner class is the culprit.

@jwgmeligmeyling
Copy link
Author

Thanks for fixing this! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these.
Projects
None yet
Development

No branches or pull requests

2 participants