[ http://issues.apache.org/jira/browse/HARMONY-65?page=all ]

Tim Ellison reassigned HARMONY-65:
----------------------------------

    Assign To: Tim Ellison

> java.text.MessageFormat.applyPattern(String pattern) and two MessageFormat 
> constructors fail to detect unmatched braces in the pattern
> --------------------------------------------------------------------------------------------------------------------------------------
>
>          Key: HARMONY-65
>          URL: http://issues.apache.org/jira/browse/HARMONY-65
>      Project: Harmony
>         Type: Bug
>   Components: Classlib
>     Reporter: tatyana doubtsova
>     Assignee: Tim Ellison

>
> Problem details:
> According to j2se 1.4.2 constructors MessageFormat(String pattern),  
> MessageFormat(String pattern, Locale) and method applyPattern(String pattern) 
> should throw IllegalArgumantException, if the pattern is invalid. Harmony 
> implementation doesn't throw IAE, when there are unmatched braces in the 
> pattern
> Code for reproducing Test.java:
> import java.text.*;
> import java.util.Locale;
> public class Test {
>     public static void main(String[] args) throws Exception {
>       MessageFormat mf = new MessageFormat("{0,number,integer}");
>       String badpattern = "{0,number,#";
>       try{
>               mf.applyPattern(badpattern);
>               System.out.println("pattern = " + mf.toPattern());              
>               System.out.println("applyPattern(String) FAILED to detect 
> invalid pattern");
>       } catch (IllegalArgumentException e) {
>               System.out.println(e.getMessage());
>               System.out.println("applyPattern(String) PASSED");
>               System.out.println(e.getMessage());
>       }
>       try {
>               mf = new MessageFormat("{0,number,integer");
>               System.out.println("pattern = " + mf.toPattern());              
>               System.out.println("MessageFormat(String) FAILED to detect 
> invalid pattern");
>       } catch (IllegalArgumentException e) {
>               System.out.println(e.getMessage());
>               System.out.println("MessageFormat(String) PASSED");
>       }
>       try {
>               mf = new MessageFormat("{0,number,integer", Locale.US);
>               System.out.println("pattern = " + mf.toPattern());              
>               System.out.println("MessageFormat(String, Locale) FAILED to 
> detect invalid pattern");
>       } catch (IllegalArgumentException e) {
>               System.out.println(e.getMessage());
>               System.out.println("MessageFormat(String, Locale) PASSED");
>       }
>     }
> }
> 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.
> pattern = {0,number,#}
> applyPattern(String) FAILED to detect invalid pattern
> pattern = {0,number,integer#}
> MessageFormat(String) FAILED to detect invalid pattern
> pattern = {0,number,integer#}
> MessageFormat(String, Locale) FAILED to detect invalid pattern
> Output on BEA 1.4.2 to compare with:
> Unmatched braces in the pattern.
> applyPattern(String) PASSED
> Unmatched braces in the pattern.
> Unmatched braces in the pattern.
> MessageFormat(String) PASSED
> Unmatched braces in the pattern.
> MessageFormat(String, Locale) PASSED
> 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_MessageFormatString() {          
>       try {
>               MessageFormat mf = new MessageFormat("{0,number,integer");
>                       fail("Assert 0: Failed to detect unmatched brackets."); 
>                 
>       } catch (IllegalArgumentException e) {
>       }
>     }
>     
>     public void test_MessageFormatStringLocale() {
>       try {
>               MessageFormat mf = new MessageFormat("{0,number,integer", 
> Locale.US);
>                       fail("Assert 0: Failed to detect unmatched brackets."); 
>                 
>       } catch (IllegalArgumentException e) {
>       }       
>     }
>     public void test_applyPatternString() {
>       MessageFormat mf = new MessageFormat("{0,number,integer}");
>       String badpattern = "{0,number,#";
>       try{
>               mf.applyPattern(badpattern);
>                       fail("Assert 0: Failed to detect unmatched brackets."); 
>                 
>       } catch (IllegalArgumentException 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

Reply via email to