Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Kinda stuck with JDT null annotations + generics
Kinda stuck with JDT null annotations + generics [message #1514995] Wed, 17 December 2014 19:41 Go to next message
Cristian Martin is currently offline Cristian MartinFriend
Messages: 3
Registered: December 2014
Junior Member
Hello,

I can't seem to understand what the issue with what I'm doing is:

@NonNullByDefault
public interface NamespaceStorage<T> 
{

	Set<T> getObjects(); 
	
}

@NonNullByDefault
public class NamespaceStorageImpl<T> implements NamespaceStorage<T>
{
	@Override
	public  Set<T> getObjects() 
	{
		return new TreeSet<T>();
	}
}


I'm getting "The method @NonNull Set<T> getObjects() from NamespaceStorageImpl<T> cannot implement the corresponding method from NamespaceStorage<T> due to incompatible nullness constraints".

I want type T to be unconstrained - at least I think I do:)

Re: Kinda stuck with JDT null annotations + generics [message #1515150 is a reply to message #1514995] Wed, 17 December 2014 22:47 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
I can't see the error you mention. Can you please specify which version JDT you are using and whether this is a Java 8 project or below?
TIA,
Stephan

Re: Kinda stuck with JDT null annotations + generics [message #1515670 is a reply to message #1515150] Thu, 18 December 2014 09:09 Go to previous messageGo to next message
Cristian Martin is currently offline Cristian MartinFriend
Messages: 3
Registered: December 2014
Junior Member
You are correct, fortunately. I've tried to reproduce the issue at work on a fresh Java 8 project and failed.

I will attempt to further investigate what setup I had at home and post if there's anything of relevance.

Thanks!

Edit:
Scratch that! I managed to reproduce it at my workplace as well. Here are the steps that I did:

- initially the two .java files were compiling fine
- I've added an error on my own by annotating the getObjects implementation with @Nullable
- The quickfix suggested to change the return and I've followed that -> quickfix removed my @Nullable
- now I'm getting my error back: compiler must have got stuck somehow
(" incompatible nullness constraints")

Note that I'm using the jdt-annotation jar by directly including it in the build path (org.eclipse.jdt.annotation_2.0.0.v20140415-1436.jar)

[Updated on: Thu, 18 December 2014 09:25]

Report message to a moderator

Re: Kinda stuck with JDT null annotations + generics [message #1516360 is a reply to message #1515670] Thu, 18 December 2014 21:03 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Thanks I can reproduce now, the bug occurs if NamespaceStorageImpl is compiled alone while NamespaceStorage is read from class file.
Might share the root cause with https://bugs.eclipse.org/bugs/show_bug.cgi?id=453475 -
I'll make a notice to test your example as well once I get to fixing that bug.

thanks,
Stephan
Re: Kinda stuck with JDT null annotations + generics [message #1524174 is a reply to message #1516360] Tue, 23 December 2014 09:13 Go to previous messageGo to next message
Cristian Martin is currently offline Cristian MartinFriend
Messages: 3
Registered: December 2014
Junior Member
Thanks for pointing out the existing bug. Indeed, my code compiles after a clean is done hence I can live with that.

Another thing I would like to comment, although this isn't really an issue.

I've noticed that org.eclipse.core.runtime.Assert is recognized in the null analysis and I was using that anyways. After such an Assert, the flow analysis is happy that the variable/field is @NonNull

Now, it appears that no compiler warnings are issued when redundant Assert.isNotNull are used. Is this intentional?

The bellow code flags only 'if (objTypes == null)' as being redundant.

 public FactoryCache(@Nullable Object objTypes)
{
    	Assert.isNotNull(objTypes);
    	
    	if (objTypes == null)
    	{
    		
    	}
    	Assert.isNotNull(objTypes); 
}


Re: Kinda stuck with JDT null annotations + generics [message #1528456 is a reply to message #1524174] Thu, 25 December 2014 19:20 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Detection of redundant checks is limited to == and != expressions.
IMHO, extending this to assertion methods would unduly complicate the logic.
In some cases people will explicitly want the assert even after flow analysis has voted "safe", just for extra safety.
Previous Topic:4K version of Eclipse
Next Topic:javadoc's "Consant Field Values" page
Goto Forum:
  


Current Time: Sat Mar 02 13:43:57 GMT 2024

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

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

Back to the top