[jbossseam-issues] [JBoss JIRA] Updated: (JBSEAM-726) Log interpolation throws exception when toString() uses braces

Gavin King (JIRA) jira-events at jboss.com
Wed Jan 31 23:00:19 EST 2007


     [ http://jira.jboss.com/jira/browse/JBSEAM-726?page=all ]

Gavin King updated JBSEAM-726:
------------------------------

    Fix Version/s: 1.1.6
                       (was: 1.2.0.BETA1)

> Log interpolation throws exception when toString() uses braces
> --------------------------------------------------------------
>
>                 Key: JBSEAM-726
>                 URL: http://jira.jboss.com/jira/browse/JBSEAM-726
>             Project: JBoss Seam
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.1.1.GA
>            Reporter: Luke Maurer
>             Fix For: 1.1.6
>
>
> For example, if you write:
> Map<String, String> map = new HashMap<String, String>(); // (or any other Map implementation that formats itself similarly)
> map.put("apple", "orange");
> map.put("pear", "banana");
> log.debug("A map: #0", map);
> and debug logging is enabled, you get an IllegalArgumentException saying "can't parse argument number apple=orange,pear=banana". The problem appears to be in Interpolator:
>    public String interpolate(String string, Object... params) {
>    
>    // ...   
>       if ( string.indexOf('#')>=0 )
>       {
>          string = interpolateExpressions(string, params);
>       }
>       if (params.length>0 && string.indexOf('{')>=0 )
>       {
>          string = new MessageFormat(string, Locale.instance()).format(params);
>       }
>       return string;
>    }
> The first if test passes and interpolateExpressions() interpolates the Map object into the string. Since this particular object's toString() method happens to format it using braces (e.g. "{apple=orange,pear=banana}" above), the second if test also passes, and the same parameters get interpolated *again*. When the part of the toString() representation between the braces fails to parse as a MessageFormat argument specifier, the IAE gets thrown.
> My guess is that an "else" is intended before the second "if" above, since it must be rare that one wants the same parameters interpolated twice. Otherwise, either the IAE should be caught and the log message left alone if it doesn't parse as a format string, or the documentation should state clearly that logging an object that represents itself using braces will throw an exception at run time.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list