Path: blob/master/test/jdk/java/text/BreakIterator/Bug7104012.java
41152 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 710401225* @summary Confirm that AIOBE is not thrown.26*/2728import java.text.*;29import java.util.*;3031public class Bug7104012 {3233public static void main(String[] args) {34boolean err = false;3536List<String> data = new ArrayList<>();37data.add("\udb40");38data.add(" \udb40");39data.add("\udc53");40data.add(" \udc53");41data.add(" \udb40\udc53");42data.add("\udb40\udc53");43data.add("ABC \udb40\udc53 123");44data.add("\udb40\udc53 ABC \udb40\udc53");4546for (Locale locale : Locale.getAvailableLocales()) {47List<BreakIterator> breakIterators = new ArrayList<>();48breakIterators.add(BreakIterator.getCharacterInstance(locale));49breakIterators.add(BreakIterator.getLineInstance(locale));50breakIterators.add(BreakIterator.getSentenceInstance(locale));51breakIterators.add(BreakIterator.getWordInstance(locale));5253for (BreakIterator bi : breakIterators) {54for (String str : data) {55try {56bi.setText(str);57bi.first();58while (bi.next() != BreakIterator.DONE) { }59bi.last();60while (bi.previous() != BreakIterator.DONE) { }61}62catch (ArrayIndexOutOfBoundsException ex) {63System.out.println(" " + data.indexOf(str)64+ ": BreakIterator(" + locale65+ ") threw AIOBE.");66err = true;67}68}69}70}7172if (err) {73throw new RuntimeException("Unexpected exeption.");74}75}7677}787980