Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
3.13.0
Description
If we have either this class
private static class MyDirect { private float value; MyDirect(float a) { value = a; } }
or this class
private static class MyReference { private MyDirect value; MyReference(float a) { value = new MyDirect(a); } }
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 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 says:
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.
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).