harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r378567 - in /incubator/harmony/enhanced/classlib/trunk/modules/text/src: main/java/java/text/Format.java main/java/java/text/MessageFormat.java test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
Date Fri, 17 Feb 2006 16:49:03 GMT
Author: tellison
Date: Fri Feb 17 08:49:02 2006
New Revision: 378567

URL: http://svn.apache.org/viewcvs?rev=378567&view=rev
Log:
Fix for HARMONY-65 (java.text.MessageFormat.applyPattern(String pattern) and two MessageFormat
constructors fail to detect unmatched braces in the pattern)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Format.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/MessageFormat.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Format.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Format.java?rev=378567&r1=378566&r2=378567&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Format.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Format.java
Fri Feb 17 08:49:02 2006
@@ -222,8 +222,8 @@
 			}
 			buffer.append(ch);
 		}
-		position.setIndex(index);
-		return false;
+		// Unmatched braces in the pattern
+		throw new IllegalArgumentException(Msg.getString("K0346"));
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/MessageFormat.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/MessageFormat.java?rev=378567&r1=378566&r2=378567&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/MessageFormat.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/MessageFormat.java
Fri Feb 17 08:49:02 2006
@@ -199,6 +199,9 @@
 	 *                by this Format
 	 */
 	public AttributedCharacterIterator formatToCharacterIterator(Object object) {
+		if (object == null)
+			throw new NullPointerException();
+
 		StringBuffer buffer = new StringBuffer();
 		Vector fields = new Vector();
 
@@ -532,7 +535,7 @@
 			return new Object[0];
 		ParsePosition internalPos = new ParsePosition(0);
 		int offset = position.getIndex();
-		Object[] result = new Object[maxOffset + 1];
+		Object[] result = new Object[maxArgumentIndex + 1];
 		for (int i = 0; i <= maxOffset; i++) {
 			String sub = strings[i];
 			if (!string.startsWith(sub, offset)) {
@@ -688,7 +691,11 @@
 			return NumberFormat.getIntegerInstance(locale);
 		}
 		// choice
-		Format.upToWithQuotes(string, position, buffer, '}', '{');
+		try {
+			Format.upToWithQuotes(string, position, buffer, '}', '{');
+		} catch (IllegalArgumentException e) {
+			// ignored
+		}
 		return new ChoiceFormat(buffer.toString());
 	}
 
@@ -711,7 +718,11 @@
 	 *            an array of Format
 	 */
 	public void setFormats(Format[] formats) {
-		this.formats = (Format[]) formats.clone();
+		int min = this.formats.length;
+		if (formats.length < min)
+			min = formats.length;
+		for (int i=0; i<min; i++)
+			this.formats[i] = formats[i];
 	}
 
 	/**
@@ -927,14 +938,21 @@
 		}
 
 		/**
-		 * serizalization method resolve instances to the constant
+		 * serialization method resolve instances to the constant
 		 * MessageFormat.Field values
 		 */
 		protected Object readResolve() throws InvalidObjectException {
-			if (this.equals(ARGUMENT))
+			String name = this.getName();
+			if (name == null)
+				// "Not a valid {0}, subclass should override readResolve()"
+				throw new InvalidObjectException(
+						Msg.getString("K0344", "MessageFormat.Field"));
+
+			if (name.equals(ARGUMENT.getName()))
 				return ARGUMENT;
-			throw new InvalidObjectException(Msg
-					.getString("K000d"));
+
+			throw new InvalidObjectException(
+					Msg.getString("K0344", "MessageFormat.Field"));
 		}
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java?rev=378567&r1=378566&r2=378567&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
Fri Feb 17 08:49:02 2006
@@ -24,6 +24,47 @@
 public class MessageFormatTest extends TestCase {
 
 	/**
+	 * @tests java.text.MessageFormat(java.util.Locale)
+	 */
+	public void test_ConstructorLjava_util_Locale() {
+		// Regression for HARMONY-65
+		try {
+			new MessageFormat("{0,number,integer", Locale.US);
+			fail("Assert 0: Failed to detect unmatched brackets.");
+		} catch (IllegalArgumentException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.text.MessageFormat(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Regression for HARMONY-65
+		try {
+			new MessageFormat("{0,number,integer");
+			fail("Assert 0: Failed to detect unmatched brackets.");
+		} catch (IllegalArgumentException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.text.MessageFormat#applyPattern(java.lang.String)
+	 */
+    public void test_applyPatternLjava_lang_String() {
+		// Regression for HARMONY-65
+		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) {
+			// expected
+		}
+	} 
+
+	/**
 	 * @tests java.text.MessageFormat#parse(java.lang.String)
 	 */
 	public void test_parse() throws ParseException {



Mime
View raw message