changeset 8975:fe3383582427

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 23a7524d930c
children 1298e476729c
files src/share/classes/java/time/Duration.java src/share/classes/java/time/Instant.java src/share/classes/java/time/LocalDate.java src/share/classes/java/time/LocalDateTime.java src/share/classes/java/time/LocalTime.java src/share/classes/java/time/MonthDay.java src/share/classes/java/time/OffsetDateTime.java src/share/classes/java/time/OffsetTime.java src/share/classes/java/time/Period.java src/share/classes/java/time/Year.java src/share/classes/java/time/YearMonth.java src/share/classes/java/time/ZoneId.java src/share/classes/java/time/ZoneOffset.java src/share/classes/java/time/ZonedDateTime.java src/share/classes/java/time/chrono/HijrahDate.java src/share/classes/java/time/chrono/JapaneseDate.java src/share/classes/java/time/chrono/MinguoDate.java src/share/classes/java/time/chrono/ThaiBuddhistDate.java test/java/time/tck/java/time/TCKLocalDateTime.java
diffstat 19 files changed, 129 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/time/Duration.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/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/src/share/classes/java/time/Instant.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/Instant.java	Wed Dec 11 16:52:41 2013 -0500
@@ -196,6 +196,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/src/share/classes/java/time/LocalDate.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/LocalDate.java	Wed Dec 11 16:52:41 2013 -0500
@@ -121,6 +121,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/src/share/classes/java/time/LocalDateTime.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/LocalDateTime.java	Wed Dec 11 16:52:41 2013 -0500
@@ -119,6 +119,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/src/share/classes/java/time/LocalTime.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/LocalTime.java	Wed Dec 11 16:52:41 2013 -0500
@@ -109,6 +109,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/src/share/classes/java/time/MonthDay.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/MonthDay.java	Wed Dec 11 16:52:41 2013 -0500
@@ -111,6 +111,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/src/share/classes/java/time/OffsetDateTime.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/OffsetDateTime.java	Wed Dec 11 16:52:41 2013 -0500
@@ -112,6 +112,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/src/share/classes/java/time/OffsetTime.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/OffsetTime.java	Wed Dec 11 16:52:41 2013 -0500
@@ -102,6 +102,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/src/share/classes/java/time/Period.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/Period.java	Wed Dec 11 16:52:41 2013 -0500
@@ -119,6 +119,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/src/share/classes/java/time/Year.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/Year.java	Wed Dec 11 16:52:41 2013 -0500
@@ -119,6 +119,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/src/share/classes/java/time/YearMonth.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/YearMonth.java	Wed Dec 11 16:52:41 2013 -0500
@@ -115,6 +115,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/src/share/classes/java/time/ZoneId.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/ZoneId.java	Wed Dec 11 16:52:41 2013 -0500
@@ -159,6 +159,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/src/share/classes/java/time/ZoneOffset.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/ZoneOffset.java	Wed Dec 11 16:52:41 2013 -0500
@@ -114,6 +114,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/src/share/classes/java/time/ZonedDateTime.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/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/src/share/classes/java/time/chrono/HijrahDate.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/chrono/HijrahDate.java	Wed Dec 11 16:52:41 2013 -0500
@@ -102,6 +102,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/src/share/classes/java/time/chrono/JapaneseDate.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/chrono/JapaneseDate.java	Wed Dec 11 16:52:41 2013 -0500
@@ -110,6 +110,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/src/share/classes/java/time/chrono/MinguoDate.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/chrono/MinguoDate.java	Wed Dec 11 16:52:41 2013 -0500
@@ -90,6 +90,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/src/share/classes/java/time/chrono/ThaiBuddhistDate.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/src/share/classes/java/time/chrono/ThaiBuddhistDate.java	Wed Dec 11 16:52:41 2013 -0500
@@ -90,6 +90,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/test/java/time/tck/java/time/TCKLocalDateTime.java	Mon Dec 09 15:01:24 2013 -0800
+++ b/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);
             }