Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-69

NullpointerException

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • None
    • None
    • Core API
    • None
    • Operating System: Windows XP
      Platform: PC

    Description

      Logger logger = LoggerFactory.getLogger("com.mycompany");

      String[] parameters = null;
      logger.debug("Parameters are {}", parameters);

      will throw a NullPointer exception as follows :

      Exception in thread "main" java.lang.NullPointerException
      at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:136)
      at org.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:223)

      Obviously the compiler binds the debug method to : logger.debug(format, new Object[])

      and to get around this we have to force the other method by using a typecast :
      String[] parameters = null;
      logger.debug("Parameters are {}", (Object)parameters);

      Is there some better way around this ambiguity?

      Attachments

        Activity

          People

            slf4j-dev SLF4J developers list
            venugopalt@ibsplc.com Venu Thachappilly
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: