# HG changeset patch # User rriggs # Date 1386798761 18000 # Node ID 99859c0e9a339b7a6792977221d1fe50e879fccf # Parent 3e6b0718041e5ff27faa882a860ec2027e0d0021 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 diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/Duration.java --- 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. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/Instant.java --- 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}. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/LocalDate.java --- 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. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/LocalDateTime.java --- 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. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/LocalTime.java --- 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. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/MonthDay.java --- 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. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/OffsetDateTime.java --- 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. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/OffsetTime.java --- 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}. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/Period.java --- 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. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/Year.java --- 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. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/YearMonth.java --- 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. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/ZoneId.java --- 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. * + *

+ * This is a value-based + * 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 diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/ZoneOffset.java --- 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. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/ZonedDateTime.java --- 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. * + *

+ * This is a value-based + * 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}. diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/chrono/HijrahDate.java --- 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. + * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/chrono/JapaneseDate.java --- 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}.
* + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/chrono/MinguoDate.java --- 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)}. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/src/share/classes/java/time/chrono/ThaiBuddhistDate.java --- 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)}. * + *

+ * This is a value-based + * 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. * diff -r 3e6b0718041e -r 99859c0e9a33 jdk/test/java/time/tck/java/time/TCKLocalDateTime.java --- 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); }