diff --git a/src/java.base/share/classes/java/lang/Boolean.java b/src/java.base/share/classes/java/lang/Boolean.java index 7bfdb98560a..49b9e556417 100644 --- a/src/java.base/share/classes/java/lang/Boolean.java +++ b/src/java.base/share/classes/java/lang/Boolean.java @@ -41,13 +41,19 @@ import static java.lang.constant.ConstantDescs.CD_Boolean; * {@code boolean} in an object. An object of type * {@code Boolean} contains a single field whose type is * {@code boolean}. - *

- * In addition, this class provides many methods for + * + *

In addition, this class provides many methods for * converting a {@code boolean} to a {@code String} and a * {@code String} to a {@code boolean}, as well as other * constants and methods useful when dealing with a * {@code boolean}. * + *

This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. + * * @author Arthur van Hoff * @since 1.0 */ diff --git a/src/java.base/share/classes/java/lang/Byte.java b/src/java.base/share/classes/java/lang/Byte.java index c6900a5f428..c4681bc621e 100644 --- a/src/java.base/share/classes/java/lang/Byte.java +++ b/src/java.base/share/classes/java/lang/Byte.java @@ -48,6 +48,12 @@ import static java.lang.constant.ConstantDescs.DEFAULT_NAME; * byte}, as well as other constants and methods useful when dealing * with a {@code byte}. * + *

This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. + * * @author Nakul Saraiya * @author Joseph D. Darcy * @see java.lang.Number diff --git a/src/java.base/share/classes/java/lang/Character.java b/src/java.base/share/classes/java/lang/Character.java index d1b85ab0d78..ec736c68d46 100644 --- a/src/java.base/share/classes/java/lang/Character.java +++ b/src/java.base/share/classes/java/lang/Character.java @@ -122,6 +122,12 @@ import static java.lang.constant.ConstantDescs.DEFAULT_NAME; * encoding. For more information on Unicode terminology, refer to the * Unicode Glossary. * + *

This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. + * * @author Lee Boynton * @author Guy Steele * @author Akira Tanaka diff --git a/src/java.base/share/classes/java/lang/Double.java b/src/java.base/share/classes/java/lang/Double.java index 85cf88c1cf0..3a0eac5c01c 100644 --- a/src/java.base/share/classes/java/lang/Double.java +++ b/src/java.base/share/classes/java/lang/Double.java @@ -46,6 +46,12 @@ import jdk.internal.vm.annotation.IntrinsicCandidate; * constants and methods useful when dealing with a * {@code double}. * + *

This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. + * * @author Lee Boynton * @author Arthur van Hoff * @author Joseph D. Darcy diff --git a/src/java.base/share/classes/java/lang/Float.java b/src/java.base/share/classes/java/lang/Float.java index e4e815deee5..eac918824ec 100644 --- a/src/java.base/share/classes/java/lang/Float.java +++ b/src/java.base/share/classes/java/lang/Float.java @@ -45,6 +45,12 @@ import jdk.internal.vm.annotation.IntrinsicCandidate; * constants and methods useful when dealing with a * {@code float}. * + *

This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. + * * @author Lee Boynton * @author Arthur van Hoff * @author Joseph D. Darcy diff --git a/src/java.base/share/classes/java/lang/Integer.java b/src/java.base/share/classes/java/lang/Integer.java index 9694213c88b..f2a0efb089f 100644 --- a/src/java.base/share/classes/java/lang/Integer.java +++ b/src/java.base/share/classes/java/lang/Integer.java @@ -50,6 +50,12 @@ import static java.lang.String.UTF16; * {@code int}, as well as other constants and methods useful when * dealing with an {@code int}. * + *

This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. + * *

Implementation note: The implementations of the "bit twiddling" * methods (such as {@link #highestOneBit(int) highestOneBit} and * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are diff --git a/src/java.base/share/classes/java/lang/Long.java b/src/java.base/share/classes/java/lang/Long.java index 16afddf556a..24c3dd2c08b 100644 --- a/src/java.base/share/classes/java/lang/Long.java +++ b/src/java.base/share/classes/java/lang/Long.java @@ -50,6 +50,12 @@ import static java.lang.String.UTF16; * long}, as well as other constants and methods useful when dealing * with a {@code long}. * + *

This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. + * *

Implementation note: The implementations of the "bit twiddling" * methods (such as {@link #highestOneBit(long) highestOneBit} and * {@link #numberOfTrailingZeros(long) numberOfTrailingZeros}) are diff --git a/src/java.base/share/classes/java/lang/ProcessHandle.java b/src/java.base/share/classes/java/lang/ProcessHandle.java index cdecba1af9f..68d1ff0026d 100644 --- a/src/java.base/share/classes/java/lang/ProcessHandle.java +++ b/src/java.base/share/classes/java/lang/ProcessHandle.java @@ -81,12 +81,11 @@ import java.util.stream.Stream; *

* The {@code ProcessHandle} static factory methods return instances that are * value-based, - * immutable and thread-safe. - * Use of identity-sensitive operations (including reference equality - * ({@code ==}), identity hash code, or synchronization) on these instances of - * {@code ProcessHandle} may have unpredictable results and should be avoided. - * Use {@link #equals(Object) equals} or - * {@link #compareTo(ProcessHandle) compareTo} methods to compare ProcessHandles. + * immutable and thread-safe. Programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may occur. + * Use the {@code equals} or {@link #compareTo(ProcessHandle) compareTo} methods + * to compare ProcessHandles. * * @see Process * @since 9 diff --git a/src/java.base/share/classes/java/lang/Runtime.java b/src/java.base/share/classes/java/lang/Runtime.java index 38991e5c6fb..5c166ec5a1e 100644 --- a/src/java.base/share/classes/java/lang/Runtime.java +++ b/src/java.base/share/classes/java/lang/Runtime.java @@ -941,11 +941,11 @@ public class Runtime { * $VNUM(-$PRE)? * * - *

This is a value-based - * class; use of identity-sensitive operations (including reference equality - * ({@code ==}), identity hash code, or synchronization) on instances of - * {@code Version} may have unpredictable results and should be avoided. - *

+ *

This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur.

* * @since 9 */ diff --git a/src/java.base/share/classes/java/lang/Short.java b/src/java.base/share/classes/java/lang/Short.java index 42ed1e6162e..57d1dc0c0ec 100644 --- a/src/java.base/share/classes/java/lang/Short.java +++ b/src/java.base/share/classes/java/lang/Short.java @@ -47,6 +47,12 @@ import static java.lang.constant.ConstantDescs.DEFAULT_NAME; * {@code short}, as well as other constants and methods useful when * dealing with a {@code short}. * + *

This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. + * * @author Nakul Saraiya * @author Joseph D. Darcy * @see java.lang.Number diff --git a/src/java.base/share/classes/java/lang/constant/ConstantDesc.java b/src/java.base/share/classes/java/lang/constant/ConstantDesc.java index 5ffb5b2aded..9d410e6774b 100644 --- a/src/java.base/share/classes/java/lang/constant/ConstantDesc.java +++ b/src/java.base/share/classes/java/lang/constant/ConstantDesc.java @@ -57,8 +57,8 @@ import java.lang.invoke.VarHandle.VarHandleDesc; *

Constants describing various common constants (such as {@link ClassDesc} * instances for platform types) can be found in {@link ConstantDescs}. * - *

Implementations of {@linkplain ConstantDesc} must be - * value-based classes. + *

Implementations of {@linkplain ConstantDesc} should be immutable + * and their behavior should not rely on object identity. * *

Non-platform classes should not implement {@linkplain ConstantDesc} directly. * Instead, they should extend {@link DynamicConstantDesc} (as {@link EnumDesc} diff --git a/src/java.base/share/classes/java/lang/constant/DynamicCallSiteDesc.java b/src/java.base/share/classes/java/lang/constant/DynamicCallSiteDesc.java index f336bc5fb4e..b57f73c0fb9 100644 --- a/src/java.base/share/classes/java/lang/constant/DynamicCallSiteDesc.java +++ b/src/java.base/share/classes/java/lang/constant/DynamicCallSiteDesc.java @@ -41,8 +41,8 @@ import static java.util.stream.Collectors.joining; * A nominal descriptor for an * {@code invokedynamic} call site. * - *

Concrete subtypes of {@linkplain DynamicCallSiteDesc} must be - * value-based. + *

Concrete subtypes of {@linkplain DynamicCallSiteDesc} should be immutable + * and their behavior should not rely on object identity. * * @since 12 */ diff --git a/src/java.base/share/classes/java/lang/constant/DynamicConstantDesc.java b/src/java.base/share/classes/java/lang/constant/DynamicConstantDesc.java index 2ff7a0ebf89..4efd3dde3c3 100644 --- a/src/java.base/share/classes/java/lang/constant/DynamicConstantDesc.java +++ b/src/java.base/share/classes/java/lang/constant/DynamicConstantDesc.java @@ -49,8 +49,8 @@ import static java.util.stream.Collectors.joining; * dynamic constant (one described in the constant pool with * {@code Constant_Dynamic_info}.) * - *

Concrete subtypes of {@linkplain DynamicConstantDesc} must be - * value-based. + *

Concrete subtypes of {@linkplain DynamicConstantDesc} should be immutable + * and their behavior should not rely on object identity. * * @param the type of the dynamic constant * diff --git a/src/java.base/share/classes/java/lang/doc-files/ValueBased.html b/src/java.base/share/classes/java/lang/doc-files/ValueBased.html index fe720a37be7..3c4cd1f4b7d 100644 --- a/src/java.base/share/classes/java/lang/doc-files/ValueBased.html +++ b/src/java.base/share/classes/java/lang/doc-files/ValueBased.html @@ -31,36 +31,38 @@

{@index "Value-based Classes"}

-Some classes, such as java.util.Optional and -java.time.LocalDateTime, are value-based. Instances of a -value-based class: +Some classes, such as java.lang.Integer and +java.time.LocalDate, are value-based. +A value-based class has the following properties: -

A program may produce unpredictable results if it attempts to distinguish two - references to equal values of a value-based class, whether directly via reference +

When two instances of a value-based class are equal (according to `equals`), a program + should not attempt to distinguish between their identities, whether directly via reference equality or indirectly via an appeal to synchronization, identity hashing, - serialization, or any other identity-sensitive mechanism. Use of such - identity-sensitive operations on instances of value-based classes may have - unpredictable effects and should be avoided.

+ serialization, or any other identity-sensitive mechanism.

+

Synchronization on instances of value-based classes is strongly discouraged, + because the programmer cannot guarantee exclusive ownership of the + associated monitor.

diff --git a/src/java.base/share/classes/java/time/Duration.java b/src/java.base/share/classes/java/time/Duration.java index e1899478f7b..baecb9e8e4c 100644 --- a/src/java.base/share/classes/java/time/Duration.java +++ b/src/java.base/share/classes/java/time/Duration.java @@ -117,13 +117,12 @@ import java.util.regex.Pattern; * This difference only impacts durations measured near a leap-second and should not affect * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/Instant.java b/src/java.base/share/classes/java/time/Instant.java index 40d7878c2f9..a59f9857104 100644 --- a/src/java.base/share/classes/java/time/Instant.java +++ b/src/java.base/share/classes/java/time/Instant.java @@ -191,13 +191,12 @@ import java.util.Objects; * The Java time-scale is used for all date-time classes. * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/LocalDate.java b/src/java.base/share/classes/java/time/LocalDate.java index 5d88ffc7880..a5d9f9e0bd3 100644 --- a/src/java.base/share/classes/java/time/LocalDate.java +++ b/src/java.base/share/classes/java/time/LocalDate.java @@ -123,13 +123,12 @@ import java.util.stream.Stream; * For most applications written today, the ISO-8601 rules are entirely suitable. * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/LocalDateTime.java b/src/java.base/share/classes/java/time/LocalDateTime.java index 2df6657a533..38a59e99e49 100644 --- a/src/java.base/share/classes/java/time/LocalDateTime.java +++ b/src/java.base/share/classes/java/time/LocalDateTime.java @@ -119,13 +119,12 @@ import java.util.Objects; * For most applications written today, the ISO-8601 rules are entirely suitable. * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/LocalTime.java b/src/java.base/share/classes/java/time/LocalTime.java index f4c285bd4f0..8983e48ec8b 100644 --- a/src/java.base/share/classes/java/time/LocalTime.java +++ b/src/java.base/share/classes/java/time/LocalTime.java @@ -109,13 +109,12 @@ import java.util.Objects; * The ISO-8601 calendar system is the modern civil calendar system used today * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/MonthDay.java b/src/java.base/share/classes/java/time/MonthDay.java index 818a1cda7c8..5dfcbec7ecb 100644 --- a/src/java.base/share/classes/java/time/MonthDay.java +++ b/src/java.base/share/classes/java/time/MonthDay.java @@ -111,13 +111,12 @@ import java.util.Objects; * For most applications written today, the ISO-8601 rules are entirely suitable. * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/OffsetDateTime.java b/src/java.base/share/classes/java/time/OffsetDateTime.java index e3c11e62fdf..c1fa78d5e41 100644 --- a/src/java.base/share/classes/java/time/OffsetDateTime.java +++ b/src/java.base/share/classes/java/time/OffsetDateTime.java @@ -112,13 +112,12 @@ import java.util.Objects; * It is intended that {@code ZonedDateTime} or {@code Instant} is used to model data * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/OffsetTime.java b/src/java.base/share/classes/java/time/OffsetTime.java index 70e5cde783b..36ba793bb83 100644 --- a/src/java.base/share/classes/java/time/OffsetTime.java +++ b/src/java.base/share/classes/java/time/OffsetTime.java @@ -102,13 +102,12 @@ import java.util.Objects; * as well as a zone offset. * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/Period.java b/src/java.base/share/classes/java/time/Period.java index f4bc462985a..673c48fb560 100644 --- a/src/java.base/share/classes/java/time/Period.java +++ b/src/java.base/share/classes/java/time/Period.java @@ -117,13 +117,12 @@ import java.util.regex.Pattern; *

* 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/Year.java b/src/java.base/share/classes/java/time/Year.java index 78bdd9ef2c5..4082e180024 100644 --- a/src/java.base/share/classes/java/time/Year.java +++ b/src/java.base/share/classes/java/time/Year.java @@ -119,13 +119,12 @@ import java.util.Objects; * For most applications written today, the ISO-8601 rules are entirely suitable. * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/YearMonth.java b/src/java.base/share/classes/java/time/YearMonth.java index ed2902a0d22..f0f99b65dca 100644 --- a/src/java.base/share/classes/java/time/YearMonth.java +++ b/src/java.base/share/classes/java/time/YearMonth.java @@ -115,13 +115,12 @@ import java.util.Objects; * For most applications written today, the ISO-8601 rules are entirely suitable. * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/ZoneId.java b/src/java.base/share/classes/java/time/ZoneId.java index 309814d40a8..1c7d8f95037 100644 --- a/src/java.base/share/classes/java/time/ZoneId.java +++ b/src/java.base/share/classes/java/time/ZoneId.java @@ -160,13 +160,12 @@ import static java.util.Map.entry; * However, any call to {@code getRules} will fail with {@code ZoneRulesException}. * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This abstract class has two implementations, both of which are immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/ZoneOffset.java b/src/java.base/share/classes/java/time/ZoneOffset.java index 09ed10a1248..36cbee8d24b 100644 --- a/src/java.base/share/classes/java/time/ZoneOffset.java +++ b/src/java.base/share/classes/java/time/ZoneOffset.java @@ -114,13 +114,12 @@ import java.util.concurrent.ConcurrentMap; * Instances of {@code ZoneOffset} must be compared using {@link #equals}. * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/ZonedDateTime.java b/src/java.base/share/classes/java/time/ZonedDateTime.java index 5e931e0dc9e..151d414f56e 100644 --- a/src/java.base/share/classes/java/time/ZonedDateTime.java +++ b/src/java.base/share/classes/java/time/ZonedDateTime.java @@ -142,13 +142,12 @@ import java.util.Objects; * of a {@code LocalDateTime} and a {@code ZoneId}. The {@code ZoneOffset} is * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * A {@code ZonedDateTime} holds state equivalent to three separate objects, diff --git a/src/java.base/share/classes/java/time/chrono/HijrahDate.java b/src/java.base/share/classes/java/time/chrono/HijrahDate.java index 7e1e9892f5a..fc77c9d1d06 100644 --- a/src/java.base/share/classes/java/time/chrono/HijrahDate.java +++ b/src/java.base/share/classes/java/time/chrono/HijrahDate.java @@ -103,13 +103,12 @@ import java.time.temporal.ValueRange; * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/chrono/JapaneseDate.java b/src/java.base/share/classes/java/time/chrono/JapaneseDate.java index 87abc68cf4c..3699933e419 100644 --- a/src/java.base/share/classes/java/time/chrono/JapaneseDate.java +++ b/src/java.base/share/classes/java/time/chrono/JapaneseDate.java @@ -110,13 +110,12 @@ import sun.util.calendar.LocalGregorianCalendar; * Calling {@code japaneseDate.get(YEAR)} will return 2012.
* 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/chrono/MinguoDate.java b/src/java.base/share/classes/java/time/chrono/MinguoDate.java index 32c6ed5c161..70ad47b6291 100644 --- a/src/java.base/share/classes/java/time/chrono/MinguoDate.java +++ b/src/java.base/share/classes/java/time/chrono/MinguoDate.java @@ -90,13 +90,12 @@ import java.util.Objects; * This date operates using the {@linkplain MinguoChronology Minguo calendar}. * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/time/chrono/ThaiBuddhistDate.java b/src/java.base/share/classes/java/time/chrono/ThaiBuddhistDate.java index aff383902cc..5153c0a672e 100644 --- a/src/java.base/share/classes/java/time/chrono/ThaiBuddhistDate.java +++ b/src/java.base/share/classes/java/time/chrono/ThaiBuddhistDate.java @@ -90,13 +90,12 @@ import java.util.Objects; * This date operates using the {@linkplain ThaiBuddhistChronology Thai Buddhist calendar}. * 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. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/java.base/share/classes/java/util/KeyValueHolder.java b/src/java.base/share/classes/java/util/KeyValueHolder.java index c5b47e2a9d1..d0b91a6b49b 100644 --- a/src/java.base/share/classes/java/util/KeyValueHolder.java +++ b/src/java.base/share/classes/java/util/KeyValueHolder.java @@ -31,10 +31,11 @@ import jdk.internal.vm.annotation.Stable; * An immutable container for a key and a value, suitable for use * in creating and populating {@code Map} instances. * - *

This is a value-based - * class; use of identity-sensitive operations (including reference equality - * ({@code ==}), identity hash code, or synchronization) on instances of - * {@code KeyValueHolder} may have unpredictable results and should be avoided. + *

This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. * * @apiNote * This class is not public. Instances can be created using the diff --git a/src/java.base/share/classes/java/util/List.java b/src/java.base/share/classes/java/util/List.java index 2496ae6dc6d..8392b4f6a23 100644 --- a/src/java.base/share/classes/java/util/List.java +++ b/src/java.base/share/classes/java/util/List.java @@ -107,10 +107,11 @@ import java.util.function.UnaryOperator; *

  • The lists and their {@link #subList(int, int) subList} views implement the * {@link RandomAccess} interface. *
  • They are value-based. - * Callers should make no assumptions about the identity of the returned instances. - * Factories are free to create new instances or reuse existing ones. Therefore, - * identity-sensitive operations on these instances (reference equality ({@code ==}), - * identity hash code, and synchronization) are unreliable and should be avoided. + * Programmers should treat instances that are {@linkplain #equals(Object) equal} + * as interchangeable and should not use them for synchronization, or + * unpredictable behavior may occur. Callers should make no assumptions + * about the identity of the returned instances. Factories are free to + * create new instances or reuse existing ones. *
  • They are serialized as specified on the * Serialized Form * page. diff --git a/src/java.base/share/classes/java/util/Map.java b/src/java.base/share/classes/java/util/Map.java index b1de34b42a5..6063af06f2c 100644 --- a/src/java.base/share/classes/java/util/Map.java +++ b/src/java.base/share/classes/java/util/Map.java @@ -131,10 +131,11 @@ import java.io.Serializable; * passed to a static factory method result in {@code IllegalArgumentException}. *
  • The iteration order of mappings is unspecified and is subject to change. *
  • They are value-based. - * Callers should make no assumptions about the identity of the returned instances. - * Factories are free to create new instances or reuse existing ones. Therefore, - * identity-sensitive operations on these instances (reference equality ({@code ==}), - * identity hash code, and synchronization) are unreliable and should be avoided. + * Programmers should treat instances that are {@linkplain #equals(Object) equal} + * as interchangeable and should not use them for synchronization, or + * unpredictable behavior may occur. Callers should make no assumptions + * about the identity of the returned instances. Factories are free to + * create new instances or reuse existing ones. *
  • They are serialized as specified on the * Serialized Form * page. @@ -1636,10 +1637,11 @@ public interface Map { * on a returned {@code Entry} result in {@code UnsupportedOperationException}. *
  • They are not serializable. *
  • They are value-based. - * Callers should make no assumptions about the identity of the returned instances. - * This method is free to create new instances or reuse existing ones. Therefore, - * identity-sensitive operations on these instances (reference equality ({@code ==}), - * identity hash code, and synchronization) are unreliable and should be avoided. + * Programmers should treat instances that are {@linkplain #equals(Object) equal} + * as interchangeable and should not use them for synchronization, or + * unpredictable behavior may occur. Callers should make no assumptions + * about the identity of the returned instances. This method is free to + * create new instances or reuse existing ones. * * * @apiNote diff --git a/src/java.base/share/classes/java/util/Optional.java b/src/java.base/share/classes/java/util/Optional.java index 4a0b58e5286..b3870cfb17d 100644 --- a/src/java.base/share/classes/java/util/Optional.java +++ b/src/java.base/share/classes/java/util/Optional.java @@ -42,10 +42,11 @@ import java.util.stream.Stream; * {@link #ifPresent(Consumer) ifPresent()} (performs an * action if a value is present). * - *

    This is a value-based - * class; use of identity-sensitive operations (including reference equality - * ({@code ==}), identity hash code, or synchronization) on instances of - * {@code Optional} may have unpredictable results and should be avoided. + *

    This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. * * @apiNote * {@code Optional} is primarily intended for use as a method return type where diff --git a/src/java.base/share/classes/java/util/OptionalDouble.java b/src/java.base/share/classes/java/util/OptionalDouble.java index c4673f9317d..285ca83d733 100644 --- a/src/java.base/share/classes/java/util/OptionalDouble.java +++ b/src/java.base/share/classes/java/util/OptionalDouble.java @@ -41,10 +41,11 @@ import java.util.stream.DoubleStream; * {@link #ifPresent(DoubleConsumer) ifPresent()} (performs * an action if a value is present). * - *

    This is a value-based - * class; use of identity-sensitive operations (including reference equality - * ({@code ==}), identity hash code, or synchronization) on instances of - * {@code OptionalDouble} may have unpredictable results and should be avoided. + *

    This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. * * @apiNote * {@code OptionalDouble} is primarily intended for use as a method return type where diff --git a/src/java.base/share/classes/java/util/OptionalInt.java b/src/java.base/share/classes/java/util/OptionalInt.java index 75747391d30..471cf5c1fea 100644 --- a/src/java.base/share/classes/java/util/OptionalInt.java +++ b/src/java.base/share/classes/java/util/OptionalInt.java @@ -41,10 +41,11 @@ import java.util.stream.IntStream; * {@link #ifPresent(IntConsumer) ifPresent()} (performs an * action if a value is present). * - *

    This is a value-based - * class; use of identity-sensitive operations (including reference equality - * ({@code ==}), identity hash code, or synchronization) on instances of - * {@code OptionalInt} may have unpredictable results and should be avoided. + *

    This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. * * @apiNote * {@code OptionalInt} is primarily intended for use as a method return type where diff --git a/src/java.base/share/classes/java/util/OptionalLong.java b/src/java.base/share/classes/java/util/OptionalLong.java index 61ad210947d..1cb92719771 100644 --- a/src/java.base/share/classes/java/util/OptionalLong.java +++ b/src/java.base/share/classes/java/util/OptionalLong.java @@ -41,10 +41,11 @@ import java.util.stream.LongStream; * {@link #ifPresent(LongConsumer) ifPresent()} (performs an * action if a value is present). * - *

    This is a value-based - * class; use of identity-sensitive operations (including reference equality - * ({@code ==}), identity hash code, or synchronization) on instances of - * {@code OptionalLong} may have unpredictable results and should be avoided. + *

    This is a value-based + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. * * @apiNote * {@code OptionalLong} is primarily intended for use as a method return type where diff --git a/src/java.base/share/classes/java/util/Set.java b/src/java.base/share/classes/java/util/Set.java index b8109d0b4fb..fd2d002ad6a 100644 --- a/src/java.base/share/classes/java/util/Set.java +++ b/src/java.base/share/classes/java/util/Set.java @@ -82,10 +82,11 @@ package java.util; * passed to a static factory method result in {@code IllegalArgumentException}. *

  • The iteration order of set elements is unspecified and is subject to change. *
  • They are value-based. - * Callers should make no assumptions about the identity of the returned instances. - * Factories are free to create new instances or reuse existing ones. Therefore, - * identity-sensitive operations on these instances (reference equality ({@code ==}), - * identity hash code, and synchronization) are unreliable and should be avoided. + * Programmers should treat instances that are {@linkplain #equals(Object) equal} + * as interchangeable and should not use them for synchronization, or + * unpredictable behavior may occur. Callers should make no assumptions + * about the identity of the returned instances. Factories are free to + * create new instances or reuse existing ones. *
  • They are serialized as specified on the * Serialized Form * page. diff --git a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/GroupLayout.java b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/GroupLayout.java index fc1fbe6c212..65165ec625f 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/GroupLayout.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/GroupLayout.java @@ -44,13 +44,12 @@ import java.util.stream.Collectors; * can be combined: if member layouts are laid out one after the other, the resulting group layout is said to be a struct * (see {@link MemoryLayout#ofStruct(MemoryLayout...)}); conversely, if all member layouts are laid out at the same starting offset, * the resulting group layout is said to be a union (see {@link MemoryLayout#ofUnion(MemoryLayout...)}). - * *

    * This is a value-based - * class; use of identity-sensitive operations (including reference equality - * ({@code ==}), identity hash code, or synchronization) on instances of - * {@code GroupLayout} may have unpredictable results and should be avoided. - * The {@code equals} method should be used for comparisons. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java index 2cc9905e29d..8fa5b4784b8 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java @@ -40,8 +40,8 @@ import java.lang.ref.Cleaner; * when performing memory dereference operations using a memory access var handle (see {@link MemoryHandles}). *

    * All implementations of this interface must be value-based; - * use of identity-sensitive operations (including reference equality ({@code ==}), identity hash code, or synchronization) on - * instances of {@code MemoryAddress} may have unpredictable results and should be avoided. The {@code equals} method should + * programmers should treat instances that are {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may occur. The {@code equals} method should * be used for comparisons. *

    * Non-platform classes should not implement {@linkplain MemoryAddress} directly. diff --git a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayout.java b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayout.java index 45487c7d76a..5206e27cb98 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayout.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayout.java @@ -76,8 +76,8 @@ SequenceLayout taggedValues = MemoryLayout.ofSequence(5, * } *

    * All implementations of this interface must be value-based; - * use of identity-sensitive operations (including reference equality ({@code ==}), identity hash code, or synchronization) on - * instances of {@code MemoryLayout} may have unpredictable results and should be avoided. The {@code equals} method should + * programmers should treat instances that are {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may occur. The {@code equals} method should * be used for comparisons. *

    * Non-platform classes should not implement {@linkplain MemoryLayout} directly. diff --git a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java index 76303bb58fa..5c3b7c6738b 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java @@ -50,8 +50,8 @@ import java.util.Spliterator; * operations on a segment cannot occur after a memory segment has been closed (see {@link MemorySegment#close()}). *

    * All implementations of this interface must be value-based; - * use of identity-sensitive operations (including reference equality ({@code ==}), identity hash code, or synchronization) on - * instances of {@code MemorySegment} may have unpredictable results and should be avoided. The {@code equals} method should + * programmers should treat instances that are {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may occur. The {@code equals} method should * be used for comparisons. *

    * Non-platform classes should not implement {@linkplain MemorySegment} directly. diff --git a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/PaddingLayout.java b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/PaddingLayout.java index d3994227595..3eaa9b5921f 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/PaddingLayout.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/PaddingLayout.java @@ -38,10 +38,10 @@ import java.util.OptionalLong; * and is typically used for aligning member layouts around word boundaries. *

    * This is a value-based - * class; use of identity-sensitive operations (including reference equality - * ({@code ==}), identity hash code, or synchronization) on instances of - * {@code PaddingLayout} may have unpredictable results and should be avoided. - * The {@code equals} method should be used for comparisons. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SequenceLayout.java b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SequenceLayout.java index 44a5e7bb941..1db09352f47 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SequenceLayout.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SequenceLayout.java @@ -55,10 +55,10 @@ MemoryLayout.ofStruct( * *

    * This is a value-based - * class; use of identity-sensitive operations (including reference equality - * ({@code ==}), identity hash code, or synchronization) on instances of - * {@code SequenceLayout} may have unpredictable results and should be avoided. - * The {@code equals} method should be used for comparisons. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/ValueLayout.java b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/ValueLayout.java index ee62081308c..c2082861d14 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/ValueLayout.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/ValueLayout.java @@ -40,10 +40,10 @@ import java.util.OptionalLong; * *

    * This is a value-based - * class; use of identity-sensitive operations (including reference equality - * ({@code ==}), identity hash code, or synchronization) on instances of - * {@code ValueLayout} may have unpredictable results and should be avoided. - * The {@code equals} method should be used for comparisons. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * * @implSpec * This class is immutable and thread-safe. diff --git a/test/lib/jdk/test/lib/hexdump/HexPrinter.java b/test/lib/jdk/test/lib/hexdump/HexPrinter.java index 12f0cfd45b0..f702fabec84 100644 --- a/test/lib/jdk/test/lib/hexdump/HexPrinter.java +++ b/test/lib/jdk/test/lib/hexdump/HexPrinter.java @@ -143,10 +143,10 @@ import java.util.Objects; * *

    * This is a value-based - * class; use of identity-sensitive operations (including reference equality - * ({@code ==}), identity hash code, or synchronization) on instances - * may have unpredictable results and should be avoided. - * The {@code equals} method should be used for comparisons. + * class; programmers should treat instances that are + * {@linkplain #equals(Object) equal} as interchangeable and should not + * use instances for synchronization, or unpredictable behavior may + * occur. The {@code equals} method should be used for comparisons. * *

    * This class is immutable and thread-safe.