Path: blob/master/test/jdk/javax/swing/JSlider/6794831/bug6794831.java
41153 views
/*1* Copyright (c) 2009, 2014, 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*/2223/*24* @test25* @key headful26* @bug 679483127* @summary Infinite loop while painting ticks on Slider with maximum=MAX_INT28* @author Pavel Porvatov29@run main bug679483130*/3132import javax.swing.*;33import javax.swing.plaf.basic.BasicSliderUI;34import java.awt.image.BufferedImage;35import java.lang.reflect.InvocationTargetException;36import java.util.concurrent.CountDownLatch;37import java.util.concurrent.TimeUnit;3839public class bug6794831 {40private final CountDownLatch countDownLatch = new CountDownLatch(1);4142public static void main(String args[])43throws InterruptedException, InvocationTargetException {44new bug6794831().run();45}4647private void run() throws InterruptedException, InvocationTargetException {48SwingUtilities.invokeAndWait(new Runnable() {49public void run() {50for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) {51try {52UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());53} catch (Exception e) {54fail(e.getMessage());55}5657BufferedImage image = new BufferedImage(300, 200, BufferedImage.TYPE_INT_ARGB);5859// Test 160JSlider slider = new JSlider(0, Integer.MAX_VALUE - 1, 0);6162slider.setMajorTickSpacing((Integer.MAX_VALUE - 1) / 4);63slider.setPaintTicks(true);6465((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics());6667// Test 268slider = new JSlider(0, Integer.MAX_VALUE - 1, 0);6970slider.setMinorTickSpacing((Integer.MAX_VALUE - 1) / 4);71slider.setPaintTicks(true);7273((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics());7475// Test 376slider = new JSlider(0, Integer.MAX_VALUE - 1, 0);7778slider.setOrientation(JSlider.VERTICAL);79slider.setMajorTickSpacing((Integer.MAX_VALUE - 1) / 4);80slider.setPaintTicks(true);8182((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics());8384// Test 485slider = new JSlider(0, Integer.MAX_VALUE - 1, 0);8687slider.setOrientation(JSlider.VERTICAL);88slider.setMinorTickSpacing((Integer.MAX_VALUE - 1) / 4);89slider.setPaintTicks(true);9091((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics());9293countDownLatch.countDown();94}95}96});9798if (countDownLatch.await(3000, TimeUnit.MILLISECONDS)) {99System.out.println("bug6794831 passed");100} else {101fail("bug6794831 failed");102}103}104105private static void fail(String msg) {106throw new RuntimeException(msg);107}108}109110111