| Summary: | [1.8][null] Java 1.8 null annotations cause 'Contradictory null annotations' error | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Tom van den Berge <tom.vandenberge> |
| Component: | Core | Assignee: | Stephan Herrmann <stephan.herrmann> |
| Status: | VERIFIED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | jarthana, shankhba, srikanth_sankaran, stephan.herrmann |
| Version: | 4.3 | ||
| Target Milestone: | 4.4 M7 | ||
| Hardware: | PC | ||
| OS: | Mac OS X | ||
| Whiteboard: | |||
Seems we are trying to infer null annotations too aggressively. Can you think of a workaround? (In reply to Tom van den Berge from comment #2) > Can you think of a workaround? Didn't find one immediately :( That's why I set the target to M7 ... Test & fix released for 4.4 M7 via http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=dd4e66116fa81ff4f74deaa928460684d87fc74d |
I've installed the Kepler java 8 feature patch, and I'm using the latest null annotations jar (version 2.0.0, that came with the java 8 patch). The following piece of code used to compile when my project was using Java 7, and the previous null annotations jar (1.1.0): public static @NonNull <T> T assertNotNull(@Nullable T object) { return assertNotNull(null, object); } public static @NonNull <T> T assertNotNull(@Nullable String message, @Nullable T object) { if (object == null) { throw new NullPointerException(message); } return object; } After upgrading the project to Java 8, and upgrading the null annotations jar to 2.0.0, the statement return assertNotNull(null, object); gives the following compiler error: "Contradictory null annotations: method was inferred as '@NonNull @Nullable T assertNotNull(@Nullable String, @Nullable T)', but only one of '@NonNull' and '@Nullable' can be effective at any location " If I replace the 2.0.0 jar with the 1.1.0 jar, it works again. This is not a solution however, since the old jar does not support type annotations.