Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
In latest version (0.10.1) @Data is incompatible with Spring's @NotNull #360
What steps will reproduce the problem?
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
Please provide any additional information below.
I imagine that Lombok expects all @ NotNull annotations to be its own and that a more precise check on the whole @ NotNull annotation class+package would solve the problem but I may be wrong as I didn't look at the sources.
I'm using the javax validation API (with hibernate validator 4.2.0 final) and Eclipse is fine, but javac running from ANT complains about the @ NotNull when using Lombok 0.10.1 - downgrading to Lombok 0.10.0 resolves the problem.
We've looked at version 0.8 of spring modules, here:
And as you can see, there's no 'annotation' package. We have no idea where its from, in fact; googling around doesn't give us much.
As far as we know, for years and years now, the right annotation for this stuff is javax.validation.constraints.NotNull and not spring's own variant.
Spring's own variant seems to only be legal on fields, whereas a recent version of javax.validation.constraints.NotNull is valid on fields, methods, and parameters - everything we need it to be legal on.
We suggest you switch versions. Otherwise, can you point us at the sources of this NotNull annotation so we can learn a little more about it? We could try to hardcode an exception for that annotation, but without any trace of that annotation other than this bugreport we're a bit hesitant to do so.
When we look at the javadoc for javax.validation.constraints.NotNull here:
It looks like there should be no problem; it's legal everywhere we need it to be legal. When I check the javaEE 5 docs, there is no javax.validation at all, so it seems to be new in javaEE 6.
What error message are you getting? What version are you on? The same caveat applies: We can hardcode an exception but before we do so we need to know what's going on.
Attached a small example, error can be seen with
Test.java:[8,1] annotation type not applicable to this kind of declaration
Appears to me that Lombok should not be getting involved but some error in processing is causing @ NotNull to be processed.
referenced this issue
Jul 14, 2015
As for the Spring @ NotNull annotation, it is only allowed on fields and methods(so ElementType.METHOD, ElementType.FIELD). This means it shouldn't qualify for an annotation @ Data should process.
The question is how should we handle these cases?
Perhaps the change should be backed out until a solution is available. We are having numerous issues with eclipse and would like to narrow down any issues and get the change to remove the memory leak with @ Delegate. Though I don't really know if this is causing us any real impact.
We've stumbled on this issue before, and at that time I 'fixed' it by just not treating @ NotNull (Any kind of @ NotNull, from any package) special. I forgot to update the documentation and I also didn't document the code. Philipp recently noticed the discrepancy in the docs, and added it back in.
Seems like this is still the best option as we've never actually heard any complaints about not having @ NotNull trigger lombok's usually non-null processing.
We'll push a new version out the door with the fix soon. That would be version 0.10.2
Fixed in commit 782daa4 (and this time I did update the docs and add a comment explaining why NotNull isn't in the list).