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

onX bug with JDK8 #778

Closed
lombokissues opened this issue Jul 14, 2015 · 12 comments
Closed

onX bug with JDK8 #778

lombokissues opened this issue Jul 14, 2015 · 12 comments

Comments

@lombokissues
Copy link

Migrated from Google Code (issue 743)

@lombokissues
Copy link
Author

👤 carlos@contaazul.com   🕗 Oct 15, 2014 at 19:18 UTC

What steps will reproduce the problem?

  1. When compiling code like this:

@ Getter(onMethod = @ __(@ XmlElement(name = "xmlName")))

the build breaks with the following error:

[ERROR] diagnostic: /home/carlos/Code/project/src/main/java/packages/MyClass.java:15: error: duplicate element '<any?>' in annotation @<any?>.
@ Getter(onMethod = @ __(@ XmlElement(name = "xmlName")))
^
[ERROR] error on execute: error during compilation

What is the expected output? What do you see instead?

Build success.

What version of the product are you using? On what operating system?

1.12.6

Please provide any additional information below.

@lombokissues
Copy link
Author

👤 carlos@contaazul.com   🕗 Oct 15, 2014 at 19:24 UTC

I can confirm that it also happens in version 1.14.8.

@lombokissues
Copy link
Author

👤 steven.dick.1972   🕗 Jun 10, 2015 at 07:26 UTC

We're trying to upgrade a project to building with Java 8 and get this problem too.

Works fine in Eclipse Luna, but fails with our Gradle 2.1 build.

I've tried with Lombok 1.16.2 and 1.16.4

Compiling with Oracle JDK 1.8.0_45 with source and target compatibility set to 1.7 in our Gradle build works, but setting source and target compatibility set to 1.8 and we get:

symbol: class __
location: class IVValMTDTransaction
C:\Users\sdick\git\hedgesphere-mt\HSMtApi\src\main\java\ch\hedgesphere\transaction\domain\InvestingPosUIVTrx.java:162: error: cannot find symbol
@ Getter(onMethod=@ __({@ XmlElement(name = "uInvestable")}))

As well as the same error as that originally reported:

C:\Users\sdick\git\hedgesphere-mt\HSMtApi\src\main\java\ch\hedgesphere\transaction\domain\InvestingPosUIVTrx.java:162: error: duplicate element '<any?>' in annotation @<any?>.
@ Getter(onMethod=@ __({@ XmlElement(name = "uInvestable")}))

I notice the problem is around the same JAXB annoation, @ XmlElement.

Googling suggests the @<any?> error is related to applying the same annotation multiple times to the same element. That doesn't look like the case here.

@lombokissues
Copy link
Author

End of migration

@pdinc-oss
Copy link

hmmm, 1.16.4 / 1.8.0_45 works in eclipse luna, but not in maven 3.3.3

@pdinc-oss
Copy link

confirmed with 1.8.0_60

@LeRiton
Copy link

LeRiton commented Mar 1, 2016

Any chance to get this fixed despite onX experimental status ?

JLengenfeld pushed a commit to JLengenfeld/deckcompare that referenced this issue Mar 22, 2016
There seems to be a problem with the onX feature from lombok in JDK8. See projectlombok/lombok#778.
@antechrestos
Copy link

Same here with lombok 1.16.8 and 1.8.0_20

@maseev
Copy link

maseev commented Jan 28, 2017

I've just run into the same problem. The following class declaration:

@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired(required = false)))
public class MagicSpringBean {
  // some fields
}

fails the build with:

duplicate element '<any?>' in annotation @<any?>.

This one doesn't:

@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MagicSpringBean {
  // some fields
}

Lombok version: 1.16.2
JDK version: 1.8.0_112

@oleksandrzaiats
Copy link

oleksandrzaiats commented Feb 15, 2017

maven 3.3.9, maven-compiler-plugin 3.6.1, Lombok 1.16.14, JDK 1.8.0_91 same issue
http://stackoverflow.com/questions/42257379/how-to-configure-lombok-with-maven-compiler-plugin
It seems that maven-compiler-plugin can not handle @ Getter(onMethod = @ __(@ XmlElement(name = "xmlName"))) annotation with field name declaration. In this case some annotations like @Annotation(field = "value") will not work, but @Annotation("value") will work fine (if Annotation has only value field and we don't need to specify the name of the field).

@rzwitserloot
Copy link
Collaborator

Did some research on this. The following holds:

Lombok needs to be invoked by javac, or all bets are off. If we're never called we can't fix anything. So, where I say 'does not work', I mean: We don't ever get invoked, so, there's simply nothing we can do about it.

Assume the following annotation:

@interface TestAnn {
    String value() default "";
}

Given that onMethod exists, whatever does not, @__ also doesn't, the following code works on JDK6 but not on JDK7 and also not on JDK8:

@Getter(onMethod = @TestAnn(value = "hello")) // snippet 1

That's nice and clean but doesn't work on 7/8. It's how onX used to work a long time ago.

The following works fine on 7, but fails on 8 with error ('duplicate <any?>'). This means we cannot fix this issue; it's a bug in javac (but note that snippet 2b, 2c, and 2d do work; it fails only if you have a named param:

@Getter(onMethod = @__(@TestAnn(value = "hello")) //snippet 2
@Getter(onMethod = @__(@TestAnn("hello")) //snippet 2b
@Getter(onMethod = @__(@TestAnn()) //snippet 2c
@Getter(onMethod = @__(@TestAnn) //snippet 2d

The following works fine on 8 but fails in 7:

@Getter(whatever = @TestAnn(value = "hello")) //snippet 3

Currently, snippet2 is what we suggest you do, and snippet1 technically still gets processed by lombok in case you somehow are still stuck on javac6.

We propose to also make snippet3 be processed by lombok. We'll make up names. Note that this solution is sucky but it's the best we can do. To wit:

  • There's nothing we can do to give you a nice error message when it goes wrong. We don't get invoked.
  • The method name will not be 'discoverable'; your IDE won't autocomplete it. Javadoc won't really mention it (it will be mentioned in the general docs of @Getter and co, but the annotation param CANNOT EXIST, that makes it 'work'.
  • If you need to add an annotation that has a named parameter, there's no way to write it such that it'll compile under both javac7 and javac8. Again, there is absolutely nothing we can do about it.

@oleksandrzaiats
Copy link

@rzwitserloot I have played around it a little and I have created a new issue about it - #1317. Looks like it works with maven 3 and Java 8 with named annotation parameters. Problem appeared when I was trying to use maven-compiler-plugin with Java 8. You can look at description of newly created issue. Thank you!

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

7 participants