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

Bug 485302

Summary: [1.8][null]Missing warnings when using Wildcards with null annotations
Product: [Eclipse Project] JDT Reporter: Till Brychcy <register.eclipse>
Component: CoreAssignee: Till Brychcy <register.eclipse>
Status: VERIFIED FIXED QA Contact: Stephan Herrmann <stephan.herrmann>
Severity: normal    
Priority: P3 CC: dusisarath, manoj.palat, stephan.herrmann
Version: 4.5.1   
Target Milestone: 4.6 M6   
Hardware: PC   
OS: Mac OS X   
See Also: https://git.eclipse.org/r/63686
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=e2fc6e7db19ada9b01733b33b99936b7344de6b1
Whiteboard:

Description Till Brychcy CLA 2016-01-06 18:20:23 EST

    
Comment 1 Till Brychcy CLA 2016-01-06 18:25:27 EST
DESCRIPTION:
During compilation of the following code, only "warning 3" is reported:

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

public class WildCardNullable {
	static class A<T> {
		@Nullable
		T returnNull() {
			return null;
		}

		void acceptNonNullT(@NonNull T t) {
		}

		void acceptNonNullObject(@NonNull Object x) {
		}
	}

	static @NonNull Number g(A<? extends @NonNull Number> a) {
		return a.returnNull(); // error 1 expected
	}

	public static final <T> void map(final A<@NonNull ? super T> a, T t) {
		a.acceptNonNullT(t); // warning 2 expected
		a.acceptNonNullObject(t); // warning 3 expected
	}
}

ANALYSIS:
In NullAnnotationMatching.areSameTypes, for capture bindings, the null bits are not compared if the bounds were found.

PATCH (via gerrit): 
compare the null bits in these cases. adjust testBug448709 so it expects are warning, too.
Comment 2 Eclipse Genie CLA 2016-01-06 18:28:58 EST
New Gerrit change created: https://git.eclipse.org/r/63686
Comment 3 Till Brychcy CLA 2016-01-27 15:09:10 EST
This didn't have Target Milestone at all, feel free to correct it if you plan to look at this later.
Comment 4 Stephan Herrmann CLA 2016-02-04 12:06:48 EST
Looks good to me.

Looking at the change in testBug448709() I only added one more (stripped-down) variant of that test, witnessing that the new warning is *not* raised, when flow analysis knows that the value is nonnull.

Rebased, test added and re-uploaded to gerrit.
Comment 6 Stephan Herrmann CLA 2016-02-04 15:04:34 EST
(In reply to Eclipse Genie from comment #5)
> Gerrit change https://git.eclipse.org/r/63686 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=e2fc6e7db19ada9b01733b33b99936b7344de6b1
> 

Released for 4.6 M6. Thanks!
Comment 7 Dusi Sarath Chandra CLA 2016-03-16 06:50:41 EDT
Didn't find UI option for pessimistic null analysis for free type variables. After manually adding the same I could reproduce the mentioned scenario in comment 1.

Verified for 4.6M6 using Version: Neon (4.6)
Build id: I20160314-2000
Comment 8 Stephan Herrmann CLA 2016-03-18 12:53:18 EDT
(In reply to Dusi Sarath Chandra from comment #7)
> Didn't find UI option for pessimistic null analysis for free type variables.

I assume this got resolved by using a more recent build, right?