Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JSlider/6794831/bug6794831.java
38855 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/* @test24* @bug 679483125* @summary Infinite loop while painting ticks on Slider with maximum=MAX_INT26* @author Pavel Porvatov27@run main bug679483128*/2930import javax.swing.*;31import javax.swing.plaf.basic.BasicSliderUI;32import java.awt.image.BufferedImage;33import java.lang.reflect.InvocationTargetException;34import java.util.concurrent.CountDownLatch;35import java.util.concurrent.TimeUnit;3637public class bug6794831 {38private final CountDownLatch countDownLatch = new CountDownLatch(1);3940public static void main(String args[])41throws InterruptedException, InvocationTargetException {42new bug6794831().run();43}4445private void run() throws InterruptedException, InvocationTargetException {46SwingUtilities.invokeAndWait(new Runnable() {47public void run() {48for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) {49try {50UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());51} catch (Exception e) {52fail(e.getMessage());53}5455BufferedImage image = new BufferedImage(300, 200, BufferedImage.TYPE_INT_ARGB);5657// Test 158JSlider slider = new JSlider(0, Integer.MAX_VALUE - 1, 0);5960slider.setMajorTickSpacing((Integer.MAX_VALUE - 1) / 4);61slider.setPaintTicks(true);6263((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics());6465// Test 266slider = new JSlider(0, Integer.MAX_VALUE - 1, 0);6768slider.setMinorTickSpacing((Integer.MAX_VALUE - 1) / 4);69slider.setPaintTicks(true);7071((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics());7273// Test 374slider = new JSlider(0, Integer.MAX_VALUE - 1, 0);7576slider.setOrientation(JSlider.VERTICAL);77slider.setMajorTickSpacing((Integer.MAX_VALUE - 1) / 4);78slider.setPaintTicks(true);7980((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics());8182// Test 483slider = new JSlider(0, Integer.MAX_VALUE - 1, 0);8485slider.setOrientation(JSlider.VERTICAL);86slider.setMinorTickSpacing((Integer.MAX_VALUE - 1) / 4);87slider.setPaintTicks(true);8889((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics());9091countDownLatch.countDown();92}93}94});9596if (countDownLatch.await(3000, TimeUnit.MILLISECONDS)) {97System.out.println("bug6794831 passed");98} else {99fail("bug6794831 failed");100}101}102103private static void fail(String msg) {104throw new RuntimeException(msg);105}106}107108109