diff options
author | Elliott Hughes <enh@google.com> | 2009-10-08 16:56:37 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2009-10-08 17:40:12 -0700 |
commit | fe1eba10c5d69e115dfab55d82cc22d42e9fbae5 (patch) | |
tree | 0b230913d22f49ce92451cb18a6e58636b36f97d | |
parent | d383e2a5ddeb291769b0e59d47c5e8ff205c1f2c (diff) | |
download | libcore-fe1eba10c5d69e115dfab55d82cc22d42e9fbae5.zip libcore-fe1eba10c5d69e115dfab55d82cc22d42e9fbae5.tar.gz libcore-fe1eba10c5d69e115dfab55d82cc22d42e9fbae5.tar.bz2 |
Squashed commit of the following:
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
8 files changed, 39 insertions, 46 deletions
diff --git a/text/src/main/java/java/text/BreakIterator.java b/text/src/main/java/java/text/BreakIterator.java index 7d19179..3a08427 100644 --- a/text/src/main/java/java/text/BreakIterator.java +++ b/text/src/main/java/java/text/BreakIterator.java @@ -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++) { diff --git a/text/src/main/java/java/text/Collator.java b/text/src/main/java/java/text/Collator.java index aaa3e12..71ebb94 100644 --- a/text/src/main/java/java/text/Collator.java +++ b/text/src/main/java/java/text/Collator.java @@ -22,12 +22,11 @@ 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); diff --git a/text/src/main/java/java/text/DateFormat.java b/text/src/main/java/java/text/DateFormat.java index f39965a..531bed8 100644 --- a/text/src/main/java/java/text/DateFormat.java +++ b/text/src/main/java/java/text/DateFormat.java @@ -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$ diff --git a/text/src/main/java/java/text/Format.java b/text/src/main/java/java/text/Format.java index 6ee1ba2..3a6e49d 100644 --- a/text/src/main/java/java/text/Format.java +++ b/text/src/main/java/java/text/Format.java @@ -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; } diff --git a/text/src/main/java/java/text/MessageFormat.java b/text/src/main/java/java/text/MessageFormat.java index 4ab1ade..f6074b2 100644 --- a/text/src/main/java/java/text/MessageFormat.java +++ b/text/src/main/java/java/text/MessageFormat.java @@ -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; } diff --git a/text/src/main/java/java/text/NumberFormat.java b/text/src/main/java/java/text/NumberFormat.java index 5b8d883..87f17c1 100644 --- a/text/src/main/java/java/text/NumberFormat.java +++ b/text/src/main/java/java/text/NumberFormat.java @@ -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; } diff --git a/text/src/main/java/org/apache/harmony/text/internal/nls/messages.properties b/text/src/main/java/org/apache/harmony/text/internal/nls/messages.properties index 22221a9..b80cde2 100644 --- a/text/src/main/java/org/apache/harmony/text/internal/nls/messages.properties +++ b/text/src/main/java/org/apache/harmony/text/internal/nls/messages.properties @@ -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} diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java index 1c2da6a..3bcc38c 100644 --- a/text/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java +++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java @@ -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() { - } } |