OSDN Git Service

Squashed commit of the following:
authorElliott Hughes <enh@google.com>
Thu, 8 Oct 2009 23:56:37 +0000 (16:56 -0700)
committerElliott Hughes <enh@google.com>
Fri, 9 Oct 2009 00:40:12 +0000 (17:40 -0700)
commit 07d78447c89a11265bf909ab6bcc315c1a784281
Author: Elliott Hughes <enh@google.com>
Date:   Thu Oct 8 16:38:26 2009 -0700

    text_dalvik

commit c390506ce060c705b6c1b04fb1e737617de1bd8a
Author: Elliott Hughes <enh@google.com>
Date:   Thu Oct 8 16:38:22 2009 -0700

    text_802921

libcore/text/src/main/java/java/text/BreakIterator.java
libcore/text/src/main/java/java/text/Collator.java
libcore/text/src/main/java/java/text/DateFormat.java
libcore/text/src/main/java/java/text/Format.java
libcore/text/src/main/java/java/text/MessageFormat.java
libcore/text/src/main/java/java/text/NumberFormat.java
libcore/text/src/main/java/org/apache/harmony/text/internal/nls/messages.properties
libcore/text/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java

index 7d19179..3a08427 100644 (file)
@@ -23,6 +23,8 @@ package java.text;
 
 import java.util.Locale;
 
