@Nonnull by default in eclipse / kepler

In eclipse, you can set the default null value for a single package. Is there a way to install it in all packages or for the package tree?

Edit

I'm talking about @Nonnull annotations that overshadow respect and politics. At the moment, we put them in each function, each variable - each parameter. I know that we can simply install them in a package by adding an attribute to the package information, but we have hundreds of packages and this is easy to miss. I hope you can set the eclipse to say "assume @Nonnull by default if @Nullable not specified".

+4
source share
3 answers

Eclipse can help you detect any packages that do not have @NonNullByDefault if you enable the compiler option "Missing" @NonNullByDefault "annotation in package". This parameter is set to "Ignore" by default, set to "Warning" or "Error" as you like.

See http://help.eclipse.org/luna/topic/org.eclipse.jdt.doc.user/reference/preferences/java/compiler/ref-preferences-errors-warnings.htm?cp=1_4_2_0_3_1

+1
source

Try this cute little project:

https://code.google.com/p/notnullcheckweaver/

It inserts null checks around each element annotated with @NotNull

Its default value is @Nullable, so you should still annotate your (root) package to force it to force everything except @Nullable annotated elements.

Disadvantages:

  • It presents another @NotNull annotation and does not allow other users (e.g. java own @Nonnull, spring annotations, etc.)
  • It works through bytecode manipulation and java-agent
0
source

Do you really want to add @Notnull to every function, every variable and every parameter in your project (bearing in mind that you have hundreds of packages)?

What if the function should return null or the parameter should be null?

I do not think it's a good idea.

-1
source

Source: https://habr.com/ru/post/1484122/


All Articles