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 2023/11/22 01:35:00 UTC
[jira] [Updated] (LANG-1708) Usage of "ReflectionDiffBuilder"
[ https://issues.apache.org/jira/browse/LANG-1708?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary D. Gregory updated LANG-1708:
----------------------------------
Fix Version/s: 3.14.1
(was: 3.14.0)
> Usage of "ReflectionDiffBuilder"
> --------------------------------
>
> Key: LANG-1708
> URL: https://issues.apache.org/jira/browse/LANG-1708
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.builder.*
> Affects Versions: 3.13.0
> Reporter: Gilles Sadowski
> Priority: Major
> Labels: functional, utility
> Fix For: 3.14.1
>
> Attachments: LANG-1708.unit_test.patch
>
>
> If we have either this class
> {code}
> private static class MyDirect {
> private float value;
> MyDirect(float a) {
> value = a;
> }
> }
> {code}
> or this class
> {code}
> private static class MyReference {
> private MyDirect value;
> MyReference(float a) {
> value = new MyDirect(a);
> }
> }
> {code}
> it could be argued that they are _functionally_ equivalent; IOW, code that uses one or the other (say, via a library) would consider it an implementation detail (e.g. if that library changed one for the other in some internal object).
> [{{ReflectionDiffBuilder}}|https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/builder/ReflectionDiffBuilder.html] however behaves differently: Two instances with the same information contents (a primitive {{float}} value, from the caller POV) are considered the same in the former case and *not the same* in the latter.
> It will be noted that neither class defines an {{equals(Object)}} method; were it the case, the documentation of {{ReflectionDiffBuilder}} [constructor|https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/builder/ReflectionDiffBuilder.html#ReflectionDiffBuilder-T-T-org.apache.commons.lang3.builder.ToStringStyle-] says:
> {noformat}
> If lhs == rhs or lhs.equals(rhs) then the builder will not evaluate any calls to append(...) and will return an empty DiffResult when build() is executed.
> {noformat}
> However there are the use-cases
> # (as above) where {{equals}} was not overridden (and the source code cannot be modified by the user who wants to list the differences, or ensure there are none, functionally), and
> # where one would want to list (potential) differences that could exist even if {{equals}} would return {{true}} (e.g. if {{equals}} is buggy).
> IMHO:
> * Current behaviour is inconsistent (even if intended).
> * There should be a way to disable the equality check (i.e. *always* use reflection to list the differences).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)