Bug 493151 - [null] Wrong warning about unchecked conversion. Constraints lost after using streams.
Summary: [null] Wrong warning about unchecked conversion. Constraints lost after using...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on: 488495
Blocks:
  Show dependency tree
 
Reported: 2016-05-06 11:05 EDT by Stephan Herrmann CLA
Modified: 2020-06-05 18:27 EDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2016-05-06 11:05:37 EDT
+++ This bug was initially created as a clone of Bug #488495 +++

Using Eclipse 4.6-I20160223-0800

After using a few stream methods, it seems that the null constraints get lost. For example, in this code:

@NonNullByDefault
public class Main {

    public static void main(String[] args, Set<String> set) {
        Optional<@Nullable String> kam = set.stream()
                .map(trace -> getString(String.class))
                .findFirst(); // Null type safety (type annotations): The expression of type 'Optional<String>' needs unchecked conversion to conform to 'Optional<@Nullable String>'
        System.out.println(kam);
    }

    public @Nullable static <T extends CharSequence> T getString(Class<T> moduleClass) {
        return null;
    }
}

After the map, it should be a stream of @Nullable String but instead it's just String (can be verified with hover). Because of that, findFirst returns an Optional<String> instead of Optional<@Nullable String>

I attached a sample project for convenience.
Comment 1 Stephan Herrmann CLA 2016-05-06 11:07:07 EDT
Spawned off bug 488495 after investigation only concerned a second (similar) example.

The attachment mentioned is attachment 259931 [details]
Comment 2 Stephan Herrmann CLA 2016-05-06 11:44:38 EDT
As of bug 488495 comment 12 I wonder whether the transfer of null hints in BoundSet.incorporate() (under if(analyzeNull)) should differentiate the bound kinds SUBTYPE and SUPERTYPE to determine in which direction a null hint should flow. I'm not sure this is related to this current bug but I will check via this bug anyway.
Comment 3 Manoj N Palat CLA 2018-05-17 03:25:40 EDT
bulk move out of 4.8
Comment 4 Manoj N Palat CLA 2018-08-17 00:11:04 EDT
Bulk move out of 4.9