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

Compilation Error with Java 8 and maven-compiler-plugin using onX with Annotations with parameters #1317

Closed
oleksandrzaiats opened this issue Feb 27, 2017 · 5 comments

Comments

@oleksandrzaiats
Copy link

I have the simple DTO class

@Data
public class DTO {
	@Getter(onMethod = @__(@TestAnnotation(testParam = "testParam")))
	@Setter
	String data;
}

Simple test annotation

@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface TestAnnotation {
    String testParam();
}

And Main class with main method with

DTO dto = new DTO();
dto.getData();

My POM file has 1 dependency and 1 plugin - maven-compiler-plugin

        <dependencies>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<version>1.16.14</version>
			<scope>provided</scope>
		</dependency>
	</dependencies>
	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-compiler-plugin</artifactId>
					<version>3.6.1</version>
					<configuration>
						<source>1.8</source>
						<target>1.8</target>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>

When I try to run main method I get

Error:(8, 29) java: cannot find symbol
  symbol:   class __
  location: class DTO
Error:(8, 48) java: duplicate element '<any?>' in annotation @<any?>.

If I am not using maven-compiler-plugin - everything works fine, if I set <source>1.7</source><target>1.7</target> in plugin configuration - works fine.
So the problem is about Java 8 and maven-compiler-plugin.
If I use @Getter(onMethod = @__(@TestAnnotation("testParam"))) or @Getter(onMethod = @__(@TestAnnotation)) - works fine. The problem occours only with named parameters for annotations.

@oleksandrzaiats
Copy link
Author

According @rzwitserloot answer in referenced issue, looks like it is a problem of maven-compiler-plugin, isn't it?

@rspilker
Copy link
Collaborator

No, it is a problem with jdk8's javac

@rspilker
Copy link
Collaborator

I don't think we need this duplicate issue.

@oleksandrzaiats
Copy link
Author

oleksandrzaiats commented Feb 28, 2017

@rspilker @rzwitserloot But in this case why everything is working fine if I am not using maven-compiler-plugin? If I remove maven-compiler-plugin from my POM file, this simple project is built successfuly. Also if I run the project using Intellij Idea with JDK 1.8 with Javac 1.8 version everything working fine as well.
In the target folder I get .class fine and with decompiler provided by Intellij I get:

public class DTO {
    String data;

    public DTO() {
    }

    public boolean equals(Object o) {...}

    protected boolean canEqual(Object other) {...}

    public int hashCode() {...}

    public String toString() {...}

    @TestAnnotation(
        testParam = "testParam"
    )
    public String getData() {
        return this.data;
    }

    public void setData(String data) {
        this.data = data;
    }
}

So looks like it is not a problem of Javac.

@rzwitserloot
Copy link
Collaborator

We reproduced it using stock javac off of the command line, so, it IS a problem with javac8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants