mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
01.16.2011 59ffa4898f12b431cfd954b3466277bea046436a
Fix OPENDJ-142: Message.raw() with treats first arg as format string even when there are no format arguments
3 files modified
62 ■■■■■ changed files
opends/src/messages/src/org/opends/messages/Message.java 35 ●●●● patch | view | raw | blame | history
opends/src/messages/src/org/opends/messages/MessageDescriptor.java 22 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/messages/MessageTest.java 5 ●●●●● patch | view | raw | blame | history
opends/src/messages/src/org/opends/messages/Message.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions copyright 2011 ForgeRock AS
 */
package org.opends.messages;
@@ -83,11 +84,7 @@
   *         null if <code>formatString</code> is null
   */
  static public Message raw(CharSequence formatString, Object... args) {
    Message message = null;
    if (formatString != null) {
      message = new MessageDescriptor.Raw(formatString).get(args);
    }
    return message;
    return raw(Category.USER_DEFINED, Severity.INFORMATION, formatString, args);
  }
  /**
@@ -116,11 +113,18 @@
                            CharSequence formatString, Object... args) {
    Message message = null;
    if (formatString != null) {
      MessageDescriptor.Raw md =
              new MessageDescriptor.Raw(formatString,
                      category,
                      severity);
      message = md.get(args);
      if (args == null || args.length == 0)
      {
        MessageDescriptor.Raw md = new MessageDescriptor.Raw(
            "%s", category, severity);
        message = md.get(formatString);
      }
      else
      {
        MessageDescriptor.Raw md = new MessageDescriptor.Raw(
            formatString, category, severity);
        message = md.get(args);
      }
    }
    return message;
  }
@@ -135,17 +139,12 @@
   * will cause this message to render without argument substitution.
   *
   * @param object from which the message will be created
   * @param arguments for message
   * @param args for message
   * @return a message object that will render the same in all locales;
   *         null if <code>object</code> is null
   */
  static public Message fromObject(Object object, Object... arguments) {
    Message message = null;
    if (object != null) {
      CharSequence cs = object.toString();
      message = raw(cs, arguments);
    }
    return message;
  static public Message fromObject(Object object, Object... args) {
    return (object != null) ? raw(object.toString(), args) : null;
  }
  /**
opends/src/messages/src/org/opends/messages/MessageDescriptor.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Portions copyright 2011 ForgeRock AS
 */
package org.opends.messages;
@@ -981,14 +982,6 @@
    /**
     * Creates a parameterized instance.
     * @param formatString for created messages
     */
    Raw(CharSequence formatString) {
      this(formatString, Category.USER_DEFINED, Severity.INFORMATION);
    }
    /**
     * Creates a parameterized instance.
     * @param formatString for created messages
     * @param category for created messages
     * @param severity for created messages
     */
@@ -1000,19 +993,6 @@
    }
    /**
     * Creates a parameterized instance.  Created messages will
     * have a category of <code>Category.USER_DEFINED</code>.
     * @param formatString for created messages
     * @param mask for created messages
     * @param severity for created messages
     */
    Raw(CharSequence formatString, int mask, Severity severity) {
      super(null, null, mask, severity, null, null);
      this.formatString = formatString != null ? formatString.toString() : "";
      this.requiresFormatter = this.formatString.matches(".*%.*");
    }
    /**
     * Creates a message with arguments that will replace format
     * specifiers in the assocated format string when the message
     * is rendered to string representation.
opends/tests/unit-tests-testng/src/server/org/opends/messages/MessageTest.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Portions copyright 2011 ForgeRock AS
 */
package org.opends.messages;
@@ -50,8 +51,8 @@
            {"Hello %s", "Hello World", new Object[]{"World"}},
            {"Hel%nlo %s", "Hel" + EOL + "lo World", new Object[]{"World"}},
            {"Hel%%lo %s", "Hel%lo World", new Object[]{"World"}},
            {"Hel%%lo", "Hel%lo", new Object[]{}},
            {"Hel%nlo", "Hel" + EOL + "lo", new Object[]{}},
            {"Hel%%lo", "Hel%%lo", new Object[]{}},
            {"Hel%nlo", "Hel%nlo", new Object[]{}},
            {"Hel%Dlo", "Hel%Dlo", new Object[]{}},
            {"Hel%Dlo", "Hel%Dlo", new Object[]{ "abc"}},