Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JButton/JButtonPaintNPE/JButtonPaintNPE.java
38853 views
/*1* Copyright (c) 2013, 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*/222324import java.awt.Graphics;25import java.awt.Toolkit;26import java.awt.image.BufferedImage;27import java.lang.reflect.InvocationTargetException;2829import javax.swing.JButton;30import javax.swing.JFrame;31import javax.swing.SwingUtilities;3233/**34* @test35* @bug 800991936* @author Sergey Bylokhov37* @library ../../../../lib/testlibrary/38* @build ExtendedRobot39* @run main JButtonPaintNPE40*/41public final class JButtonPaintNPE {4243private static JFrame frame;4445public static void main(final String[] args)46throws InvocationTargetException, InterruptedException {47SwingUtilities.invokeAndWait(() -> {48frame = new JFrame();49frame.add(new JButton() {50@Override51protected void paintComponent(final Graphics g) {52Graphics gg = new BufferedImage(getWidth(), getHeight(),53BufferedImage.TYPE_INT_ARGB).createGraphics();54super.paintComponent(gg);55gg.dispose();56}57});58frame.setSize(300, 300);59frame.setLocationRelativeTo(null);60frame.setVisible(true);61});62sleep();63SwingUtilities.invokeAndWait(() -> {64if (frame != null) {65frame.dispose();66}67});68}6970private static void sleep() {71try {72ExtendedRobot robot = new ExtendedRobot();73robot.waitForIdle(1000);74}catch(Exception ex) {75ex.printStackTrace();76throw new Error("Unexpected Failure");77}78}79}808182