Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-4701

TextPosition.equal() fails after getDir()

    XMLWordPrintableJSON

    Details

      Description

      From "Esteban R" in the users mailing list:

      This is a simplification of a real life problem: when I compare two TextPositions, equality changes after calling getDir() in one of the TextPositions.

      Code to reproduce:

      Matrix m1 = new Matrix(1, 1, 1, 1, 1, 1);
      Matrix m2 = new Matrix(1, 1, 1, 1, 1, 1);
      TextPosition t1 = new TextPosition(0, 1000, 1000, m2, 10, 10, 100, 10, 10, "a", null, null, 10, 10);
      TextPosition t2 = new TextPosition(0, 1000, 1000, m2, 10, 10, 100, 10, 10, "a", null, null, 10, 10);
      System.out.println("Before getDir, equals: "+t1.equals(t2)); //true
      t1.getDir(); //changes direction field!!!
      System.out.println("After getDir, equals: "+t1.equals(t2)); //false!!

      The reason is that mutable fields are used in equals().

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                tilman Tilman Hausherr
                Reporter:
                tilman Tilman Hausherr
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: