< prev index next >

src/java.desktop/share/classes/java/awt/font/TextMeasurer.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -650,10 +650,12 @@
      * the insertion.  Cannot be null.
      * @param insertPos the position in the text where the character was
      * inserted.  Must not be less than the start of
      * {@code newParagraph}, and must be less than the end of
      * {@code newParagraph}.
+     * @throws IllegalArgumentException if multiple characters are inserted
+     *         in the text represented by {@code newParagraph}
      * @throws IndexOutOfBoundsException if {@code insertPos} is less
      *         than the start of {@code newParagraph} or greater than
      *         or equal to the end of {@code newParagraph}
      * @throws NullPointerException if {@code newParagraph} is
      *         {@code null}

@@ -665,16 +667,19 @@
         }
         if (wantStats) {
             collectStats = true;
         }
 
-        fStart = newParagraph.getBeginIndex();
+        int start = newParagraph.getBeginIndex();
         int end = newParagraph.getEndIndex();
-        if (end - fStart != fChars.length+1) {
-            initAll(newParagraph);
+        if (end - start != fChars.length+1) {
+            // The new paragraph attempts to insert multiple characters
+            throw new IllegalArgumentException("The new paragraph"
+                    + " attempts to insert multiple characters into the text.");
         }
 
+        fStart = start;
         char[] newChars = new char[end-fStart];
         int newCharIndex = insertPos - fStart;
         System.arraycopy(fChars, 0, newChars, 0, newCharIndex);
 
         char newChar = newParagraph.setIndex(insertPos);

@@ -716,24 +721,29 @@
      * the deletion.  Cannot be null.
      * @param deletePos the position in the text where the character was removed.
      * Must not be less than
      * the start of {@code newParagraph}, and must not be greater than the
      * end of {@code newParagraph}.
+     * @throws IllegalArgumentException if multiple characters are deleted from
+     *         the text represented by {@code newParagraph}
      * @throws IndexOutOfBoundsException if {@code deletePos} is
      *         less than the start of {@code newParagraph} or greater
      *         than the end of {@code newParagraph}
      * @throws NullPointerException if {@code newParagraph} is
      *         {@code null}
      */
     public void deleteChar(AttributedCharacterIterator newParagraph, int deletePos) {
 
-        fStart = newParagraph.getBeginIndex();
+        int start = newParagraph.getBeginIndex();
         int end = newParagraph.getEndIndex();
-        if (end - fStart != fChars.length-1) {
-            initAll(newParagraph);
+        if (end - start != fChars.length-1) {
+            // The new paragraph attempts to delete multiple characters
+            throw new IllegalArgumentException("The new paragraph"
+                    + " attempts to delete multiple characters from the text.");
         }
 
+        fStart = start;
         char[] newChars = new char[end-fStart];
         int changedIndex = deletePos-fStart;
 
         System.arraycopy(fChars, 0, newChars, 0, deletePos-fStart);
         System.arraycopy(fChars, changedIndex+1, newChars, changedIndex, end-deletePos);
< prev index next >