Index: trunk/modules/text/src/main/java/java/text/DateFormat.java =================================================================== --- trunk/modules/text/src/main/java/java/text/DateFormat.java (revision 424155) +++ trunk/modules/text/src/main/java/java/text/DateFormat.java (working copy) @@ -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); @@ -699,4 +707,13 @@ 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); + } } Index: trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java =================================================================== --- trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java (revision 424155) +++ trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java (working copy) @@ -122,6 +122,13 @@ new DateFormatSymbols())); assertTrue("Doesn't work4", f2.format(new Date()).getClass() == String.class); + + // regression test for HARMONY-940 + try { + DateFormat.getDateInstance(77); + } catch (IllegalArgumentException iae) { + //expected + } } /** @@ -159,6 +166,13 @@ 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); + } catch (IllegalArgumentException iae) { + //expected + } } /** @@ -215,6 +229,13 @@ 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); + } catch (IllegalArgumentException iae) { + //expected + } } private void testDateTimeLocale(int dStyle, int tStyle) { @@ -257,6 +278,13 @@ 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); + } catch (IllegalArgumentException iae) { + //expected + } } /** @@ -337,6 +365,13 @@ new DateFormatSymbols())); assertTrue("Doesn't work4", f2.format(new Date()).getClass() == String.class); + + // regression test for HARMONY-940 + try { + DateFormat.getTimeInstance(77); + } catch (IllegalArgumentException iae) { + //expected + } } /** @@ -374,6 +409,13 @@ 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); + } catch (IllegalArgumentException iae) { + //expected + } } /**