Summary
The specification for java.lang.Record::equals, in particular its implSpec section, should be updated in order to sync it with the current default implementation provided at java.lang.runtime.ObjectMethods.
Problem
There are two issues in the current specification for java.lang.Record::equals:
- It states that the values used in the comparison are the ones returned by the component accessors, while the implementation uses the values of the component fields
- The equality of primitives states that the implementation should use the
valueOfmethod of the corresponding boxed type along withObject::equalswhich is not what the implementation is actually doing
Solution
Update the specification for method java.lang.Record::equals in particular:
- Clarify that the values used in the comparison are the ones of the component field
- Clarify that the equality of primitives should use the
comparemethod at the corresponding boxed type
Specification
diff --git a/src/java.base/share/classes/java/lang/Record.java b/src/java.base/share/classes/java/lang/Record.java
index 121fc7ce73c..ac41c375a70 100644
--- a/src/java.base/share/classes/java/lang/Record.java
+++ b/src/java.base/share/classes/java/lang/Record.java
@@ -109,15 +109,14 @@ public abstract class Record {
* <li> If the component is of a reference type, the component is
* considered equal if and only if {@link
* java.util.Objects#equals(Object,Object)
- * Objects.equals(this.c(), r.c()} would return {@code true}.
+ * Objects.equals(this.c, r.c} would return {@code true}.
*
* <li> If the component is of a primitive type, using the
* corresponding primitive wrapper class {@code PW} (the
* corresponding wrapper class for {@code int} is {@code
* java.lang.Integer}, and so on), the component is considered
* equal if and only if {@code
- * PW.valueOf(this.c()).equals(PW.valueOf(r.c()))} would return
- * {@code true}.
+ * PW.compare(this.c, r.c)} would return {@code 0}.
*
* </ul>
*
- csr of
-
JDK-8257598 Clarify what component values are used in Record::equals
-
- Resolved
-