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

Error using %K in pattern : MapPatternConverter cannot contain multiple static newInstance method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.11.2
    • 2.12.0
    • None
    • None

    Description

      When using a %K in a pattern, the MapPatterConverter is used and there is an error message :

      ERROR Class class org.apache.logging.log4j.core.pattern.MapPatternConverter cannot contain multiple static newInstance methods

       

      The control is done by org.apache.logging.log4j.core.pattern.PatternParser.createConverter here :

       // Work around the regression bug in Class.getDeclaredMethods() in Oracle Java in version > 1.6.0_17:
              _// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6815786_
              final Method[] methods = converterClass.getDeclaredMethods();
              Method newInstanceMethod = null;
              for (final Method method : methods) {
                  if (Modifier.isStatic(method.getModifiers()) && method.getDeclaringClass().equals(converterClass)
                          && method.getName().equals("newInstance")) {
                      if (newInstanceMethod == null) {
                          newInstanceMethod = method;
                      } else if (method.getReturnType().equals(newInstanceMethod.getReturnType())) {
                          LOGGER.error("Class " + converterClass + " cannot contain multiple static newInstance methods");
                          return null;
                      }
                  }
              }

       

      The class org.apache.logging.log4j.core.pattern.MapPatternConverter contains 2 newInstances message (teh second introduced in 2.11.2)

       

       /**
           * Obtains an instance of {@link MapPatternConverter}.
           *
           * @param options options, may be null or first element contains name of property to format.
           * @return instance of {@link MapPatternConverter}.
           */
          public static MapPatternConverter newInstance(final String[] options) {
              return new MapPatternConverter(options, JAVA_UNQUOTED);
          }

          /**
           * Obtain an instance of {@link MapPatternConverter}.
           *
           * @param options options, may be null or first element contains name of property to format.
           * @param format the format to use if no options are given (i.e., options is null). Ignored if options is non-null.
           * @return instance of {@link MapPatternConverter}.
           * @since 2.11.2
           */
          public static MapPatternConverter newInstance(final String[] options, final MapFormat format) {
              return new MapPatternConverter(options, Objects.toString(format, JAVA_UNQUOTED));
          }

       

       

      Attachments

        Issue Links

          Activity

            People

              ckozak Carter Kozak
              anthonyC Anthony Communier
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m