3032N/A/*
3032N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3032N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3032N/A *
3032N/A * This code is free software; you can redistribute it and/or modify it
3032N/A * under the terms of the GNU General Public License version 2 only, as
3032N/A * published by the Free Software Foundation.
3032N/A *
3032N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3032N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3032N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3032N/A * version 2 for more details (a copy is included in the LICENSE file that
3032N/A * accompanied this code).
3032N/A *
3032N/A * You should have received a copy of the GNU General Public License version
3032N/A * 2 along with this work; if not, write to the Free Software Foundation,
3032N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3032N/A *
3032N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3032N/A * or visit www.oracle.com if you need additional information or have any
3032N/A * questions.
3032N/A */
3032N/A
3032N/A/*
3032N/A * @test
3032N/A * @bug 6771184
3032N/A * @summary Some methods in text package don't throw BadLocationException when expected
3032N/A * @author Pavel Porvatov
3032N/A */
3032N/A
3032N/Aimport javax.swing.*;
3032N/Aimport javax.swing.text.BadLocationException;
3032N/Aimport javax.swing.text.Highlighter;
3032N/Aimport javax.swing.text.JTextComponent;
3032N/Aimport java.awt.*;
3032N/A
3032N/Apublic class bug6771184 {
3032N/A public static void main(String[] args) {
3032N/A SwingUtilities.invokeLater(new Runnable() {
3032N/A public void run() {
3032N/A JTextArea textArea = new JTextArea("Tested string");
3032N/A
3032N/A Highlighter highlighter = textArea.getHighlighter();
3032N/A Highlighter.HighlightPainter myPainter = new Highlighter.HighlightPainter() {
3032N/A public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) {
3032N/A }
3032N/A };
3032N/A
3032N/A int negativeTestedData[][] = {{50, 0},
3032N/A {-1, 1},
3032N/A {-5, -4},
3032N/A {Integer.MAX_VALUE, Integer.MIN_VALUE},
3032N/A {Integer.MIN_VALUE, Integer.MAX_VALUE},
3032N/A {Integer.MIN_VALUE, Integer.MIN_VALUE}};
3032N/A
3032N/A for (int[] data : negativeTestedData) {
3032N/A try {
3032N/A highlighter.addHighlight(data[0], data[1], myPainter);
3032N/A
3032N/A throw new RuntimeException("Method addHighlight() does not throw BadLocationException for (" +
3032N/A data[0] + ", " + data[1] + ") ");
3032N/A } catch (BadLocationException e) {
3032N/A // Ok
3032N/A }
3032N/A
3032N/A Object objRef;
3032N/A
3032N/A try {
3032N/A objRef = highlighter.addHighlight(0, 1, myPainter);
3032N/A } catch (BadLocationException e) {
3032N/A throw new RuntimeException("highlighter.addHighlight(0, 1, myPainter) throws exception", e);
3032N/A }
3032N/A
3032N/A try {
3032N/A highlighter.changeHighlight(objRef, data[0], data[1]);
3032N/A
3032N/A throw new RuntimeException("Method changeHighlight() does not throw BadLocationException for (" +
3032N/A data[0] + ", " + data[1] + ") ");
3032N/A } catch (BadLocationException e) {
3032N/A // Ok
3032N/A }
3032N/A }
3032N/A }
3032N/A });
3032N/A }
3032N/A}