harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Beyer (JIRA)" <j...@apache.org>
Subject [jira] Updated: (HARMONY-59) java.text.MessageFormat.toPattern() causes IndexOutOfBoundsException in StringBuffer.setLength method
Date Tue, 07 Feb 2006 03:40:00 GMT
     [ http://issues.apache.org/jira/browse/HARMONY-59?page=all ]

Nathan Beyer updated HARMONY-59:
--------------------------------

    Attachment: ChoiceFormat_patches.txt
                ChoiceFormatTest.java

The issue is in how the ChoiceFormat.toPattern() was implemented. The method would loop through
all formats and append a '|' character at the end of very loop, then it would decrement the
length of the StringBuffer by one, so as to eliminate the extra OR symbol. This works fine
if there's a format, but in the test case, there wasn't one, the MessageFormat class would
pass an empty string to the ChoiceFormat constructor.

To fix this, I've just move the OR symbol appending to the beginning of the loop and append
it when it's not the first loop and remove the length adjustment. This should resolve the
issue. Addittionally, I've attached a TestCase for ChoiceFormat to verify this functionality
and a bit more.

> java.text.MessageFormat.toPattern() causes IndexOutOfBoundsException in  StringBuffer.setLength
method
> ------------------------------------------------------------------------------------------------------
>
>          Key: HARMONY-59
>          URL: http://issues.apache.org/jira/browse/HARMONY-59
>      Project: Harmony
>         Type: Bug
>   Components: Classlib
>     Reporter: tatyana doubtsova
>  Attachments: ChoiceFormatTest.java, ChoiceFormat_patches.txt
>
> Problem details:
> According to j2se 1.4.2, method toPattern() should return a pattern representing the
current state of the message format. However, Harmony throws IndexOutOfBoundsException for
"CHOICE {1,choice}" message format.
> Code for reproducing Test.java:
> import java.text.*;
> 	public class Test {
> 		public static void main(String[] args) {
> 			MessageFormat mf = new MessageFormat("CHOICE {1,choice}");
> 			String ptrn = mf.toPattern();
> 			System.out.println("ptrn = " + ptrn);
> 	    }
> 	}
> Steps to Reproduce:
> 1. Build Harmony (check-out on 2006-01-30) j2se subset as described in README.txt.
> 2. Compile Test.java using BEA 1.4 javac
> > javac -d . Test.java
> 3. Run java using compatible VM (J9)
> > java -showversion Test
> Output:
> java version 1.4.2 (subset)
> (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable.
> Exception in thread "main" java.lang.IndexOutOfBoundsException
> 	at java.lang.StringBuffer.setLength(StringBuffer.java:810)
> 	at java.text.ChoiceFormat.toPattern(ChoiceFormat.java:386)
> 	at java.text.MessageFormat.toPattern(MessageFormat.java:802)
> 	at Test.main(Test.java:5)
> Output on BEA 1.4.2 to compare with:
> ptrn = CHOICE {1,choice,}
> Suggested junit test case:
> package org.apache.harmony.tests.java.text;
> import java.text.MessageFormat;
> import java.util.Locale;
> import junit.framework.TestCase;
> public class MessageFormatTest extends TestCase {
>     public static void main(String[] args) {
> 	junit.textui.TestRunner.run(MessageFormatTest.class);
>     }
>     public void test_toPattern() {
>         try {
>             MessageFormat mf = new MessageFormat("CHOICE {1,choice}");
>             String ptrn = mf.toPattern();
>         } catch (Exception e) {
> 	    fail("Assert 0: Unexpected exception " + e);			
>         }
>     }   
> }

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


Mime
View raw message