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

LocalizedMessageFactory creates new message with baseName as messagePattern

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Trivial
    • Resolution: Unresolved
    • 2.13.3
    • None
    • API
    • Important

    Description

      When I instantiate LocalizedMessageFactory with the String baseName constructor and then I create a new LocalizedMessage by the method public Message newMessage(final String key), it instantiates the message with the constructor that use String messagePattern and String key, using the resource bundle baseName as messagePattern, and the key as an argument of the pattern.

      /**
      * @since 2.8
      */
      @Override
      public Message newMessage(final String key) {
          if (resourceBundle == null) {
              return new LocalizedMessage(baseName,  key);
          }
          return new LocalizedMessage(resourceBundle, key);
      }

      The constructor of LocalizedMessage used is:

      public LocalizedMessage(final String messagePattern, final Object arg) {
          this((ResourceBundle) null, (Locale) null, messagePattern, new Object[] {arg});
      }
      

       The Factory should use this constructor: 

      public LocalizedMessage(final String baseName, final String key, final Object arg) {
          this(baseName, (Locale) null, key, new Object[] {arg});
      }

        The fix should be: 

      /**
       * @since 2.8
       */
      @Override
      public Message newMessage(final String key) {
          if (resourceBundle == null) {
              return new LocalizedMessage(baseName, key, null);
          }
          return new LocalizedMessage(resourceBundle, key);
      }
      
      

       

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dvillablanca Diego Villablanca
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 10m
                  10m
                  Remaining:
                  Remaining Estimate - 10m
                  10m
                  Logged:
                  Time Spent - Not Specified
                  Not Specified