Created
March 6, 2014 17:39
-
-
Save jodastephen/9395197 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HG changeset patch | |
# User scolebourne | |
# Date 1394127067 0 | |
# Node ID c307f1e300d9d9d620ff17ec22437fc7d4b63592 | |
# Parent 5fa8324688fe78e43799053eab88e3e643e1d34b | |
JDK-8036818 - DateTimeFormatter withResolverFields() fails to accept null | |
diff --git a/src/share/classes/java/time/format/DateTimeFormatter.java b/src/share/classes/java/time/format/DateTimeFormatter.java | |
--- a/src/share/classes/java/time/format/DateTimeFormatter.java | |
+++ b/src/share/classes/java/time/format/DateTimeFormatter.java | |
@@ -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<TemporalField> fields = new HashSet<>(Arrays.asList(resolverFields)); | |
+ Set<TemporalField> 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<TemporalField> 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 --git a/test/java/time/tck/java/time/format/TCKDateTimeFormatter.java b/test/java/time/tck/java/time/format/TCKDateTimeFormatter.java | |
--- a/test/java/time/tck/java/time/format/TCKDateTimeFormatter.java | |
+++ b/test/java/time/tck/java/time/format/TCKDateTimeFormatter.java | |
@@ -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<TemporalField>) null); | |
+ DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR); | |
+ assertEquals(f.getResolverFields().size(), 1); | |
+ f = f.withResolverFields((Set<TemporalField>) null); | |
+ assertEquals(f.getResolverFields(), null); | |
} | |
//----------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment