Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 453475 - [1.8][null] Contradictory null annotations (4.5 M3 edition)
Summary: [1.8][null] Contradictory null annotations (4.5 M3 edition)
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.4.2   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-27 13:36 EST by Chris Hubick CLA
Modified: 2015-01-28 03:41 EST (History)
3 users (show)

See Also:


Attachments
Combined patch to consider for 4.4.2 (25.12 KB, patch)
2015-01-14 18:40 EST, Stephan Herrmann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Hubick CLA 2014-11-27 13:36:21 EST
TestMap.java
------------
> import java.util.*;
> import org.eclipse.jdt.annotation.*;
> 
> @NonNullByDefault
> public abstract class TestMap extends AbstractMap<String,@Nullable String> {
> 
> }

Test.java
------------
> import java.util.*;
> import org.eclipse.jdt.annotation.*;
> 
> @NonNullByDefault
> public class Test {
> 
>   public static final void test(TestMap testMap) {
>     testMap.putAll(new HashMap<String,@Nullable String>()); // Error: Contradictory null annotations: method was inferred as 'void putAll(Map<? extends @NonNull String,? extends @NonNull @Nullable String>)', but only one of '@NonNull' and '@Nullable' can be effective at any location
>   }
> 
> }

eclipse.buildId=4.5.0.I20141029-2000

If I do a "Project->Clean..." the error disappears and won't show up until I modify and save Test.java.

Sorry if this is a dup, but all the others are marked verified fixed in earlier releases.
Comment 1 Chris Hubick CLA 2014-12-04 17:18:09 EST
(In reply to Chris Hubick from comment #0)
> If I do a "Project->Clean..." the error disappears and won't show up until I
> modify and save Test.java.

Maybe related to Bug 444024?
Comment 2 Stephan Herrmann CLA 2014-12-16 18:39:15 EST
I can reproduce: TestMap must be read from .class while compiling Test.java.

I assume that merging default & explicit annotations just doesn't work for type arguments of a BinaryTypeBinding's super type. Apparently a bug in NonNullDefaultAwareTypeAnnotationWalker.getAnnotationsAtCursor(), which blindly merges annotations without checking for overriding.
Comment 3 Stephan Herrmann CLA 2014-12-18 19:08:22 EST
See https://www.eclipse.org/forums/index.php?t=msg&th=896396&goto=1514995&#msg_1514995 for a related example - perhaps same root cause?
Comment 4 Stephan Herrmann CLA 2014-12-22 14:54:16 EST
Released for 4.5 M5 via commit 7c493ed6b34d98f52ff4fc8520fcd8662e5ffd91.

@Jay: I believe this would be good to have in 4.4.2.

Reading null default annotations from binary types didn't follow our rules for null defaults:
- @NNBD was wrongly applied despite explicit @Nullable (comment 0)
- @NNBD was wrongly applied to wildcards and type variable use (see comment 3), violating the javadoc of DefaultLocation.

Let me know if you'd like a description of the fix, too.
Comment 5 Jay Arthanareeswaran CLA 2015-01-14 06:33:15 EST
(In reply to Stephan Herrmann from comment #4)
> Released for 4.5 M5 via commit 7c493ed6b34d98f52ff4fc8520fcd8662e5ffd91.
> 
> @Jay: I believe this would be good to have in 4.4.2.

Stephan, sorry I missed out this one. Yes, We can include this one. I tried a quick attempt at back porting along with other ones, but ran into merge conflicts. Will take this up little later.
Comment 6 Stephan Herrmann CLA 2015-01-14 10:08:48 EST
(In reply to Jay Arthanareeswaran from comment #5)
> (In reply to Stephan Herrmann from comment #4)
> > Released for 4.5 M5 via commit 7c493ed6b34d98f52ff4fc8520fcd8662e5ffd91.
> > 
> > @Jay: I believe this would be good to have in 4.4.2.
> 
> Stephan, sorry I missed out this one.

n.p.

> Yes, We can include this one. I tried
> a quick attempt at back porting along with other ones, but ran into merge
> conflicts. Will take this up little later.

I can handle this tomorrow, unless you beat me to it :)
Comment 7 Stephan Herrmann CLA 2015-01-14 17:02:02 EST
I see why this doesn't cleanly apply: it depends on commit 63231f253dc3aaae18caf57a7f77da85f8cefe96 (1st part of bug 439516).

I'm running tests against this pair of commits on top of R4_4_maintenance.

If tests pass, I'll come back and comment on risks with / without those changes.
Comment 8 Stephan Herrmann CLA 2015-01-14 18:40:00 EST
Created attachment 249951 [details]
Combined patch to consider for 4.4.2

RunJDTCoreTests are green.

Sorry this came piecemeal. Both patches in question are actually closely related:

(from bug 439516 comment #4)
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=63231f253dc3aaae18caf57a7f77da85f8cefe96
> Don't apply nonnull-default on <T extends Object> when read from .class.

and

(In reply to Stephan Herrmann from comment #4)
> Released for 4.5 M5 via commit 7c493ed6b34d98f52ff4fc8520fcd8662e5ffd91.
>
> Reading null default annotations from binary types didn't follow our rules
> for null defaults:
> - @NNBD was wrongly applied despite explicit @Nullable (comment 0)
> - @NNBD was wrongly applied to wildcards and type variable use (see comment
> 3), violating the javadoc of DefaultLocation.


The first patch may look big, but it's not complex: we just need to feed one more piece of information into TypeAnnotationWalker - from several places.


While null type annotations are still new, I see the risk that adopters might wrongly adjust their code in response to these bugs.

OTOH, users that don't enable null type annotations should not be affected, since the main change is in NonNullDefaultAwareTypeAnnotationWalker, which isn't even instantiated in their case.

For your convenience, I've attached a patch combined from both commits under consideration.

OK to release both changes to 4.4.2?


If you're unsure, it's probably OK to tell adopters that they should switch to Mars at their earliest convenience, because quite a few bugs are only fixed in master, in particular most from the cluster of bug 438458.
Comment 9 Jay Arthanareeswaran CLA 2015-01-15 01:41:55 EST
(In reply to Stephan Herrmann from comment #8)
> OK to release both changes to 4.4.2?

+1 for back porting.

> If you're unsure, it's probably OK to tell adopters that they should switch
> to Mars at their earliest convenience, because quite a few bugs are only
> fixed in master, in particular most from the cluster of bug 438458.

I share the same thoughts. We can still back port this. But this should be our line or response for those we can't accommodate in 4.4.2 :)
Comment 10 Stephan Herrmann CLA 2015-01-15 07:30:58 EST
Thanks, pushed to R4_4_maintenance:

Prerequisite patch #1 from bug 439516 comment #4 via commit e0b75d21a26e97c9a42f6cf8d270088b82d36613

Patch from this bug via commit ecc644906c7fc73a8306ba44f6555680f46dcb51
Comment 11 shankha banerjee CLA 2015-01-21 23:40:32 EST
Verified for 4.4.2 RC1 using build M20150121-0900.
Comment 12 shankha banerjee CLA 2015-01-22 00:15:20 EST
Verified for 4.5 M5 using build N20150121-2000.
Comment 13 Stephan Herrmann CLA 2015-01-22 07:13:08 EST
Reverted target milestone the 4.4.2 as that is the lowest version containing the fix.
Comment 14 Manoj N Palat CLA 2015-01-28 03:41:49 EST
Verified for Eclipse Mars 4.5 M5 Build id: I20150126-2000