Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1708

Usage of "ReflectionDiffBuilder"

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    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

      1. (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
      2. 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).

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            erans Gilles Sadowski

            Dates

              Created:
              Updated:

              Slack

                Issue deployment