Hi,

in a Planet Eclipse article I just came across some JDT feature yet unknown to me, which helps in better null-check analysis of Java code at compile-time, and at the same time improves API documentation:

http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-using_null_annotations.htm&cp=1_3_9_0

Maybe this could be used to improve API quality of Magnolia, and of course help in avoiding NPEs?

From the above Eclipse help page:

Available annotations

The Eclipse Java compiler can be configured to use three distinct annotation types for its enhanced null analysis (which is disabled by default):

  • @NonNull: null is not a legal value
  • @Nullable: null value is allowed and must be expected
  • @NonNullByDefault: types in method signatures that lack a null annotation are regarded as non-null.

Annotations @NonNull and @Nullable are supported in these locations:

  • Method parameter
  • Method return (syntactically a method annotation is used here)
  • Local variables
  • (more to come in the future)

@NonNullByDefault is supported for

  • Methods - to affect all types in this method's signature
  • Types (classes, interfaces, enums) - to affect all methods in the type body
  • Package (via a file package-info.java) - to affect all types in the package

Note, that even the actual qualified names of these annotations are configurable, but by default the ones given above are used (from the package org.eclipse.jdt.annotation).

So one can define one's own annotations to be used, in case it is a problem to get the JDT jar in the compile time classpath. The annotations are not required at runtime. Not sure how this can be used in a Maven build, IIRC some Maven plugin for using the JDT compiler exists.

WDYT?

Regards,
Jörg

--
Dipl. inf. Jörg von Frantzius, System Architect

Email mailto:joerg.frantz...@aperto.de
Phone +49 30 283921-318
Fax +49 30 283921-29

Aperto AG - In der Pianofabrik
Chausseestraße 5, D-10115 Berlin-Mitte
http://www.aperto.de
http://www.facebook.com/aperto
https://www.xing.com/companies/apertoag

HRB 77049, AG Berlin Charlottenburg
Vorstand: Dirk Buddensiek (Vorsitzender), Kai Großmann, Stephan Haagen
Aufsichtsrat: Bernd Hardes (Vorsitzender)



----------------------------------------------------------------
For list details, see: http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <dev-list-unsubscr...@magnolia-cms.com>
----------------------------------------------------------------

Reply via email to