Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » JDT Annotation @Nullable not treated as default
JDT Annotation @Nullable not treated as default [message #1118533] Fri, 27 September 2013 13:58 Go to next message
Mark Leone is currently offline Mark LeoneFriend
Messages: 69
Registered: April 2012
Member
Maybe I'm misreading the documentation, but it seems to me that when using JDT annotations for null analysis, @Nullable is considered the default when inheriting from a a class with annotations applied.

So I have the following method declaration in an abstract class:
protected void someMethod(@Nullable SomeType param_1, @Nullable SomeType param_2) {
		
}

And the following overriding declaration in a sublcass:

@Override
protected void someMethod(SomeType param_1, SomeType param_2) {
	...
}

The compiler complains that I have to annotate the method parameters in the subclass implementation with @Nullable since the parameters are declared that way in the superclass. But I thought that @Nullable is the default, so I don't have to explicitly apply the @Nullable annotations to subclass implementations. Either I'm wrong about that, or there's some configuration setting I'm not aware of.

The annotation @NonNullByDefault is not being used anywhere, but the compiler seems to be acting as though it is. I'm trying to avoid having to apply hundreds of annotations in a legacy code base.

Edit: I'm using Juno. A colleague using Kepler has a preference option under Java -> Compiler -> Errors and Warnings -> Null Analysis called "Inherit Null Annotations". Checking this preference fixes the problem for him, but the preference is not available in my IDE. I can upgrade to Kepler, but would like to know is there any way to get the desired behavior in Juno?

[Updated on: Fri, 27 September 2013 15:33]

Report message to a moderator

Re: JDT Annotation @Nullable not treated as default [message #1118631 is a reply to message #1118533] Fri, 27 September 2013 15:59 Go to previous messageGo to next message
Mark Leone is currently offline Mark LeoneFriend
Messages: 69
Registered: April 2012
Member
Apparently this is expected behavior, which in Kepler can be overridden.

From http://wiki.eclipse.org/JDT_Core/Null_Analysis/Null_Contracts#Null_Contract_Inheritance

"A method that overrides or implements a corresponding method of a super type (class or interface) inherits the full obligations put forward by the super method's null contract. For clarity of the code the overriding method must repeat the inherited signature including any null annotations."

I updated the Platform feature in my IDE, which took me to Kepler SR1, and I now have the preference that enables me to enable inheritance of null annotations.

[Updated on: Fri, 27 September 2013 18:58]

Report message to a moderator

Re: JDT Annotation @Nullable not treated as default [message #1118635 is a reply to message #1118533] Fri, 27 September 2013 16:01 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Quote:
Maybe I'm misreading the documentation, but it seems to me that when using JDT annotations for null analysis, @Nullable is considered the default when inheriting from a a class with annotations applied.


Where did you read that?

Normally, no annotation really means no annotation, neither @NonNull nor @Nullable (the mode I tend to call "legacy"). As you mentioned, this can be changed using @NonNullByDefault.

Regarding inheritance JDT normally does not implicitly apply any annotations, but there's a compiler option to "inherit" null annotations from a super method.

That's all there is.
Stephan
Previous Topic:Tooltip over expression: Ocurrence of Vs. Javadoc
Next Topic:Cannot run app
Goto Forum:
  


Current Time: Wed Apr 24 17:06:37 GMT 2024

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

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

Back to the top