Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1477

@NonNull support (for @NonNullByDefault or similar)

    XMLWordPrintableJSON

Details

    • Wish
    • Status: In Progress
    • Major
    • Resolution: Unresolved
    • 2.6.2
    • 3.0.0
    • API
    • None
    • any

    Description

      Eclipse (and other tools) offer non-null checks by annotation processing.

      One of the possibilities to enable this is to add the annotation @org.eclipse.jdt.annotation.NonNullByDefault in your package-info.java file.

      Example:

      @org.eclipse.jdt.annotation.NonNullByDefault
      package foo;

      A frequent problem is reported when using a logger:

      private static final Logger LOGGER = LogManager.getLogger(Bla.class);

      for which Eclipse says:
      Null type safety (type annotations): The expression of type 'Logger' needs unchecked conversion to conform to '@NonNull Logger' Bla.java (...)

      This can by bypassed by putting a @SuppressWarnings("null") over the expression, but this has to be done in every class, and may be the only line of code with this workaround.

      Problems:

      • There are other annotations for non-null (javax.annotation.Nonnull) and many other frameworks, like the Checker Framework.
      • I don't want to be a judge which one to choose.
      • Deeper support may require a dependency on Java 8.
      • If you want to do it framework wide, this can be a huge task.
      • As some tools are not mature (IMHO), it will need experiments.

      Attachments

        Issue Links

          Activity

            People

              mattsicker Matt Sicker
              bojanantonovic Bojan Antonović
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: