Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » null type mismatch with eclipse 4.4rc1 and java 1.8
null type mismatch with eclipse 4.4rc1 and java 1.8 [message #1378575] Sat, 24 May 2014 09:38 Go to next message
Nicola Zanaga is currently offline Nicola ZanagaFriend
Messages: 56
Registered: July 2009
Member
using eclipse 4.4RC1 with "compiler compliance level 1.7", the code below is fine, but with "compiler compliance level 1.8", it doesn't work.


if you use "(E)null" instead of "null" the code work with a warning

import org.eclipse.jdt.annotation.Nullable;

public class Test2<E> {

@Nullable
E test() {
return null;
}


void test2() {
E local = null;
}

}
Re: null type mismatch with eclipse 4.4rc1 and java 1.8 [message #1379023 is a reply to message #1378575] Sat, 24 May 2014 14:11 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
That's to be expected! You need to annotate the generic type

> import org.eclipse.jdt.annotation.Nullable;
>
> public class Test2<@Nullable E> {
> @Nullable
> E test() {
> return null;
> }
>
> void test2() {
> E local = null;
> }
> }

I had the same missunderstanding see
https://bugs.eclipse.org/bugs/show_bug.cgi?id=434374#c8 and
https://bugs.eclipse.org/bugs/show_bug.cgi?id=434374#c11

Tom


On 24.05.14 11:38, Nicola Zanaga wrote:
> import org.eclipse.jdt.annotation.Nullable;
>
> public class Test2<E> {
> @Nullable
> E test() {
> return null;
> }
> void test2() {
> E local = null;
> }
> }
Re: null type mismatch with eclipse 4.4rc1 and java 1.8 [message #1379174 is a reply to message #1379023] Sat, 24 May 2014 15:43 Go to previous messageGo to next message
Nicola Zanaga is currently offline Nicola ZanagaFriend
Messages: 56
Registered: July 2009
Member
I have read the bugs, but I don't understand why it is related.
I declared the variable @Nullable, so it has to be nullable, indeed (E)null works ok.


the declaration
public class Test2<@Nullable E> {
}
give me an error, maybe I miss something

However, E type can be null or not null at class level, but I think I always can do a local variable null:

@NonNull E test2() {
E local = null;
...
if( local != null )
return E;
....
}



Thomas Schindl wrote on Sat, 24 May 2014 10:11
That's to be expected! You need to annotate the generic type

> import org.eclipse.jdt.annotation.Nullable;
>
> public class Test2<@Nullable E> {
> @Nullable
> E test() {
> return null;
> }
>
> void test2() {
> E local = null;
> }
> }

I had the same missunderstanding see
https://bugs.eclipse.org/bugs/show_bug.cgi?id=434374#c8 and
https://bugs.eclipse.org/bugs/show_bug.cgi?id=434374#c11

Tom


On 24.05.14 11:38, Nicola Zanaga wrote:
> import org.eclipse.jdt.annotation.Nullable;
>
> public class Test2<E> {
> @Nullable
> E test() {
> return null;
> }
> void test2() {
> E local = null;
> }
> }

Re: null type mismatch with eclipse 4.4rc1 and java 1.8 [message #1379412 is a reply to message #1379174] Sat, 24 May 2014 18:08 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
The semantics of null type annotations in relation to type parameters and type variables still needs to be documented. I hope I'll find the time to include the basic explanations into the Luna migration guide.

Basically, all examples you give work as designed, but:

Quote:

the declaration
public class Test2<@Nullable E> {
}
give me an error, maybe I miss something


this works for me. What error are you seeing?

best,
Stephan
Re: null type mismatch with eclipse 4.4rc1 and java 1.8 [message #1382012 is a reply to message #1379412] Sun, 25 May 2014 20:52 Go to previous message
Nicola Zanaga is currently offline Nicola ZanagaFriend
Messages: 56
Registered: July 2009
Member
i found the problem: i have update eclipse 4.3 to 4.4, my project point to old
org.eclipse.jdt.annotation
Previous Topic:How to keep track of the selected Quick Fixes?
Next Topic:"enable syntactic null analysis for fields" broken with eclise 4.4rc1 jdk1.8
Goto Forum:
  


Current Time: Sat Nov 09 03:09:56 GMT 2024

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

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

Back to the top