--- old/src/java.desktop/share/classes/java/awt/font/TextMeasurer.java 2018-01-08 12:01:56.456832000 +0530 +++ new/src/java.desktop/share/classes/java/awt/font/TextMeasurer.java 2018-01-08 12:01:55.988832000 +0530 @@ -1,5 +1,5 @@ /* - * 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 @@ -652,6 +652,8 @@ * 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} @@ -667,12 +669,15 @@ 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); @@ -718,6 +723,8 @@ * 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} @@ -726,12 +733,15 @@ */ 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;