changeset 22108:99859c0e9a33

8029551: Add value-type notice to java.time classes Summary: Add warning about identity of value types and reference to ValueBased.html Reviewed-by: briangoetz, smarks, scolebourne
author rriggs
date Wed, 11 Dec 2013 16:52:41 -0500
parents 3e6b0718041e
children 94e298e5a08b
files jdk/src/share/classes/java/time/Duration.java jdk/src/share/classes/java/time/Instant.java jdk/src/share/classes/java/time/LocalDate.java jdk/src/share/classes/java/time/LocalDateTime.java jdk/src/share/classes/java/time/LocalTime.java jdk/src/share/classes/java/time/MonthDay.java jdk/src/share/classes/java/time/OffsetDateTime.java jdk/src/share/classes/java/time/OffsetTime.java jdk/src/share/classes/java/time/Period.java jdk/src/share/classes/java/time/Year.java jdk/src/share/classes/java/time/YearMonth.java jdk/src/share/classes/java/time/ZoneId.java jdk/src/share/classes/java/time/ZoneOffset.java jdk/src/share/classes/java/time/ZonedDateTime.java jdk/src/share/classes/java/time/chrono/HijrahDate.java jdk/src/share/classes/java/time/chrono/JapaneseDate.java jdk/src/share/classes/java/time/chrono/MinguoDate.java jdk/src/share/classes/java/time/chrono/ThaiBuddhistDate.java jdk/test/java/time/tck/java/time/TCKLocalDateTime.java
diffstat 19 files changed, 129 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/share/classes/java/time/Duration.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/Duration.java	Wed Dec 11 16:52:41 2013 -0500
@@ -118,6 +118,13 @@
  * most applications.
  * See {@link Instant} for a discussion as to the meaning of the second and time-scales.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code Duration} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/Instant.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/Instant.java	Wed Dec 11 16:52:41 2013 -0500
@@ -197,6 +197,13 @@
  * This includes {@code Instant}, {@code LocalDate}, {@code LocalTime}, {@code OffsetDateTime},
  * {@code ZonedDateTime} and {@code Duration}.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code Instant} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/LocalDate.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/LocalDate.java	Wed Dec 11 16:52:41 2013 -0500
@@ -122,6 +122,13 @@
  * However, any application that makes use of historical dates, and requires them
  * to be accurate will find the ISO-8601 approach unsuitable.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code LocalDate} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/LocalDateTime.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/LocalDateTime.java	Wed Dec 11 16:52:41 2013 -0500
@@ -120,6 +120,13 @@
  * However, any application that makes use of historical dates, and requires them
  * to be accurate will find the ISO-8601 approach unsuitable.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code LocalDateTime} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/LocalTime.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/LocalTime.java	Wed Dec 11 16:52:41 2013 -0500
@@ -110,6 +110,13 @@
  * in most of the world. This API assumes that all calendar systems use the same
  * representation, this class, for time-of-day.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code LocalTime} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/MonthDay.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/MonthDay.java	Wed Dec 11 16:52:41 2013 -0500
@@ -112,6 +112,13 @@
  * However, any application that makes use of historical dates, and requires them
  * to be accurate will find the ISO-8601 approach unsuitable.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code MonthDay} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/OffsetDateTime.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/OffsetDateTime.java	Wed Dec 11 16:52:41 2013 -0500
@@ -113,6 +113,13 @@
  * in simpler applications. This class may be used when modeling date-time concepts in
  * more detail, or when communicating to a database or in a network protocol.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code OffsetDateTime} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/OffsetTime.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/OffsetTime.java	Wed Dec 11 16:52:41 2013 -0500
@@ -103,6 +103,13 @@
  * For example, the value "13:45.30.123456789+02:00" can be stored
  * in an {@code OffsetTime}.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code OffsetTime} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/Period.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/Period.java	Wed Dec 11 16:52:41 2013 -0500
@@ -120,6 +120,13 @@
  * The period is modeled as a directed amount of time, meaning that individual parts of the
  * period may be negative.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code Period} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/Year.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/Year.java	Wed Dec 11 16:52:41 2013 -0500
@@ -120,6 +120,13 @@
  * However, any application that makes use of historical dates, and requires them
  * to be accurate will find the ISO-8601 approach unsuitable.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code Year} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/YearMonth.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/YearMonth.java	Wed Dec 11 16:52:41 2013 -0500
