You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/08/17 21:25:40 UTC
svn commit: r432353 - in
/incubator/harmony/enhanced/classlib/trunk/modules/text/src:
main/java/java/text/DateFormat.java
test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java
Author: tellison
Date: Thu Aug 17 12:25:40 2006
New Revision: 432353
URL: http://svn.apache.org/viewvc?rev=432353&view=rev
Log:
Apply modified form of patch for HARMONY-940 ([classlib][text] unexpected MissingResourceException for DateFormat.getDateInstance(<illegal.style>))
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormat.java
incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormat.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormat.java?rev=432353&r1=432352&r2=432353&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormat.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormat.java Thu Aug 17 12:25:40 2006
@@ -300,6 +300,7 @@
* @return a DateFormat
*/
public final static DateFormat getDateInstance(int style) {
+ checkDateStyle(style);
return getDateInstance(style, Locale.getDefault());
}
@@ -314,6 +315,7 @@
* @return a DateFormat
*/
public final static DateFormat getDateInstance(int style, Locale locale) {
+ checkDateStyle(style);
ResourceBundle bundle = getBundle(locale);
String pattern = bundle.getString("Date_" + getStyleName(style));
return new SimpleDateFormat(pattern, locale);
@@ -342,6 +344,8 @@
*/
public final static DateFormat getDateTimeInstance(int dateStyle,
int timeStyle) {
+ checkTimeStyle(timeStyle);
+ checkDateStyle(dateStyle);
return getDateTimeInstance(dateStyle, timeStyle, Locale.getDefault());
}
@@ -359,6 +363,8 @@
*/
public final static DateFormat getDateTimeInstance(int dateStyle,
int timeStyle, Locale locale) {
+ checkTimeStyle(timeStyle);
+ checkDateStyle(dateStyle);
ResourceBundle bundle = getBundle(locale);
String pattern = bundle.getString("Date_" + getStyleName(dateStyle))
+ " " + bundle.getString("Time_" + getStyleName(timeStyle));
@@ -424,6 +430,7 @@
* @return a DateFormat
*/
public final static DateFormat getTimeInstance(int style) {
+ checkTimeStyle(style);
return getTimeInstance(style, Locale.getDefault());
}
@@ -438,6 +445,7 @@
* @return a DateFormat
*/
public final static DateFormat getTimeInstance(int style, Locale locale) {
+ checkTimeStyle(style);
ResourceBundle bundle = getBundle(locale);
String pattern = bundle.getString("Time_" + getStyleName(style));
return new SimpleDateFormat(pattern, locale);
@@ -698,5 +706,14 @@
throw new InvalidObjectException(Msg.getString("K000d"));
}
+ }
+
+ private static void checkDateStyle(int style) {
+ if (!(style == SHORT || style == MEDIUM || style == LONG || style == FULL || style == DEFAULT))
+ throw new IllegalArgumentException("Illegal date style: " + style);
+ }
+ private static void checkTimeStyle(int style) {
+ if (!(style == SHORT || style == MEDIUM || style == LONG || style == FULL || style == DEFAULT))
+ throw new IllegalArgumentException("Illegal time style: " + style);
}
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java?rev=432353&r1=432352&r2=432353&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java Thu Aug 17 12:25:40 2006
@@ -122,6 +122,14 @@
new DateFormatSymbols()));
assertTrue("Doesn't work4",
f2.format(new Date()).getClass() == String.class);
+
+ // regression test for HARMONY-940
+ try {
+ DateFormat.getDateInstance(77);
+ fail("Should throw IAE");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
}
/**
@@ -159,6 +167,14 @@
new DateFormatSymbols(Locale.GERMAN)));
assertTrue("Doesn't work",
f2.format(new Date()).getClass() == String.class);
+
+ // regression test for HARMONY-940
+ try {
+ DateFormat.getDateInstance(77, Locale.GERMAN);
+ fail("Should throw IAE");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
}
/**
@@ -215,6 +231,14 @@
testDateTime(DateFormat.FULL, DateFormat.MEDIUM);
testDateTime(DateFormat.FULL, DateFormat.LONG);
testDateTime(DateFormat.FULL, DateFormat.FULL);
+
+ // regression test for HARMONY-940
+ try {
+ DateFormat.getDateTimeInstance(77, 66);
+ fail("Should throw IAE");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
}
private void testDateTimeLocale(int dStyle, int tStyle) {
@@ -257,6 +281,14 @@
testDateTimeLocale(DateFormat.FULL, DateFormat.MEDIUM);
testDateTimeLocale(DateFormat.FULL, DateFormat.LONG);
testDateTimeLocale(DateFormat.FULL, DateFormat.FULL);
+
+ // regression test for HARMONY-940
+ try {
+ DateFormat.getDateTimeInstance(77, 66, Locale.GERMAN);
+ fail("Should throw IAE");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
}
/**
@@ -337,6 +369,14 @@
new DateFormatSymbols()));
assertTrue("Doesn't work4",
f2.format(new Date()).getClass() == String.class);
+
+ // regression test for HARMONY-940
+ try {
+ DateFormat.getTimeInstance(77);
+ fail("Should throw IAE");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
}
/**
@@ -374,6 +414,14 @@
new DateFormatSymbols(Locale.GERMAN)));
assertTrue("Doesn't work",
f2.format(new Date()).getClass() == String.class);
+
+ // regression test for HARMONY-940
+ try {
+ DateFormat.getTimeInstance(77, Locale.GERMAN);
+ fail("Should throw IAE");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
}
/**