Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 432223

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: CoreAssignee: 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:

Description Tom van den Berge CLA 2014-04-08 03:39:46 EDT
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.
Comment 1 Stephan Herrmann CLA 2014-04-13 17:23:57 EDT
Seems we are trying to infer null annotations too aggressively.
Comment 2 Tom van den Berge CLA 2014-04-14 16:53:23 EDT
Can you think of a workaround?
Comment 3 Stephan Herrmann CLA 2014-04-14 19:11:06 EDT
(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 ...
Comment 4 Stephan Herrmann CLA 2014-04-15 08:22:08 EDT
Test & fix released for 4.4 M7 via http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=dd4e66116fa81ff4f74deaa928460684d87fc74d
Comment 5 shankha banerjee CLA 2014-04-28 09:12:21 EDT
The code in Comment 0 compiles without any issues.

Verified for 4.4 M7 using I20140427-2030 build.