# HG changeset patch # User scolebourne # Date 1394127067 0 # Node ID 877a047171bbe19c107d581d37d2a6b3d926148f # Parent 83da5b49850433b452229db4a2f31b91f1ee50ad 8036818: DateTimeFormatter withResolverFields() fails to accept null Reviewed-by: chegar, rriggs Contributed-by: scolebourne@joda.org diff -r 83da5b498504 -r 877a047171bb jdk/src/share/classes/java/time/format/DateTimeFormatter.java --- a/jdk/src/share/classes/java/time/format/DateTimeFormatter.java Fri Apr 04 13:01:26 2014 +0200 +++ b/jdk/src/share/classes/java/time/format/DateTimeFormatter.java Thu Mar 06 17:31:07 2014 +0000 @@ -1644,12 +1644,13 @@ * @return a formatter based on this formatter with the requested resolver style, not null */ public DateTimeFormatter withResolverFields(TemporalField... resolverFields) { - Objects.requireNonNull(resolverFields, "resolverFields"); - Set fields = new HashSet<>(Arrays.asList(resolverFields)); + Set fields = null; + if (resolverFields != null) { + fields = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(resolverFields))); + } if (Objects.equals(this.resolverFields, fields)) { return this; } - fields = Collections.unmodifiableSet(fields); return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, fields, chrono, zone); } @@ -1693,11 +1694,12 @@ * @return a formatter based on this formatter with the requested resolver style, not null */ public DateTimeFormatter withResolverFields(Set resolverFields) { - Objects.requireNonNull(resolverFields, "resolverFields"); if (Objects.equals(this.resolverFields, resolverFields)) { return this; } - resolverFields = Collections.unmodifiableSet(new HashSet<>(resolverFields)); + if (resolverFields != null) { + resolverFields = Collections.unmodifiableSet(new HashSet<>(resolverFields)); + } return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, resolverFields, chrono, zone); } diff -r 83da5b498504 -r 877a047171bb jdk/test/java/time/tck/java/time/format/TCKDateTimeFormatter.java --- a/jdk/test/java/time/tck/java/time/format/TCKDateTimeFormatter.java Fri Apr 04 13:01:26 2014 +0200 +++ b/jdk/test/java/time/tck/java/time/format/TCKDateTimeFormatter.java Thu Mar 06 17:31:07 2014 +0000 @@ -254,14 +254,20 @@ assertEquals(parsed.isSupported(YEAR), false); // not in the list of resolverFields } - @Test(expectedExceptions = NullPointerException.class) + @Test public void test_resolverFields_Array_null() throws Exception { - DateTimeFormatter.ISO_DATE.withResolverFields((TemporalField[]) null); + DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR); + assertEquals(f.getResolverFields().size(), 1); + f = f.withResolverFields((TemporalField[]) null); + assertEquals(f.getResolverFields(), null); } - @Test(expectedExceptions = NullPointerException.class) + @Test public void test_resolverFields_Set_null() throws Exception { - DateTimeFormatter.ISO_DATE.withResolverFields((Set) null); + DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR); + assertEquals(f.getResolverFields().size(), 1); + f = f.withResolverFields((Set) null); + assertEquals(f.getResolverFields(), null); } //-----------------------------------------------------------------------