+import org.apache.harmony.text.internal.nls.Messages;
+
 /**
  * Locates boundaries in text. This class defines a protocol for objects that
  * break up a piece of natural-language text according to a set of criteria.
@@ -542,11 +544,10 @@ public abstract class BreakIterator implements Cloneable {
      *             greater than the length of {@code buf}.
      */
     protected static long getLong(byte[] buf, int offset) {
-        if (null == buf) {
-            throw new NullPointerException();
-        }
-        if (offset < 0 || buf.length - offset < LONG_LENGTH) {
-            throw new ArrayIndexOutOfBoundsException();
+        // Force a buf null check first!
+        if (buf.length - offset < LONG_LENGTH || offset < 0) {
+            // text.1E=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Messages.getString("text.1E", offset)); //$NON-NLS-1$
         }
         long result = 0;
         for (int i = offset; i < offset + LONG_LENGTH; i++) {
@@ -571,11 +572,10 @@ public abstract class BreakIterator implements Cloneable {
      *             greater than the length of {@code buf}.
      */
     protected static int getInt(byte[] buf, int offset) {
-        if (null == buf) {
-            throw new NullPointerException();
-        }
-        if (offset < 0 || buf.length - INT_LENGTH < offset) {
-            throw new ArrayIndexOutOfBoundsException();
+        // Force buf null check first!
+        if (buf.length - INT_LENGTH < offset || offset < 0) {
+            // text.1E=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Messages.getString("text.1E", offset)); //$NON-NLS-1$
         }
         int result = 0;
         for (int i = offset; i < offset + INT_LENGTH; i++) {
@@ -600,11 +600,10 @@ public abstract class BreakIterator implements Cloneable {
      *             greater than the length of {@code buf}.
      */
     protected static short getShort(byte[] buf, int offset) {
-        if (null == buf) {
-            throw new NullPointerException();
-        }
-        if (offset < 0 || buf.length - SHORT_LENGTH < offset) {
-            throw new ArrayIndexOutOfBoundsException();
+        // Force buf null check first!
+        if (buf.length - SHORT_LENGTH < offset || offset < 0) {
+            // text.1E=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Messages.getString("text.1E", offset)); //$NON-NLS-1$
         }
         short result = 0;
         for (int i = offset; i < offset + SHORT_LENGTH; i++) {
index aaa3e12..71ebb94 100644 (file)
 package java.text;
 
 import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Comparator;
 import java.util.Locale;
 import java.util.Vector;
 
-import org.apache.harmony.luni.util.PriviAction;
-
 /**
  * Performs locale-sensitive string comparison. A concrete subclass,
  * {@link RuleBasedCollator}, allows customization of the collation ordering by
@@ -163,7 +162,11 @@ public abstract class Collator implements Comparator<Object>, Cloneable {
     static {
         // CACHE_SIZE includes key and value, so needs to be double
         String cacheSize = AccessController
-                .doPrivileged(new PriviAction<String>("collator.cache")); //$NON-NLS-1$
+                .doPrivileged(new PrivilegedAction<String>() {
+                    public String run() {
+                        return System.getProperty("collator.cache"); //$NON-NLS-1$
+                    }
+                });
         if (cacheSize != null) {
             try {
                 CACHE_SIZE = Integer.parseInt(cacheSize);
index f39965a..531bed8 100644 (file)
@@ -666,7 +666,7 @@ public abstract class DateFormat extends Format {
     public Date parse(String string) throws ParseException {
         ParsePosition position = new ParsePosition(0);
         Date date = parse(string, position);
-        if (position.getErrorIndex() != -1 || position.getIndex() == 0) {
+        if (position.getIndex() == 0) {
             // text.19=Unparseable date: {0}
             throw new ParseException(
                     Messages.getString("text.19", string), position.getErrorIndex()); //$NON-NLS-1$
index 6ee1ba2..3a6e49d 100644 (file)
@@ -202,8 +202,10 @@ public abstract class Format implements Serializable, Cloneable {
     public Object parseObject(String string) throws ParseException {
         ParsePosition position = new ParsePosition(0);
         Object result = parseObject(string, position);
-        if (position.getErrorIndex() != -1 || position.getIndex() == 0) {
-            throw new ParseException(null, position.getErrorIndex());
+        if (position.getIndex() == 0) {
+            // text.1C=Format.parseObject(String) parse failure
+            throw new ParseException(
+                    Messages.getString("text.1C"), position.getErrorIndex()); //$NON-NLS-1$
         }
         return result;
     }
index 4ab1ade..f6074b2 100644 (file)
@@ -859,8 +859,10 @@ public class MessageFormat extends Format {
     public Object[] parse(String string) throws ParseException {
         ParsePosition position = new ParsePosition(0);
         Object[] result = parse(string, position);
-        if (position.getErrorIndex() != -1 || position.getIndex() == 0) {
-            throw new ParseException(null, position.getErrorIndex());
+        if (position.getIndex() == 0) {
+            // text.1B=MessageFormat.parseObject(String) parse failure
+            throw new ParseException(
+                    Messages.getString("text.1B"), position.getErrorIndex()); //$NON-NLS-1$
         }
         return result;
     }
index 5b8d883..87f17c1 100644 (file)
@@ -555,8 +555,10 @@ public abstract class NumberFormat extends Format {
     public Number parse(String string) throws ParseException {
         ParsePosition pos = new ParsePosition(0);
         Number number = parse(string, pos);
-        if (pos.getErrorIndex() != -1 || pos.getIndex() == 0) {
-            throw new ParseException(null, pos.getErrorIndex());
+        if (pos.getIndex() == 0) {
+            // text.1D=Unparseable number: {0}
+            throw new ParseException(
+                    Messages.getString("text.1D", string), pos.getErrorIndex()); //$NON-NLS-1$
         }
         return number;
     }
index 22221a9..b80cde2 100644 (file)
@@ -43,4 +43,7 @@ text.17=Unknown format
 text.18=Not a valid {0}, subclass should override readResolve()
 text.19=Unparseable date: {0}
 text.1A=position is null
-
+text.1B=MessageFormat.parseObject(String) parse failure
+text.1C=Format.parseObject(String) parse failure
+text.1D=Unparseable number: {0}
+text.1E=Offset out of bounds \: {0}
index 1c2da6a..3bcc38c 100644 (file)
@@ -37,15 +37,13 @@ public class ParseExceptionTest extends junit.framework.TestCase {
         args = {java.lang.String.class, int.class}
     )
     public void test_ConstructorLjava_lang_StringI() {
-        // Test for method java.text.ParseException(java.lang.String, int)
-        // SM
         try {
             DateFormat df = DateFormat.getInstance();
             df.parse("HelloWorld");
+            fail("ParseException not created/thrown.");
         } catch (ParseException e) {
-            return;
+            // expected
         }
-        fail("ParseException not created/thrown.");
     }
 
     /**
@@ -58,8 +56,6 @@ public class ParseExceptionTest extends junit.framework.TestCase {
         args = {}
     )
     public void test_getErrorOffset() {
-        // Test for method int java.text.ParseException.getErrorOffset()
-        // SM
         try {
             DateFormat df = DateFormat.getInstance();
             df.parse("1999HelloWorld");
@@ -67,18 +63,4 @@ public class ParseExceptionTest extends junit.framework.TestCase {
             assertEquals("getErrorOffsetFailed.", 4, e.getErrorOffset());
         }
     }
-
-    /**
-     * Sets up the fixture, for example, open a network connection. This method
-     * is called before a test is executed.
-     */
-    protected void setUp() {
-    }
-
-    /**
-     * Tears down the fixture, for example, close a network connection. This
-     * method is called after a test is executed.
-     */
-    protected void tearDown() {
-    }
 }