Path: blob/master/test/jdk/javax/swing/JSlider/6794836/bug6794836.java
41153 views
/*1* Copyright (c) 2009, 2016, 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 679483627* @summary BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE28* @author Pavel Porvatov29* @modules java.desktop/javax.swing.plaf.basic:open30* @run main bug679483631*/3233import javax.swing.*;34import javax.swing.plaf.basic.BasicSliderUI;35import java.lang.reflect.Method;36import java.util.Hashtable;3738public class bug6794836 {39public static void main(String[] args) throws Exception {40new bug6794836().run();41}4243public void run() throws Exception {44JSlider slider = new JSlider(0, Integer.MAX_VALUE);4546slider.setPaintLabels(true);4748JLabel minLabel = new JLabel("Min");49JLabel maxLabel = new JLabel("Max");5051Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();5253labelTable.put(Integer.MIN_VALUE, minLabel);54labelTable.put(Integer.MAX_VALUE, maxLabel);5556slider.setLabelTable(labelTable);5758BasicSliderUI ui = (BasicSliderUI) slider.getUI();5960if (invokeMethod("getHighestValueLabel", ui) != maxLabel) {61fail("invalid getHighestValueLabel result");62}6364if (invokeMethod("getLowestValueLabel", ui) != minLabel) {65fail("invalid getLowestValueLabel result");66}6768System.out.println("The bug6794836 test passed");69}7071private static Object invokeMethod(String name, BasicSliderUI ui) throws Exception {72Method method = BasicSliderUI.class.getDeclaredMethod(name, null);7374method.setAccessible(true);7576return method.invoke(ui, null);77}7879private static void fail(String s) {80throw new RuntimeException("Test failed: " + s);81}82}838485