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 errors with @NotNull #365

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

Compilation errors with @NotNull #365

lombokissues opened this issue Jul 14, 2015 · 4 comments

Comments

@lombokissues
Copy link

Migrated from Google Code (issue 292)

@lombokissues
Copy link
Author

👤 osa8aso   🕗 Oct 25, 2011 at 18:37 UTC

When a property is annotated with @ NotNull, lombok's @ Data, @ Getter and @ Setter use this annotation class to annotate methods and method and constructor parameters. However, if @ NotNull targets do not include METHOD or PARAMETER element types, it fails to compile.

Example:

import static java.lang.annotation.ElementType.FIELD;
import java.lang.annotation.Target;
import lombok.Setter;

@ Target({ FIELD })
@ interface NotNull {
}

@ Setter
public class Foo {
@ NotNull
private int field;

}

Trying to compile it with lombok 0.10.1 produces the following error:

$ javac -cp ../lib/lombok-0.10.1.jar Foo.java
Foo.java:11: annotation type not applicable to this kind of declaration
@ NotNull
^
1 error

From delombok output it is easy to see that error was caused by adding @ NotNull annotation to the setter parameter:

// Generated by delombok at Tue Oct 25 13:32:26 CDT 2011
import static java.lang.annotation.ElementType.FIELD;
import java.lang.annotation.Target;

@ Target({FIELD})
@ interface NotNull {
}
public class Foo {
@ NotNull
private int field;

@ java.lang.SuppressWarnings("all")
public void setField(@ NotNull final int field) { // <--- ERROR
    this.field = field;
}

}

This is a real problem if @ NotNull annotation is provided by another library and there is no way to change targets it supports. For example, Ebean @ NotNull works only for METHOD and FIELD: http://www.avaje.org/static/javadoc/pub/com/avaje/ebean/validation/NotNull.html

I think lombok should check supported @ NotNull targets before applying it to generated methods and method parameters to prevent such errors.

Additional information:
javac 1.6.0_23
lombok 0.10.1
Linux 3.0.0-12-generic ﹟20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

@lombokissues
Copy link
Author

👤 pe.fips   🕗 Oct 26, 2011 at 06:48 UTC

@lombokissues
Copy link
Author

👤 pe.fips   🕗 Oct 26, 2011 at 06:48 UTC

Duplicate of issue #360

@lombokissues
Copy link
Author

End of migration

lianhaijun pushed a commit to lianhaijun/lombok that referenced this issue May 8, 2020
….. and 'varl' -> producing lombok.experimental.var foo = ...

resolves projectlombok#365
lianhaijun pushed a commit to lianhaijun/lombok that referenced this issue May 8, 2020
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

1 participant