You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gh...@apache.org on 2006/06/30 14:43:09 UTC

svn commit: r418249 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Formatter.java test/java/tests/api/java/util/FormatterTest.java

Author: gharley
Date: Fri Jun 30 05:43:08 2006
New Revision: 418249

URL: http://svn.apache.org/viewvc?rev=418249&view=rev
Log:
HARMONY 706 : java.util.Formatter does not validate code point when formatter number using "%c"

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Formatter.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/FormatterTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Formatter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Formatter.java?rev=418249&r1=418248&r2=418249&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Formatter.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Formatter.java Fri Jun 30 05:43:08 2006
@@ -993,18 +993,23 @@
                     result.append(arg);
                 } else if (arg instanceof Byte) {
                     byte b = ((Byte) arg).byteValue();
+                    if(!Character.isValidCodePoint(b)){
+                        throw new IllegalFormatCodePointException(b);
+                    }
                     result.append((char) b);
                 } else if (arg instanceof Short) {
                     short s = ((Short) arg).shortValue();
+                    if (!Character.isValidCodePoint(s)) {
+                        throw new IllegalFormatCodePointException(s);
+                    }
                     result.append((char) s);
                 } else if (arg instanceof Integer) {
                     int codePoint = ((Integer) arg).intValue();
-                    try {
-                        result.append(String.valueOf(Character
-                                .toChars(codePoint)));
-                    } catch (IllegalArgumentException e) {
+                    if (!Character.isValidCodePoint(codePoint)) {
                         throw new IllegalFormatCodePointException(codePoint);
                     }
+                        result.append(String.valueOf(Character
+                                .toChars(codePoint)));
                 } else {
                     // argument of other class is not acceptable.
                     throw new IllegalFormatConversionException(formatToken

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/FormatterTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/FormatterTest.java?rev=418249&r1=418248&r2=418249&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/FormatterTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/FormatterTest.java Fri Jun 30 05:43:08 2006
@@ -1412,6 +1412,31 @@
                 // expected
             }
         }
+        
+        // Regression test
+        f = new Formatter();
+        try {
+            f.format("%c", (byte)-0x0001);
+            fail("Should throw IllegalFormatCodePointException");
+        } catch (IllegalFormatCodePointException e) {
+            // expected
+        }
+        
+        f = new Formatter();
+        try {
+            f.format("%c", (short)-0x0001);
+            fail("Should throw IllegalFormatCodePointException");
+        } catch (IllegalFormatCodePointException e) {
+            // expected
+        }
+        
+        f = new Formatter();
+        try {
+            f.format("%c", -0x0001);
+            fail("Should throw IllegalFormatCodePointException");
+        } catch (IllegalFormatCodePointException e) {
+            // expected
+        }
     }
 
     /**