You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by Julian Reschke <ju...@gmx.de> on 2012/05/18 12:16:29 UTC

nullability annotations - https://issues.apache.org/jira/browse/OAK-37

Hi there,

- oak-core and oak-jcr now include the necessary findbugs dependency 
(jsr305)

- I have started annotating methods on JCR interface impls (SessionImpl 
& friends), plus a few internal classes (*Delegate)

I believe this is useful, it already revealed a number of potential 
problems (see below).

Adding the annotation *is* a bit verbose, but we can probably reduce the 
noise by adding class-wide (or even package-wide) defaults.

Feedback appreciated,

Julian


-- snip --


Description	Resource	Path	Location	Type
Possible null pointer dereference in 
org.apache.jackrabbit.oak.jcr.PropertyDelegate.getPath() due to return 
value of called method	PropertyDelegate.java 
/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr	line 67	FindBugs 
Problem (Troubling)
Possible null pointer dereference in 
org.apache.jackrabbit.oak.jcr.PropertyImpl.getParent() due to return 
value of called method	PropertyImpl.java 
/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr	line 75	FindBugs 
Problem (Troubling)
Possible null pointer dereference in 
org.apache.jackrabbit.oak.jcr.query.QueryResultImpl$2.fetch() due to 
return value of called method	QueryResultImpl.java 
/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query	line 140 
FindBugs Problem (Troubling)
Possible null pointer dereference in 
org.apache.jackrabbit.oak.jcr.query.RowImpl.getNodeForPath(String) due 
to return value of called method	RowImpl.java 
/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query	line 60 
FindBugs Problem (Troubling)
Possible null pointer dereference in 
org.apache.jackrabbit.oak.jcr.security.user.UserManagerImpl.removeInternalProperty(Node, 
String) due to return value of called method	UserManagerImpl.java 
/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user 
line 352	FindBugs Problem (Troubling)
Possible null pointer dereference in 
org.apache.jackrabbit.oak.jcr.security.user.UserManagerImpl.setInternalProperty(Node, 
String, String, int) due to return value of called method 
UserManagerImpl.java 
/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user 
line 338	FindBugs Problem (Troubling)
Possible null pointer dereference in 
org.apache.jackrabbit.oak.jcr.security.user.UserManagerImpl.setInternalProperty(Node, 
String, String[], int) due to return value of called method 
UserManagerImpl.java 
/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user 
line 343	FindBugs Problem (Troubling)
Possible null pointer dereference in 
org.apache.jackrabbit.oak.jcr.security.user.UserManagerImpl.setInternalProperty(Node, 
String, Value[]) due to return value of called method 
UserManagerImpl.java 
/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user 
line 348	FindBugs Problem (Troubling)

Re: nullability annotations - https://issues.apache.org/jira/browse/OAK-37

Posted by Julian Reschke <ju...@gmx.de>.
Hi there,

I just tried @Nullable vs @CheckForNull on parameters.

It appears that the stand-alone version of FindBugs handles these, while 
the Eclipse plugin does not. (If anybody can enlighten me what I'm doing 
wrong, please go ahead)

Thus I would propose that if we want to annotate parameters, we stick 
with @CheckForNull for now, even if it looks a bit awkward.

Best regards, Julian

Re: nullability annotations - https://issues.apache.org/jira/browse/OAK-37

Posted by Michael Dürig <md...@apache.org>.

On 23.5.12 21:22, Julian Reschke wrote:
> On 2012-05-23 18:43, Michael Dürig wrote:
>>
>> Hi,
>>
>> IntelliJ gives me the warning
>>
>> "Not annotated method overrides method annotated with @NotNull"
>>
>> whenever a method is not annotated with @NotNull and the method it
>> overrides is annotated with @NotNull.
>>
>> Should we add annotations in all those places? Or should we ignore the
>> warning?
>> ...
>
> Findbugs inherits the annotation and does apply it.

Ok.

>
> If adding it to the implementation avoids warning noise in IntelliJ,
> let's do that.

I just disabled this warning in IntelliJ globally. It seems IntelliJ 
also inherits the annotations so there is no point in having the warning 
or spaming the code with extra annotations.

Michael

>
> Best regards, Julian


Re: nullability annotations - https://issues.apache.org/jira/browse/OAK-37

Posted by Julian Reschke <ju...@gmx.de>.
On 2012-05-23 18:43, Michael Dürig wrote:
>
> Hi,
>
> IntelliJ gives me the warning
>
> "Not annotated method overrides method annotated with @NotNull"
>
> whenever a method is not annotated with @NotNull and the method it
> overrides is annotated with @NotNull.
>
> Should we add annotations in all those places? Or should we ignore the
> warning?
> ...

Findbugs inherits the annotation and does apply it.

If adding it to the implementation avoids warning noise in IntelliJ, 
let's do that.

Best regards, Julian

Re: nullability annotations - https://issues.apache.org/jira/browse/OAK-37

Posted by Michael Dürig <md...@apache.org>.
Hi,

IntelliJ gives me the warning

"Not annotated method overrides method annotated with @NotNull"

whenever a method is not annotated with @NotNull and the method it 
overrides is annotated with @NotNull.

Should we add annotations in all those places? Or should we ignore the 
warning?

Michael

On 18.5.12 11:16, Julian Reschke wrote:
> Hi there,
>
> - oak-core and oak-jcr now include the necessary findbugs dependency
> (jsr305)
>
> - I have started annotating methods on JCR interface impls (SessionImpl
> & friends), plus a few internal classes (*Delegate)
>
> I believe this is useful, it already revealed a number of potential
> problems (see below).
>
> Adding the annotation *is* a bit verbose, but we can probably reduce the
> noise by adding class-wide (or even package-wide) defaults.
>
> Feedback appreciated,
>
> Julian
>
>
> -- snip --
>
>
> Description Resource Path Location Type
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.PropertyDelegate.getPath() due to return
> value of called method PropertyDelegate.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr line 67 FindBugs
> Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.PropertyImpl.getParent() due to return
> value of called method PropertyImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr line 75 FindBugs
> Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.query.QueryResultImpl$2.fetch() due to
> return value of called method QueryResultImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query line 140
> FindBugs Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.query.RowImpl.getNodeForPath(String) due
> to return value of called method RowImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query line 60
> FindBugs Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.security.user.UserManagerImpl.removeInternalProperty(Node,
> String) due to return value of called method UserManagerImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user line
> 352 FindBugs Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.security.user.UserManagerImpl.setInternalProperty(Node,
> String, String, int) due to return value of called method
> UserManagerImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user line
> 338 FindBugs Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.security.user.UserManagerImpl.setInternalProperty(Node,
> String, String[], int) due to return value of called method
> UserManagerImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user line
> 343 FindBugs Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.security.user.UserManagerImpl.setInternalProperty(Node,
> String, Value[]) due to return value of called method
> UserManagerImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user line
> 348 FindBugs Problem (Troubling)

Re: nullability annotations - https://issues.apache.org/jira/browse/OAK-37

Posted by Michael Dürig <md...@apache.org>.

On 18.5.12 18:25, Julian Reschke wrote:
> On 2012-05-18 13:58, Michael Dürig wrote:
>>
>> Hi Julian,
>>
>> Thanks for setting this up. I think this is of great value and we should
>> take these warning very serious.
>>
>> In case anyone wonders how to integrate this with IntelliJ: just enable
>> the inspection called "Constants, conditions & exceptions". Took me a
>> while to figure this out.
>>
>> Michael
>> ...
>
> Thanks for that.
>
> Here's an example of the problems we need to take care of --
> PropertyDelegate has:


