projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.83k stars 2.37k forks source link

@__ fail on annotaions with parameters and java 1.8 #1116

Open wayerr opened 8 years ago

wayerr commented 8 years ago

At below code compiled with maven i give error. Error appear only if enclosed annotation using any parameter and compiler source and target options is set to 1.8 (on 1.7 and same other environment error will not existed) Code (in test i use copy of org.springframework.beans.factory.annotation.Autowired annotation ):

public class App {

// below string work correct
  //@Setter(onMethod = @__(@Autowired))
// below string broke compilation
  @Setter(onMethod = @__(@Autowired(required = false)))
  private String data;
}

Error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project lab: Compilation failure: Compilation failure:
[ERROR] .../lab/src/main/java/wayerr/bug/App.java:[9,23] cannot find symbol
[ERROR] symbol:   class __
[ERROR] location: class wayerr.bug.App
[ERROR] .../lab/src/main/java/wayerr/bug/App.java:[9,37] duplicate element '<any?>' in annotation @<any?>.

Info:

lombok version: 1.16.6
Apache Maven 3.2.1 
Java version: 1.8.0_77, vendor: Oracle Corporation
Default locale: ru_RU, platform encoding: UTF-8
OS name: "linux", version: "4.5.0-1-amd64", arch: "amd64", family: "unix"

Pom file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>wayerr.bug</groupId>
  <artifactId>lab</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>lab</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.16.6</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target> 
                </configuration>
            </plugin>
    </plugins>
  </build>
</project>
wayerr commented 8 years ago

Attach sample project lab.zip

arthware commented 6 years ago

Just ran into the same problem. How do people fix this? Issue is pretty old.

Maaartinus commented 6 years ago

@arthware @wayerr

See https://projectlombok.org/features/experimental/onX at the bottom:

In javac8, the above feature should work but due to a bug in javac8 it does not. However, starting in javac8, if the parameter name does not exist in the annotation type, compilation proceeds to a phase where lombok can fix it.

Two things are pretty funny:

The new way is IIRC something like @Setter(onMethod_ = @Autowired) Note the trailing underscore.

arthware commented 6 years ago

Thank you :) Ok, I simply write my annotated constructors the old-fashioned way. Annotating annotations that generate bytecode feels somehow weird anyway ;)