[OpenJDK 2D-Dev] [11] RFR: [JDK-5064835] TextMeasurer/deleteChar function fails when deleting more than one characters

Phil Race philip.race at oracle.com
Fri Jan 12 22:03:48 UTC 2018

I think we need to divine what the authors of the method intended since they
seem a bit conflicted about whether only 1 or > 1 chars can be deleted.

- The method is called deleteChar and says it updates the measurer in 
such a case.
- It then says that this call is equivalent to creating a new measurer 
from the text ..
    presumably meaning the text represented by the iterator.

- I am sure that "newParagraph" is expected to be a sub-set of the old 
text but
   what stops you from having original text "abcdef" and new text "12345" ?
   That seems like it neds some doc treatment .. at the least .. have some
fun testing that when you replace LTR with RTL text for example.

- The code does check to see if the new text is other than one char 
different .. although
    it checks only the length .. not the content and if the length is 
!=1 char different
    it it is then re-creates from scratch. This seems to suggest that it 
is expected to
    support > 1 char deleted and allows for the 1 char case as an 

- A consequence of these previous two points is that

- I don't see any "state" at the API level, so the discussions about 
resetting or losing
   state are confusing. The internal "state" won't be lost, it'll be 

- I am at a loss to understand why after "initAll()" the method needs to 
go through
the pointless exercise of recreating the arrays and calling 
Seems to me it can just proceed straight to invalidateComponents()
In fact isn't this the bug ? That's why we get AIOB .. because the code 
assumes "fChars"
is the original longer array.

On balance I think the method is mis-named and mis-documented in suggesting
only a single char is supported. We can't fix the name but we can fix 
the docs
and the exception. This may be the most compatible and most useful fix.

- LineBreakMeasurer looks very similar and needs the same treatment as 
this class

- Minor thing to fix : StyledParagraph.deleteChar javadoc seems to have 
a copy paste
error from StyledParagraph.insertChar

      * Return a StyledParagraph reflecting the insertion of a single 
      * into the text

Should be
      * Return a StyledParagraph reflecting the deletion of a single 
      * from the text


On 12/29/2017 03:00 AM, Prahalad Kumar Narayanan wrote:
> Hello Everyone
> Good day to you.
> Request your time in reviewing the fix for the bug:
> JDK-5064835    TextMeasurer/deleteChar function fails when deleting more than one characters.
> Root Cause:
> . The spec clearly mentions that the concerned method is to be used to delete a single character.
> . However, the spec does not mention the outcome when the method is used to delete multiple characters (as reported in the bug)
> Solution Approaches:
> . Since the spec does not mention the outcome when multiple characters are deleted, the result is left to the implementation.
> . The solution can be approached in two perspectives-
>        1. Update the spec to explicitly mention the exception that would be thrown in such cases or
>        2. Re-initialize the TextMeasurer with the new text as present in the argument of the method.
> Solution:
> . I inspected feasibility/ risk of both the approaches and I 'm of the opinion that approach 1. is better.
> . Reason is that, with the second approach-
>        . The re-initialization would reset all text attributes, and state variabes that were set on TextMeasurer (and internal StyledParagraph) object.
>        . If re-initialization is required, one could create a new TextMeasurer using the modified text rather than invoking deleteChar method.
> . Thus in the proposed solution- I 've added a throws clause that explicitly mentions that IllegalArgumentException will be thrown when attempted to delete multiple characters.
> Other Info:
> . The fix was tested with existing jtreg test cases- No regressions were seen.
> . 2 JCK tests have been found to fail. They are-
>        . java_awt/Font/TextMeasurer/CharTest (TestCase5)
>        . java_awt/Font/LineBreakMeasurer/CharTest (TestCase4)
> . In both the failures, incorrect arguments are passed to deleteChar method- newParagraph (with multiple chars deleted) & beginIndex (-1)
> . While the test case expects index out of bounds exception for -ve index, the code now throws IllegalArgumentsException.
> . A minor correction to JCK test will fix the issue. I shall raise a JCK bug once the fix is approved & submitted.
> Kindly review the changes at your convenience & share your feedback:
> http://cr.openjdk.java.net/~pnarayanan/5064835/webrev.00/
> Note: I 've not raised a CSR for this bug yet.
> Based on review, I will create the CSR for change to the specification.
> Thank you for your time in review &
> Happy New Year
> Prahalad N.

More information about the 2d-dev mailing list