You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2026/03/08 14:25:00 UTC
[jira] [Comment Edited] (VALIDATOR-509) apache/commons-validator — Cloneable classes missing equals()/hashCode()
[ https://issues.apache.org/jira/browse/VALIDATOR-509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18063898#comment-18063898 ]
Gary D. Gregory edited comment on VALIDATOR-509 at 3/8/26 2:24 PM:
-------------------------------------------------------------------
[~shanjiang]
Where is this documented in the JRE Javadoc?
was (Author: garydgregory):
[~shanjiang]
Where is this documented in the JRE Java document?
> apache/commons-validator — Cloneable classes missing equals()/hashCode()
> ------------------------------------------------------------------------
>
> Key: VALIDATOR-509
> URL: https://issues.apache.org/jira/browse/VALIDATOR-509
> Project: Commons Validator
> Issue Type: Bug
> Reporter: Shan Jiang
> Priority: Minor
>
> `Arg`, `Msg`, `Var`, `Field` — `clone()` copies state but `equals()` uses identity comparison
> ### Summary
> Four classes in `org.apache.commons.validator` implement `Cloneable` with correct `clone()`
> implementations that copy all fields, but do not override `equals()` or `hashCode()`.
> This means `x.clone().equals(x)` always returns `false` (identity comparison), violating
> the `clone()` contract:
> > "By convention, the object returned by this method should be equal to this object."
> ### Affected classes
> | Class | clone() copies |
> |-------|---------------|
> | `Arg` | name, key, position, bundle, resource |
> | `Msg` | name, key, bundle, resource |
> | `Var` | name, value, jsType, bundle, resource |
> | `Field` | property, indexedProperty, indexedListProperty, key, args, depends, ... |
> ### How this was found
> Detected by an automated JDK conformance oracle (`ObjectOracles.checkCloneEqualsConsistency`).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)