Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 471048 - [1.8][null] False positive for 'Null type safety' depends on package name order then using lambdas
Summary: [1.8][null] False positive for 'Null type safety' depends on package name ord...
Status: VERIFIED DUPLICATE of bug 485465
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5   Edit
Hardware: PC Linux
: P3 blocker (vote)
Target Milestone: 4.6 M6   Edit
Assignee: Till Brychcy CLA
QA Contact: Stephan Herrmann CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-25 16:07 EDT by Vladimir Tsichevski CLA
Modified: 2016-04-26 00:44 EDT (History)
3 users (show)

See Also:


Attachments
The tiny complete eclipse project that demonstrates the bug (5.42 KB, application/gzip)
2015-06-25 16:07 EDT, Vladimir Tsichevski CLA
no flags Details
Updated version of the previous attachment (5.39 KB, application/gzip)
2015-06-26 05:18 EDT, Vladimir Tsichevski CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Tsichevski CLA 2015-06-25 16:07:00 EDT
Created attachment 254724 [details]
The tiny complete eclipse project that demonstrates the bug

I have two classes: y.A and x.B:

------------------------------------------------
package y;

public class A {
  private String f = "";

  public void setF(String v) {
    f = v;
  }

   public String getF() {
    return f;
  }
}
------------------------------------------------
package x;

import java.util.concurrent.Callable;

public class B {

  public static void dummy(final A p) throws Exception {
    dummy1(() -> {
      p.setF("a");
      return "b";
    });
    p.setF("c");
  }

  public static <T> void dummy1(Callable<T> callable) throws Exception {
    callable.call();
  }
}
------------------------------------------------

1. I have Java compiler null analysis On.
2. I set the NonNullByDefault behaviour on in all package-info.java
3. The compiler complains:
Null type safety (type annotations): The expression of type 'String' needs unchecked conversion to conform to '@NonNull String'

for the 'v' parameter of void A.setF(String v).

This happens when all the following conditions are met:

1. Every time after I have 'project clean' called. If I touch the A.java in the editor, the problem disappears.
2. I refer the 'setF' in a lambda expression. If I change the lambda to an anonymous class, the problem disappears.
3. If I have no statements with a call to 'setF' before is is referred in the lambda. For example, if I move the 'p.setF("c");' statement to the beginning of the 'dummy' method, the problem disappears.
4. If the package for the A class ('y' in my example) is alphabetically after the package of the B class ('x' in my example).

The whole project is appended to this report.

I use eclipse-rcp-mars-R-linux-gtk-x86_64
Comment 1 Stephan Herrmann CLA 2015-06-25 16:27:25 EDT
Thanks, I'll take a look.
Comment 2 Vladimir Tsichevski CLA 2015-06-26 05:18:28 EDT
Created attachment 254746 [details]
Updated version of the previous attachment

Class names in the original attachment did not match that in the bug description.
Comment 3 Vladimir Tsichevski CLA 2015-07-26 12:28:11 EDT
Hi, any progress here?
Comment 4 Stephan Herrmann CLA 2015-07-26 12:43:20 EDT
(In reply to Vladimir Tsichevski from comment #3)
> Hi, any progress here?

Not yet. See that the bug is scheduled for 4.6 which is still 11 months ahead :)
Comment 5 Till Brychcy CLA 2016-04-06 15:16:22 EDT
Stephan, this is already fixed.
It is is as duplicate of bug 485465, fixed by commit 5959bbf385fc1f797d392576c0a27049452fc9d1
Comment 6 Stephan Herrmann CLA 2016-04-11 08:36:53 EDT
(In reply to Till Brychcy from comment #5)
> Stephan, this is already fixed.
> It is is as duplicate of bug 485465, fixed by commit
> 5959bbf385fc1f797d392576c0a27049452fc9d1

You're right, thanks for making the connection.

FWIW, I tried to reproduce using the batch compiler, but failed. Only a full build in the IDE proved that the bug occurred prior to commit 5959bbf385fc1f797d392576c0a27049452fc9d1 and has been fixed by that commit.

*** This bug has been marked as a duplicate of bug 485465 ***
Comment 7 Jay Arthanareeswaran CLA 2016-04-26 00:44:12 EDT
Verified for 4.6 M7 with build I20160425-1300