Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8096418

[TextFlow] TextFlow.computePrefHeight(double width) with width > Float.MAX_VALUE leads to erroneous behavior.

    XMLWordPrintable

    Details

      Description

      The problem is that when width (of type double) is greater than Float.MAX_VALUE, then the cast

          (float) width

      results in Float.POSITIVE_INFINITY. This is what happens in TextFlow.java on line 227 (method computePrefHeight(double)):

          layout.setWrapWidth((float)wrappingWidth);

      So this sets the wrapWidth in PrismTextLayout.java to infinity. Later, in PrismTextLayout.layout(), there is

          float fullWidth = Math.max(wrapWidth, layoutWidth); // fullWidth is now Infinity
          // ...
          align = 0;
          // ...
          float lineX = (fullWidth - [...]) * align; // lineX is now NaN (Infinity*0)
          // ...
          float runX = lineX; // runX is now NaN
          // ...
          run.setLocation(runX, lineY);

      So we have a TextRun whose location's x coordinate is NaN. Now, I don't have an example that demonstrates this bug using only the public API, but I have one that uses non-public API, namely PrismTextLayout.getCaretShape(). These lines from the getCaretShape() method cause the propagation of the NaN value to path elements of the caret shape, making them unusable.

          Point2D location = run.getLocation();
          lineX = location.x + [...]; // lineX is now NaN
          // ...
          result[0] = new MoveTo(lineX, lineY);
          result[1] = new LineTo(lineX, lineY + lineHeight);
          return result;

      I guess that depending on how this is fixed, it may also affect this advice in TextFlow's Javadoc:

          "If no wrapping is desired, the application can either set the preferred with to Double.MAX_VALUE or Region.USE_COMPUTED_SIZE."

      Namely, I'm concerned about the use of Double.MAX_VALUE, or anything greater than Float.MAX_VALUE.

        Attachments

          Activity

            People

            Assignee:
            fheidric Felipe Heidrich (Inactive)
            Reporter:
            tmikula Tomas Mikula
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: