Anybody using @Nullable/@NotNull in production systems?

If so, are you just using it for method parameters and return values? Or
are you annotating class fields as well? What about threading effects?
Have you ever seen a NullPointerException where @NotNull led you to
expect you couldn't get one?

Just curious ;)
R

9 comments

Well, IDEA itself is shot through with them, but I'm starting to use it in the next "day job" project as well. Early days, and I'm mostly just using it for returns and parameters.

--Dave Griffith

0

Robert Gibson wrote:

If so, are you just using it for method parameters and return values? Or
are you annotating class fields as well? What about threading effects?
Have you ever seen a NullPointerException where @NotNull led you to
expect you couldn't get one?

Just curious ;)
R


We can't use it until JB allows you to specify which annotations are
considered notnull./nullable We already have internally used
notnull/nullable annotations and we're not going to switch over our
entire codebase just for the IDEA users.

0

Robert Gibson <robbie_usenet@yahoo.co.uk> wrote:

If so, are you just using it for method parameters and return values? Or
are you annotating class fields as well?


I am using it for all three of them.

What about threading effects?
Have you ever seen a NullPointerException where @NotNull led you to
expect you couldn't get one?


@NotNull does not prevent you from making mistakes. If you write

public class X {

public static void doStuff(@NotNull Date when) {. . .}

}

Nobody prevents you from writing

public class Y {
. . .
X.doStuff(null);
. . .
}

You'll get a warning when you're in file Y, but only when you're in that
particular file.

Those annotations still help a lot because you're a lot more aware of
when something may or may not be null. Whether it works depends on
whether everybody in your team plays by the rules.

Best,

Dirk Dittert

0

Yes, mainly for parameters and return types.
And, yes it helps me. Found some possible NPE I didn't expect. And it
helps me to be more avoid them, where I knew they could occure, but was
too lazy to work around them ;-).

Johannes Schneider


Robert Gibson wrote:

If so, are you just using it for method parameters and return values? Or
are you annotating class fields as well? What about threading effects?
Have you ever seen a NullPointerException where @NotNull led you to
expect you couldn't get one?

Just curious ;)
R

0

Struts Plugin for IDEA is completely annotated with those, both parameters and return types. It helped me to detect a lot of corner cases, and it has become so familiar to me that I always want to use them in my daily work - where I can't use them at all cause we're on 1.4 :)

IMHO it helps alot when the API used in your project is annotated or you have your own complex and abstract code, but it's of limited use for "old" APIs like e.g. Struts itself (unless somebody releases an "upgraded" version ?! ;) ).

0

The other question I would like to ask is if you use those annotations, do you use runtime @NotNull checks facility, if yes does it help you to catch wrong contracts,if no what is the reason. And if you don't use @Nullable/@NotNull at all, would you consider using them if we bundled some migration/erasure tools (those would be simple SSR rules, but just to make sure it is possible=)

Regards,
Eugene.

0

What there really, really, really needs to be is inspections which suggest places where @Nullable/@NotNull annotations should be used. Let the dataflow engine do the work for me!

--Dave Griffith

0

Eugene Vigdorchik wrote:

The other question I would like to ask is if you use those annotations, do you use
runtime @NotNull checks facility, if yes does it help you to catch wrong contracts,if
no what is the reason.


I don't use the annotations except for my plugin development for the same reason that has
already been mentioned, i.e. the requirement to be 1.4 compatible. If I did use them, I'd
like the @NotNull checks to behave like assert statements, i.e. to throw AssertionErrors
and be controlled by the -ea JVM argument. If I did feel the need for an explicit check,
I'd write the code for this instead of relying on a proprietary system.

>And if you don't use @Nullable/@NotNull at all, would you

consider using them if we bundled some migration/erasure tools (those would be simple
SSR rules, but just to make sure it is possible=)


Absolutely, though I doubt SSR rules would do it. There needs to be something more
sophisticated using dataflow analysis that would tell me what needs to be @NotNull and
what can be @Nullable: http://www.jetbrains.net/jira/browse/IDEA-2002

Sascha

0

Dave Griffith wrote:

What there really, really, really needs to be is
inspections which suggest places where @Nullable/@NotNull annotations
should be used. Let the dataflow engine do the work for me!


+100

Even very simple extensions such as being able to let IDEA treat
unannotated fields or methods similarly to @Nullable ones would help a
lot, allowing us to use quickfixes to add @NotNull to the right places.

0

Please sign in to leave a comment.