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

ArrayIndexOutOfBoundsException in ReusableParameterizedMessage

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.6
    • 2.6.1
    • API, Core
    • None

    Description

      A specific set of parameterised logging messages produces an Array Index Out of Bounds exception. It occurs due to the params array (initially set to 10) being reset to a lower number due to a lambda function passed in as an parameter. Then the subsequent logging messages don't reset this number.

      Best to explain in an example:

          static Logger logger = LogManager.getLogger();
      
          public static void main(String[] args) {
              logger.info("Hello {} {} {}", 1, 2,3);
              logger.info("Hello {}", () -> "World");
              logger.info("Hello {}", 1);
              
              // Uncomment out this log event and the params gets reset correctly
              // No exception occurs
              // logger.info("Hello {}", 1);
      
              // Exception at this log event - as the params is set to 1!
              logger.info("Hello {} {} {}", 1, 2,3);
          }
      

      Work around for this is not to use the ReusableParameterizedMessage. Instead to specify the legacy Message Factory of ParameterizedMessageFactory as a property of the program and no exception occurs.

      Attachments

        Activity

          People

            rpopma Remko Popma
            Shahan Shahan
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: