Zero analysis compatible with a gap between 7 and 8

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 { /** * This will fail to compile under java 7 (null analysis works in STS * 3.6.2). But under java 8 it does not show error in Eclipse Markers - * static analysis does not work ?! * * @return null which is not allowed */ @NotNull public String fail() { return null; } /** * Simple main. * * @param args * ignored args */ 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: - (()

+5
source share
1 answer

For Eclipse Luna, development efforts focused on “typical” combinations:

  • Java 7 and announcement annotations
  • Java 8 and type annotations

In this version, the combination of Java 8 and annotation declarations (as asked in this question) were not fully implemented. This has been fixed using https://bugs.eclipse.org/bugs/show_bug.cgi?id=435805

The fix is ​​available in the milestone lines towards Eclipse Mars with M4.

OTOH, I can only encourage projects using Java 8 to update type annotations for greater expressiveness, which allows me to check the null type much more accurately.

+1
source

Source: https://habr.com/ru/post/1207306/


All Articles