Null analysis in eclipse compatibility break between 7 and 8

kulatamicuda

I have encountered strange behaviour of nullcheck analysis under Spring tool suite 3.6.2 (Eclipse clon) on windows 7 64bit with Oracle java 8u25. The same maven project with java 7 source compatibility successfully finds NPE error in eclipse, but when I change compilation version in maven to java 1.8, the eclipse is unable to find this error.

My nullcheck analysis configuration in Eclipse (Java->Compiler->Errors/Warnings->Null analysis) is: Include asserts in null analysis true Enable annotation based analysis true NotNull custom annotation is properly set to javax.validation.constraints.NotNull etc. (everything seems to be OK, as it works under java 7)

My maven pom is here http://pastebin.com/pF1yJSG2 , as mentioned above when java.version in pom is 1.7 null check works, when is 1.8 null check does not work.

Sample source code is:

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 anybody know where is problem and how to enable nullcheck to work under jdk 1.8 compatibility ?

EDITED: Maven seems to be not involved. The same problem simulated on non maven project with the same source code and compatibility level of compiler set to 1.7. Is it a bug ?

EDITED-2: After more examination I have found that the following difference in annotation makes difference : java.lang.annotation.ElementType.TYPE_USE , when annotation does not have this, the nullcheck is not detected under Java 8, but is detected under Java 7. But why ?! Why there is so different behaviour ?!

EDITED-3: After research from MartinLippert and tested by me it seems that nullcheck API has drastically changed between java 7 and java 8. Null detection requires (as seen from version 2.0 of eclipse libraries) java.lang.annotation.ElementType.TYPE_USE, the types @Target(value={METHOD,FIELD,ANNOTATION_TYPE,CONSTRUCTOR,PARAMETER}) are ignored in analysis. SO THE QUESTION IS NOW AS FOLLOWS: WHY NULL ANALYSIS UNDER JAVA 8 REQUIRES AND WORKS ONLY UNDER NEW ELEMENT TYPE ? (I understand that with java 8 it is good to fully utilise new language features, but why was needed to break compatibility ? For example javax.validation @NotNull is now unusable as nullchecking annotation :-((( )

Stephan Herrmann

For Eclipse Luna, the development effort was focused on the "typical" combinations:

  • Java 7 and declaration annotations
  • Java 8 and type annotations

In this version the combination Java 8 and declaration annotations (what is requested in this question) was not fully implemented. This has been fixed via https://bugs.eclipse.org/bugs/show_bug.cgi?id=435805

The fix is available in milestone builds towards Eclipse Mars since M4.

OTOH, I can only encourage projects using Java 8 to upgrade to type annotations for much greater expressiveness - enabling much more precise null type checking.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Do Java 8 default methods break source compatibility?

From Dev

Compatibility between Windows 7 and Windows 10.

From Dev

UIAlertView/UIAlertController iOS 7 and iOS 8 compatibility

From Dev

eclipse null analysis field initialization

From Dev

Compatibility between iOS7 and iOS6 after publication

From Dev

Core Location iOS8 compatibility with iOS7

From Dev

Eclipse null analysis issues null type safety warning for class literal

From Dev

What are the differences between null analysis annotations packages?

From Dev

Best way to read lines from file Java 8 and break in between

From Dev

Eclipse null analysis raises false positive NullPointerException warning

From Dev

JavaFX 8 swing compatibility

From Dev

Java 8 generics compatibility

From Dev

Shared library: break the ABI compatibility without breaking API compatibility

From Dev

Shared library: break the ABI compatibility without breaking API compatibility

From Dev

How to add and iOS7 support to iOS8 compatibility version in xamarin

From Dev

How to add and iOS7 support to iOS8 compatibility version in xamarin

From Dev

Cross browser compatibility issue of Internet Explorer 6, 7 and 8 for png/jpg image used as background of an html element

From Dev

Source code compatibility setting in Eclipse

From Dev

Source code compatibility setting in Eclipse

From Dev

Different NSError localizedDescription between iOS 7 and 8

From Dev

Switching between Java 7 and 8 in OS X

From Dev

Difference between Drupal 7 And Drupal 8 for beginners

From Dev

New testflight compatibility with ios 7

From Dev

FinalBuilder 7 compatibility with windows 10

From Dev

List compatibility programs in windows 7

From Dev

Compatibility with IE7 Angularjs

From Dev

Null-conditional Operators Compatibility

From Dev

Compatibility of free/malloc between compilers

From Dev

ABI Compatibility between release and debug

Related Related

  1. 1

    Do Java 8 default methods break source compatibility?

  2. 2

    Compatibility between Windows 7 and Windows 10.

  3. 3

    UIAlertView/UIAlertController iOS 7 and iOS 8 compatibility

  4. 4

    eclipse null analysis field initialization

  5. 5

    Compatibility between iOS7 and iOS6 after publication

  6. 6

    Core Location iOS8 compatibility with iOS7

  7. 7

    Eclipse null analysis issues null type safety warning for class literal

  8. 8

    What are the differences between null analysis annotations packages?

  9. 9

    Best way to read lines from file Java 8 and break in between

  10. 10

    Eclipse null analysis raises false positive NullPointerException warning

  11. 11

    JavaFX 8 swing compatibility

  12. 12

    Java 8 generics compatibility

  13. 13

    Shared library: break the ABI compatibility without breaking API compatibility

  14. 14

    Shared library: break the ABI compatibility without breaking API compatibility

  15. 15

    How to add and iOS7 support to iOS8 compatibility version in xamarin

  16. 16

    How to add and iOS7 support to iOS8 compatibility version in xamarin

  17. 17

    Cross browser compatibility issue of Internet Explorer 6, 7 and 8 for png/jpg image used as background of an html element

  18. 18

    Source code compatibility setting in Eclipse

  19. 19

    Source code compatibility setting in Eclipse

  20. 20

    Different NSError localizedDescription between iOS 7 and 8

  21. 21

    Switching between Java 7 and 8 in OS X

  22. 22

    Difference between Drupal 7 And Drupal 8 for beginners

  23. 23

    New testflight compatibility with ios 7

  24. 24

    FinalBuilder 7 compatibility with windows 10

  25. 25

    List compatibility programs in windows 7

  26. 26

    Compatibility with IE7 Angularjs

  27. 27

    Null-conditional Operators Compatibility

  28. 28

    Compatibility of free/malloc between compilers

  29. 29

    ABI Compatibility between release and debug

HotTag

Archive