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

Avoid calling toString() on auto-boxed primitive message parameters

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.6
    • Fix Version/s: 2.6.2
    • Component/s: None
    • Labels:
      None

      Description

      When using Log4j 2 through the SLF4J binding, the Unboxer mecanism is not available and a parameterized message with a primitive type parameter will be auto-boxed.

      Then this boxed value will be formatted by ParameterFormatter.recursiveDeepToString() and further allocations will happen

      To lower allocation rate for SLF4J users, ParameterFormatter.appendSpecialTypes() should handle boxed primitive types too.

      private static boolean appendSpecialTypes(final Object o, final StringBuilder str) {
          ...
          } else if (o instanceof Long) {
              str.append(((Long) o).longValue());
              return true;
          } else if (o instanceof Integer) {
              str.append(((Integer) o).intValue());
              return true;
          } else if (o instanceof Double) {
              str.append(((Double) o).doubleValue());
              return true;
          } // similarly for float, short, boolean and char.
          ...
      }
      

        Attachments

        Issue Links

          Activity

            People

            • Assignee:
              rpopma Remko Popma
              Reporter:
              Anthony Maire Anthony Maire

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment