ObjectMethods seems generating wrong methods for array-type field
forax at univ-mlv.fr
Wed Apr 14 10:12:06 UTC 2021
----- Mail original -----
> De: "Kengo TODA" <skypencil at gmail.com>
> À: "core-libs-dev" <core-libs-dev at openjdk.java.net>
> Envoyé: Mercredi 14 Avril 2021 11:03:14
> Objet: Re: ObjectMethods seems generating wrong methods for array-type field
> I found that the JLS 16 does not cover the array type record component:
> So it could be not a core-lib issue but a JLS issue.
Nope, the implementation of a record is covered in the javadoc of java.lang.Record
for equals, see https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Record.html#equals(java.lang.Object)
As you can see the spec clearly says that for any fields which is an object (arrays are objects), it should be semantically equivalent to calling java.util.Objects.equals() on those fields.
So it's not a bug, it's how record.equals() works, as Raffaello said, records are dumb containers, this is how we have specified them.
Records have been specified as part of the project Amber, you can take a look to the mailing list  for more if you want.
> Do I need to forward this thread to another mailing list?
> If so, please let me know which is the preferred one.
> I've checked https://mail.openjdk.java.net/mailman/listinfo but not so sure.
> Thank you very much.
> Kengo TODA
> skypencil at gmail.com
> On Wed, Apr 14, 2021 at 9:04 AM Kengo TODA <skypencil at gmail.com> wrote:
>> Hello there,
>> I'm Kengo TODA, an engineer learning about the Record feature.
>> Today I found a nonintentional behavior, and it seems that the bug
>> database has no info about it.
>> Let me ask here to confirm it's by-design or not. If it's a bug, I want to
>> try to send a patch to OpenJDK.
>> Here is the code reproducing the nonintentional behavior:
>> In short, the ObjectMethods class in OpenJDK v16 generates code
>> that invokes the fields' method, even when the field is an array.
>> Please help me to understand this behavior, or
>> make an entry in the bug database to propose a patch.
>> Thanks in advance! :)
>> Kengo TODA
>> skypencil at gmail.com
More information about the core-libs-dev