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

jvergara
02.08.2008 3da3689e0ed13c19dd80d3a382bb18a7da702d19
Workaround for 3077 (Investigate possible issues with message formatting in AIX) 
1 files modified
68 ■■■■■ changed files
opends/src/messages/src/org/opends/messages/Message.java 68 ●●●●● patch | view | raw | blame | history
opends/src/messages/src/org/opends/messages/Message.java
@@ -56,6 +56,10 @@
  /** Represents an empty message string. */
  public static final Message EMPTY = Message.raw("");
  // Variable used to workaround a bug in AIX Java 1.6
  // TODO: remove this code once the JDK issue referenced in 3077 is closed.
  private final boolean isAIXPost5 = isAIXPost5();
  /**
   * Creates an uninternationalized message that will render itself
   * the same way regardless of the locale requested in
@@ -180,7 +184,46 @@
    String fmt = descriptor.getFormatString(locale);
    if (descriptor.requiresFormatter()) {
      try {
        s = new Formatter(locale).format(locale, fmt, args).toString();
        // TODO: remove this code once the JDK issue referenced in 3077 is
        // closed.
        if (isAIXPost5)
        {
          // Java 6 in AIX Formatter does not handle properly Formattable
          // arguments; this code is a workaround for the problem.
          boolean changeType = false;
          for (Object o : args)
          {
            if (o instanceof Formattable)
            {
              changeType = true;
              break;
            }
          }
          if (changeType)
          {
            Object[] newArgs = new Object[args.length];
            for (int i=0; i<args.length; i++)
            {
              if (args[i] instanceof Formattable)
              {
                newArgs[i] = args[i].toString();
              }
              else
              {
                newArgs[i] = args[i];
              }
            }
            s = new Formatter(locale).format(locale, fmt, newArgs).toString();
          }
          else
          {
            s = new Formatter(locale).format(locale, fmt, args).toString();
          }
        }
        else
        {
          s = new Formatter(locale).format(locale, fmt, args).toString();
        }
      } catch (IllegalFormatException e) {
        // This should not happend with any of our internal messages.
        // However, this may happen for raw messages that have a
@@ -431,4 +474,27 @@
    return result;
  }
  // TODO: remove this code once the JDK issue referenced in 3077 is closed.
  /**
   * Returns whether we are running post 1.5 on AIX or not.
   * @return <CODE>true</CODE> if we are running post 1.5 on AIX and
   * <CODE>false</CODE> otherwise.
   */
  private boolean isAIXPost5()
  {
    boolean isJDK15 = false;
    try
    {
      String javaRelease = System.getProperty ("java.version");
      isJDK15 = javaRelease.startsWith("1.5");
    }
    catch (Throwable t)
    {
      System.err.println("Cannot get the java version: " + t);
    }
    boolean isAIX = "aix".equalsIgnoreCase(System.getProperty("os.name"));
    return !isJDK15 && isAIX;
  }
}