[...]
> So getParentTree() calls resolve(), which in turn can return with parent
> == null.
>
> Yet, remove() assumes the return value of getParentTree is never null.
>

Yes I know. This is a result of the Oak API and internals being in flux 
for quite some time and also the discussion about how/whether to use 
exceptions to report error conditions. Having the nullability 
annotations in place will be a great help to clean this up. I plan to 
look at this as soon as I'm done with OAK-100 and OAK-102 and related stuff.

Michael

Re: nullability annotations - https://issues.apache.org/jira/browse/OAK-37

Posted by Julian Reschke <ju...@gmx.de>.
On 2012-05-18 13:58, Michael Dürig wrote:
>
> Hi Julian,
>
> Thanks for setting this up. I think this is of great value and we should
> take these warning very serious.
>
> In case anyone wonders how to integrate this with IntelliJ: just enable
> the inspection called "Constants, conditions & exceptions". Took me a
> while to figure this out.
>
> Michael
> ...

Thanks for that.

Here's an example of the problems we need to take care of -- 
PropertyDelegate has:

     public void remove() {
         getParentTree().removeProperty(getName());
     }

     private Tree getParentTree() {
         resolve();
         return parent;
     }

     private synchronized void resolve() {
         parent = sessionDelegate.getTree(parent.getPath());

         if (parent == null) {
             propertyState = null;
         } else {
             String path = PathUtils.concat(parent.getPath(), 
propertyState.getName());
             propertyState = parent.getProperty(PathUtils.getName(path));
         }
     }

So getParentTree() calls resolve(), which in turn can return with parent 
== null.

Yet, remove() assumes the return value of getParentTree is never null.

Best regards, Julian

Re: nullability annotations - https://issues.apache.org/jira/browse/OAK-37

Posted by Michael Dürig <md...@apache.org>.
Hi Julian,

Thanks for setting this up. I think this is of great value and we should 
take these warning very serious.

In case anyone wonders how to integrate this with IntelliJ: just enable 
the inspection called "Constants, conditions & exceptions".  Took me a 
while to figure this out.

Michael

On 18.5.12 11:16, Julian Reschke wrote:
> Hi there,
>
> - oak-core and oak-jcr now include the necessary findbugs dependency
> (jsr305)
>
> - I have started annotating methods on JCR interface impls (SessionImpl
> & friends), plus a few internal classes (*Delegate)
>
> I believe this is useful, it already revealed a number of potential
> problems (see below).
>
> Adding the annotation *is* a bit verbose, but we can probably reduce the
> noise by adding class-wide (or even package-wide) defaults.
>
> Feedback appreciated,
>
> Julian
>
>
> -- snip --
>
>
> Description Resource Path Location Type
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.PropertyDelegate.getPath() due to return
> value of called method PropertyDelegate.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr line 67 FindBugs
> Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.PropertyImpl.getParent() due to return
> value of called method PropertyImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr line 75 FindBugs
> Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.query.QueryResultImpl$2.fetch() due to
> return value of called method QueryResultImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query line 140
> FindBugs Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.query.RowImpl.getNodeForPath(String) due
> to return value of called method RowImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query line 60
> FindBugs Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.security.user.UserManagerImpl.removeInternalProperty(Node,
> String) due to return value of called method UserManagerImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user line
> 352 FindBugs Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.security.user.UserManagerImpl.setInternalProperty(Node,
> String, String, int) due to return value of called method
> UserManagerImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user line
> 338 FindBugs Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.security.user.UserManagerImpl.setInternalProperty(Node,
> String, String[], int) due to return value of called method
> UserManagerImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user line
> 343 FindBugs Problem (Troubling)
> Possible null pointer dereference in
> org.apache.jackrabbit.oak.jcr.security.user.UserManagerImpl.setInternalProperty(Node,
> String, Value[]) due to return value of called method
> UserManagerImpl.java
> /oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user line
> 348 FindBugs Problem (Troubling)