I came across a strange nullcheck analysis behavior under Spring toolkit 3.6.2 (Eclipse clone) on Windows 7 64 bit with Oracle java 8u25. The same maven project with java 7 compatibility successfully detects an NPE error in eclipse, but when I change the compilation version in maven to java 1.8, eclipse cannot find this error.
My nullcheck analysis configuration in Eclipse (Java-> Compiler-> Errors / Warnings-> Null analysis): Include assertions in null analysis true Enable annotation analysis true NotNull user annotation is correctly set to javax.validation.constraints.NotNull and etc. (everything seems to be OK, since it works under java 7)
My maven pom is here http://pastebin.com/pF1yJSG2 , as mentioned above, when java.version in pom 1.7 works with null validation, when 1.8 null validation fails.
Sample source code:
package test.nullcheckbug.core; import javax.validation.constraints.NotNull; public class Program { @NotNull public String fail() { return null; } public static void main(String[] args) { } }
Does anyone know where the problem is and how to enable nullcheck work as part of jdk 1.8 compatibility?
Editorial: It seems that Maven is not involved. The same problem is simulated in a non maven project with the same source code and compiler compatibility level set to 1.7. This is mistake?
EDITED-2: After a more detailed study, I found that the following annotation difference makes a difference: java.lang.annotation.ElementType.TYPE_USE, when there is no annotation, the nullcheck value is not found in Java 8, but found in Java 7. But why? ! Why is there such a different behavior ?!
EDITED-3: After research done by MartinLippert and tested by me, it seems that the nullcheck API has changed dramatically between java 7 and java 8. Requires Null (as seen from version 2.0 of the eclipse libraries) java.lang.annotation.ElementType.TYPE_USE, @Target types (value = {METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) are ignored during analysis. SO THE FOLLOWING IS THE FOLLOWING: WHY A ZERO ANALYSIS UNDER JAVA 8 IS REQUIRED AND WORKS ONLY UNDER A NEW ELEMENT TYPE? (I understand that it’s good to use new language features with java 8, but why break compatibility? For example, javax.validation @NotNull is now not applicable as nullchecking annotation: - (()