Uploaded image for project: 'Velocity Tools'
  1. Velocity Tools
  2. VELTOOLS-104

MessageFormat.format() not invoked in ResourceTool.render() if there are no arguments



    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.4, 2.0, 2.x
    • 2.0, 2.x, 3.0
    • GenericTools
    • None


      render() currently looks like this:

      public String render(Object resource, Object[] args)
      String value = String.valueOf(resource);
      if (args == null)

      { return value; }

      return MessageFormat.format(value, args);

      Unfortunately, if you're using MessageFormat-ready messages then you should be format()ting even strings with no arguments, even if this seems like an inefficiency.

      We use many strings that are used on their own, or as part of other messages, sometimes they have arguments and sometimes they don't. This creates a sticky situation if you have to use MessageFormat escaping for some messages and not others. For example:

      message1=ResourceTool's problem
      message2=$(message1) is


      where "$(message1)" is a substitution for message1 (which our ResourceBundle does for us). ResourceTool renders the first message fine but the second message with an argument doesn't render properly due to the unescaped ' passed to MessageFormat. Even without the special message substitution render() causes problems because the escaping rules are different depending on the message context.

      The messages should actually be:

      message1=ResourceTool''s problem
      message2=$(message1) is {0}

      to be consistent with MessageFormat's rules across all messages. Unfortunately ResourceTool can't handle this because it doesn't pass a no-argument resource to MessageFormat.

      I'm using a subclass of ResourceTool that doesn't have the shortcut:

      public String render(Object resource, Object[] args)

      { return MessageFormat.format(String.valueOf(resource), args); }

      So all my messages have the same escaping rules.




            Unassigned Unassigned
            rvagg Rod
            0 Vote for this issue
            0 Start watching this issue