@@ -116,6 +116,13 @@
  * However, any application that makes use of historical dates, and requires them
  * to be accurate will find the ISO-8601 approach unsuitable.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code YearMonth} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/ZoneId.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/ZoneId.java	Wed Dec 11 16:52:41 2013 -0500
@@ -160,6 +160,13 @@
  * This approach is designed to allow a {@link ZonedDateTime} to be loaded and
  * queried, but not modified, on a Java Runtime with incomplete time-zone information.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code ZoneId} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This abstract class has two implementations, both of which are immutable and thread-safe.
  * One implementation models region-based IDs, the other is {@code ZoneOffset} modelling
--- a/jdk/src/share/classes/java/time/ZoneOffset.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/ZoneOffset.java	Wed Dec 11 16:52:41 2013 -0500
@@ -115,6 +115,13 @@
  * Implementations may choose to cache certain common offsets, however
  * applications must not rely on such caching.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code ZoneOffset} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/ZonedDateTime.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/ZonedDateTime.java	Wed Dec 11 16:52:41 2013 -0500
@@ -142,6 +142,13 @@
  * a vital, but secondary, piece of information, used to ensure that the class
  * represents an instant, especially during a daylight savings overlap.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code ZonedDateTime} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * A {@code ZonedDateTime} holds state equivalent to three separate objects,
  * a {@code LocalDateTime}, a {@code ZoneId} and the resolved {@code ZoneOffset}.
--- a/jdk/src/share/classes/java/time/chrono/HijrahDate.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/chrono/HijrahDate.java	Wed Dec 11 16:52:41 2013 -0500
@@ -103,6 +103,14 @@
  * to create new HijrahDate instances.
  * Alternatively, the {@link #withVariant} method can be used to convert
  * to a new HijrahChronology.
+ *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code HijrahDate} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/chrono/JapaneseDate.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/chrono/JapaneseDate.java	Wed Dec 11 16:52:41 2013 -0500
@@ -111,6 +111,13 @@
  * Calling {@code japaneseDate.get(ERA)} will return 2, corresponding to
  * {@code JapaneseChronology.ERA_HEISEI}.<br>
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code JapaneseDate} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/chrono/MinguoDate.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/chrono/MinguoDate.java	Wed Dec 11 16:52:41 2013 -0500
@@ -91,6 +91,13 @@
  * This calendar system is primarily used in the Republic of China, often known as Taiwan.
  * Dates are aligned such that {@code 0001-01-01 (Minguo)} is {@code 1912-01-01 (ISO)}.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code MinguoDate} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/src/share/classes/java/time/chrono/ThaiBuddhistDate.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/src/share/classes/java/time/chrono/ThaiBuddhistDate.java	Wed Dec 11 16:52:41 2013 -0500
@@ -91,6 +91,13 @@
  * This calendar system is primarily used in Thailand.
  * Dates are aligned such that {@code 2484-01-01 (Buddhist)} is {@code 1941-01-01 (ISO)}.
  *
+ * <p>
+ * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
+ * class; use of identity-sensitive operations (including reference equality
+ * ({@code ==}), identity hash code, or synchronization) on instances of
+ * {@code ThaiBuddhistDate} may have unpredictable results and should be avoided.
+ * The {@code equals} method should be used for comparisons.
+ *
  * @implSpec
  * This class is immutable and thread-safe.
  *
--- a/jdk/test/java/time/tck/java/time/TCKLocalDateTime.java	Mon Jan 06 13:20:06 2014 -0800
+++ b/jdk/test/java/time/tck/java/time/TCKLocalDateTime.java	Wed Dec 11 16:52:41 2013 -0500
@@ -1847,7 +1847,7 @@
             LocalDateTime dt = base.plusMinutes(i);
             t = t.plusMinutes(1);
 
-            if (t == LocalTime.MIDNIGHT) {
+            if (t.equals(LocalTime.MIDNIGHT)) {
                 d = d.plusDays(1);
             }
 
@@ -2539,7 +2539,7 @@
             LocalDateTime dt = base.minusMinutes(i);
             t = t.plusMinutes(1);
 
-            if (t == LocalTime.MIDNIGHT) {
+            if (t.equals(LocalTime.MIDNIGHT)) {
                 d = d.plusDays(1);
             }