Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How to null annotate Collectors.joining?
How to null annotate Collectors.joining? [message #1749497] Wed, 07 December 2016 12:08 Go to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 125
Registered: July 2009
Senior Member
@NonNullByDefault
public class Example {
	public String func(List<String> list){
		return list.stream().collect(Collectors.joining(","));
	}
}


I get these warnings:
Null type safety (type annotations): The expression of type 'Collector<CharSequence,capture#of ?,String>' needs unchecked conversion to conform to 'Collector<? super @NonNull String,capture#of ?,@NonNull String>'

Unsafe interpretation of method return type as '@NonNull' based on substitution 'R=@NonNull String'. Declaring type 'Stream<T>' doesn't seem to be designed with null type annotations in mind


I use this annotation:
class java/util/stream/Collectors
joining
 (Ljava/lang/CharSequence;)Ljava/util/stream/Collector<Ljava/lang/CharSequence;*Ljava/lang/String;>;
 (Ljava/lang/CharSequence;)L1java/util/stream/Collector<L1java/lang/CharSequence;*1L1java/lang/String;>;



Are those annotations good?
How can these warning be removed in the cleanest way?

Re: How to null annotate Collectors.joining? [message #1749627 is a reply to message #1749497] Thu, 08 December 2016 17:39 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1526
Registered: July 2009
Senior Member
The second issue "Unsafe interpretation ..." originates from Stream, not from Collectors. Just creating any empty .eea for this class avoids this (e.g., create an arbitrary external annotation and then delete it Smile ).

The former issue looks like a bug to me. This is the exact message I see in HEAD:
Null type safety (type annotations): The expression of type '@NonNull Collector<@NonNull CharSequence,@NonNull capture#of ?,String>' needs unchecked conversion to conform to 'Collector<? super @NonNull String,@NonNull capture#of ?,@NonNull String>'


note that everything is appropriately annotated except for the "String" type argument. Interestingly, removing the annotation on "?" avoids the bug.

Could you please file a bug? TIA.
Stephan
Re: How to null annotate Collectors.joining? [message #1749648 is a reply to message #1749627] Fri, 09 December 2016 05:57 Go to previous message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 125
Registered: July 2009
Senior Member
Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=508955
Previous Topic:Unable to run Java class
Next Topic:Building Eclipse JDT From Source
Goto Forum:
  


Current Time: Fri Nov 17 19:44:48 GMT 2017

Powered by FUDForum. Page generated in 0.01624 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software