-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Illegal redefinition of parameter o when using lombok together with Eclipse null check annotation analysis #788
Comments
👤 tomas.bucki 🕗 Nov 21, 2014 at 15:46 UTC What steps will reproduce the problem?1.Use @ EqualsAndHashCode on your empty class What is the expected output? What do you see instead?Expected output is to not see compilation errors. I see 4 errors "Type What version of the product are you using? On what operating system?STS 3.6.2, Java 8u25, Win 7 64bit, Lombok 14.4.8 Please provide any additional information below.Problem is in generated implementation of equals(Object o) which should be equals(@ Nullable Object o) to work together with Eclipse null annotation analysis. |
👤 tomas.bucki 🕗 Nov 21, 2014 at 17:16 UTC It seems that using @ EqualsAndHashCode(onParam = @ __(@ AllowNull)) where AllowNull is the: |
End of migration |
Same with Java 1.8.0_51 and Lombok 1.16.4. @Data
public class FileImporter {
@Nullable
private List<String> fileEndings = new ArrayList<String>();
} Error displayed on the @DaTa anntation (that adds the equals-method that is unconstrained in Object) is:
A viable workaround for this error message would be (at least that's what we used to do in Java 1.7): @Data
@EqualsAndHashCode(onParam = @__(@Nullable))
public class FileImporter {
@Nullable
private List<String> fileEndings = new ArrayList<String>();
} This should add the the @nullable annotation to the parameter of the equals-method generated by the @data-annotation. But it seems that the orX-method of Lombok doesn't work in Java 8 (tested with _25, _45 and _51) since the error message now is still(now on the @EqualsAndHashCode annotation instead of the @DaTa annotation):
Implying that the @nullable annotation hasn't been added to the equals-method. When we switch to 1.7 this second error vanishes and everything works like expected. |
Same problem with this code, using Lombok 1.16.10, Java 1.7, Eclipse 4.6.1: @Value
@org.eclipse.jdt.annotation.NonNullByDefault
public class Entity {
String name;
String code;
} Note that adding |
We should scan for We should optimally also manually parse package-info.java in the same dir as your source file and check if you have We need to code into the system the following: If the enclosing class has an annotation of type If the enclosing class did not have the annotation, check if the The appropriate annotation is Secondly, if class or package has Anyone know of any other annotations in this vein? |
There are the (now deprecated in lieu of javax.annotation) FindBug annotations:
|
Before we fix this, we should also fix NNBD effects elsewhere. Specifically:
Thus, the 2 fixes to apply to address this issue would be:
|
@Gaibne: I don't think those are relevant here; is there a NonNullByDefault annotation in findbugs's annotationset which implies |
There is, also deprecated:
|
So for that one, the rule is: NonNull needs to be part of the argslist. If so, generate e.u.c.f.a.Nullable. |
Additional complication: there are now 4 places you can stick an annotation on an equals method: On the method, on the method's return type, on the parameter, and on the type holding the parameter. eclipse's So, we need to generate the We also need to make a separate bug/enhancement to add onParamType for |
I hope it's not poor form for me to bump this ? Just ran into it again and after googling ended up here, reading my own comments :D I think two years later we can definitely assume J8+. |
I'm going to go for an intermediate solution: I'm not going to write code to do a scan for package-info, that's quite complicated, but I will scan for both common variants of |
HEADSUP: We've changed how this is going to work. We're not going to hunt for Therefore, instead, there is a lombok.config key where you configure what kind of 'flavour' of nullity annotations you want, and then lombok will generate them everywhere that it is relevant (toString, equals, canEqual, withX, and plural forms of This also covers nullity annotations relevant for issue 2221. |
(chainable setters, static constructors, builder stuff)
…nullity annotations. Which 'flavour' is defined in lombok.config; applied to toString, equals, canEqual, and plural-form of `@Singular`.
(chainable setters, static constructors, builder stuff)
Migrated from Google Code (issue 753)
The text was updated successfully, but these errors were encountered: