undefect. CWE-407 — 63 sites patched across 27 ecosystems

Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
This commit is contained in:
russell@unturf.com 2026-03-26 17:11:57 -04:00
commit 0a580b313d
70422 changed files with 17213626 additions and 0 deletions

View file

@ -0,0 +1,80 @@
/*
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @key headful
* @bug 8007146 8213119
* @summary [macosx] Setting a display mode crashes JDK under VNC
*/
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
public class CheckDisplayModes {
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] allDevices = ge.getScreenDevices();
for (GraphicsDevice gd : allDevices) {
System.out.println("Available screen device: " + gd.getIDstring());
}
for (GraphicsDevice graphicDevice : allDevices) {
System.out.println("On screen device " + graphicDevice.getIDstring());
if (!graphicDevice.isDisplayChangeSupported()) {
System.err.println("Display mode change is not supported on this host. Test is considered passed.");
continue;
}
DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
System.out.println("Default display mode: " + defaultDisplayMode);
checkDisplayMode(defaultDisplayMode);
graphicDevice.setDisplayMode(defaultDisplayMode);
DisplayMode[] displayModes = graphicDevice.getDisplayModes();
for (int i = 0; i < displayModes.length; i++) {
System.out.println("displayModes[" + i + "] = " + displayModes[i]);
}
boolean isDefaultDisplayModeIncluded = false;
for (DisplayMode displayMode : displayModes) {
System.out.println("Attempting display mode " + displayMode);
checkDisplayMode(displayMode);
graphicDevice.setDisplayMode(displayMode);
if (defaultDisplayMode.equals(displayMode)) {
isDefaultDisplayModeIncluded = true;
}
}
if (!isDefaultDisplayModeIncluded) {
throw new RuntimeException("Default display mode is not included");
}
}
}
static void checkDisplayMode(DisplayMode displayMode) {
if (displayMode == null || displayMode.getWidth() <= 1 || displayMode.getHeight() <= 1) {
throw new RuntimeException("invalid display mode");
}
}
}

View file

@ -0,0 +1,118 @@
/*
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @key headful
* @bug 6822057 7124400 8059848 8198613
*
* @summary Test verifies that list of supported graphics configurations
* can not be changed via modification of elements of an array
* returned by getConfiguration() method.
*
* @run main CloneConfigsTest
* @run main/othervm -Dsun.java2d.d3d=true CloneConfigsTest
* @run main/othervm -Dsun.java2d.noddraw=true CloneConfigsTest
*/
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
public class CloneConfigsTest {
public static void main(String[] args) {
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] devices = env.getScreenDevices();
GraphicsConfiguration c = new TestConfig();
for (GraphicsDevice gd : devices) {
System.out.println("Device: " + gd);
GraphicsConfiguration[] configs = gd.getConfigurations();
for (int i = 0; i < configs.length; i++) {
GraphicsConfiguration gc = configs[i];
System.out.println("\tConfig: " + gc);
configs[i] = c;
}
// verify whether array of configs was modified
configs = gd.getConfigurations();
for (GraphicsConfiguration gc : configs) {
if (gc == c) {
throw new RuntimeException("Test failed.");
}
}
System.out.println("Test passed.");
}
}
private static class TestConfig extends GraphicsConfiguration {
@Override
public GraphicsDevice getDevice() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public BufferedImage createCompatibleImage(int width, int height) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ColorModel getColorModel() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ColorModel getColorModel(int transparency) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public AffineTransform getDefaultTransform() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public AffineTransform getNormalizingTransform() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Rectangle getBounds() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @key headful
* @bug 8022810 8196616
* @summary Cannot list all the available display modes on Ubuntu linux in case
* of two screen devices
* @run main CompareToXrandrTest
*/
import java.awt.GraphicsEnvironment;
import java.awt.GraphicsDevice;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class CompareToXrandrTest {
public static void main(String[] args) throws Exception {
if (!new File("/usr/bin/xrandr").exists()) {
System.out.println("No xrandr tool to compare");
return;
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
Runtime.getRuntime().exec("/usr/bin/xrandr").getInputStream()))) {
Pattern pattern = Pattern.compile("^\\s*(\\d+x\\d+)");
for (GraphicsDevice d : GraphicsEnvironment
.getLocalGraphicsEnvironment().getScreenDevices()) {
Set<String> xrandrModes = reader.lines().map(pattern::matcher)
.filter(Matcher::find).map(m -> m.group(1))
.collect(Collectors.toSet());
Set<String> javaModes = Arrays.stream(d.getDisplayModes())
.map(m -> m.getWidth() + "x" + m.getHeight())
.collect(Collectors.toSet());
if (!xrandrModes.equals(javaModes)) {
throw new RuntimeException("Failed");
} else {
System.out.println("Device " + d + ": " + javaModes.size() +
" modes found.");
}
}
}
}
}

View file

@ -0,0 +1,303 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.awt.Color;
import java.awt.Component;
import java.awt.DisplayMode;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Transparency;
import java.awt.Window;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
/**
* @test
* @bug 4836241 6364134 8232200 8252133
* @key headful
* @summary verify that images are restored correctly after display mode
* switches and that no other rendering or crash problems occur
* @run main/timeout=500 CycleDMImage
*/
public class CycleDMImage extends Component implements Runnable, KeyListener {
/**
* This test cycles through all available display modes, waiting after
* each call to setDisplayMode() to ensure that the new one is active
* before proceeding on to the next one. The Component is filled with
* a green background color and then compatible images of all 3
* Transparency types are copied to the screen. The results of these
* operations are checked (using Robot) and the test fails if any of the
* rendering is wrong in any of the DisplayModes. The purpose of this
* test is to ensure that display mode switches do not cause problems
* with image restoration (or other rendering operations).
*/
boolean painted = false;
boolean earlyExit = false;
Image rImage = null, wImage = null, bImage = null;
int imgSize = 10;
static Robot robot = null;
volatile static boolean done = false;
static String errorMessage = null;
public synchronized void paint(Graphics g) {
if (!painted) {
painted = true;
(new Thread(this)).start();
}
if (rImage == null) {
GraphicsConfiguration gc = getGraphicsConfiguration();
rImage = gc.createCompatibleImage(imgSize, imgSize);
wImage = gc.createCompatibleImage(imgSize, imgSize,
Transparency.BITMASK);
bImage = gc.createCompatibleImage(imgSize, imgSize,
Transparency.TRANSLUCENT);
Graphics imgGraphics = rImage.getGraphics();
imgGraphics.setColor(Color.red);
imgGraphics.fillRect(0, 0, imgSize, imgSize);
imgGraphics = wImage.getGraphics();
imgGraphics.setColor(Color.white);
imgGraphics.fillRect(0, 0, imgSize, imgSize);
imgGraphics = bImage.getGraphics();
imgGraphics.setColor(Color.blue);
imgGraphics.fillRect(0, 0, imgSize, imgSize);
}
g.setColor(Color.green);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(rImage, 0, 0, this);
g.drawImage(wImage, imgSize, 0, this);
g.drawImage(bImage, imgSize*2, 0, this);
g.drawImage(rImage, 0, getHeight()-imgSize, null);
g.drawImage(rImage, getWidth()-imgSize, getHeight()-imgSize, null);
g.drawImage(rImage, getWidth()-imgSize, 0, null);
}
static void delay(long ms) {
try {
Thread.sleep(ms);
} catch (Exception e) {}
}
public boolean checkResult(DisplayMode dm) {
Rectangle bounds = getGraphicsConfiguration().getBounds();
int pixels[] = new int[imgSize * 4];
BufferedImage clientPixels =
robot.createScreenCapture(new Rectangle(bounds.x, bounds.y,
imgSize*4, 1));
clientPixels.getRGB(0, 0, imgSize * 4, 1, pixels, 0, getWidth());
// Now check the results. We expect: imgSize blocks of r/w/b/g
int colors[] = {0xffff0000, 0xffffffff, 0xff0000ff, 0xff00ff00};
for (int color = 0; color < 4; ++color) {
for (int i = 0; i < imgSize; ++i) {
int pixelIndex = imgSize * color + i;
if (pixels[pixelIndex] != colors[color]) {
errorMessage = "\n DisplayMode(" +
dm.getWidth() + " x " +
dm.getHeight() + " x " +
dm.getBitDepth() + "bpp x " +
dm.getRefreshRate() +
")\n Pixel " + i +
": Expected " +
Integer.toHexString(colors[color]) +
", got " +
Integer.toHexString(pixels[pixelIndex]) +
" at " + i;
return false;
}
}
}
return true;
}
boolean displayModesEqual(DisplayMode dm1, DisplayMode dm2) {
if (dm1.equals(dm2)) {
return true;
}
// not enough - check whether the modes are equal except for
// refreshRate, if either mode has REFRESH_RATE_UNKNOWN
// value for this parameter
if (dm1.getWidth() != dm2.getWidth() ||
dm1.getHeight() != dm2.getHeight() ||
dm1.getBitDepth() != dm2.getBitDepth())
{
// core parameters must match
return false;
}
// Now we know that w1 == w2, h1 == h2, and d1 == d2; must be the
// case that the refresh rates do not match.
// Is either one REFRESH_RATE_UNKNOWN?
if (dm1.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN ||
dm2.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN)
{
return true;
}
return false;
}
public void run() {
GraphicsDevice gd = getGraphicsConfiguration().getDevice();
gd.setFullScreenWindow((Window) getParent());
// First, delay a bit just to let the fullscreen window
// settle down before switching display modes
robot.waitForIdle();
delay(1000);
if (!gd.isDisplayChangeSupported()) {
System.err.println("Display change is not supported,"+
" the test is considered passed.");
finished();
return;
}
// We are really only interested in unique w/h/d resolutions
// and it would be nice to skip the myriad of refresh rate
// varations, so let us construct a subset that contains
// only those DisplayModes with unique w/h/d values
// Also, due to a current bug (4837228), we should skip the
// 24-bit depths since attempting to create bitmask-transparent
// ddraw images can cause the test to crash (we should change this
// test to include that depth when the bug is fixed).
ArrayList<DisplayMode> dmSubset = new ArrayList<>();
for (final DisplayMode dm : gd.getDisplayModes()) {
boolean skip = false;
for (final DisplayMode dmUnique : dmSubset) {
int bitDepth = dm.getBitDepth();
int width = dm.getWidth();
int height = dm.getHeight();
if (bitDepth == 24 || width <= 800 || height <= 600 ||
(dmUnique.getWidth() == width &&
dmUnique.getHeight() == height &&
dmUnique.getBitDepth() == bitDepth)) {
skip = true;
break;
}
}
if (!skip) {
dmSubset.add(dm);
}
}
// Now, cycle through the display modes one-by-one. For
// each new display mode, delay until we detect that the
// new mode == the current mode. Then delay an additional
// second (to allow any repaints to occur)
for (DisplayMode newDM : dmSubset) {
gd.setDisplayMode(newDM);
while (!displayModesEqual(newDM, gd.getDisplayMode())) {
delay(100);
}
// Delay another few seconds after the new display mode is active
delay(4000);
// Check the rendering results
if (!checkResult(newDM)) {
finished();
return;
}
// Escape out if requested by the user
if (earlyExit) {
System.out.println("Exiting test early, by request");
System.exit(0);
}
}
// Done with test; if we got here, we passed
System.out.println("Passed");
finished();
}
public static void finished() {
synchronized (CycleDMImage.class) {
done = true;
CycleDMImage.class.notify();
}
}
/**
* KeyListener methods; these provide a way for a user to escape out of
* a potentially lengthy test.
*/
public void keyTyped(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
earlyExit = true;
}
}
public void keyReleased(KeyEvent e) {
}
public static void main(String args[]) throws Exception {
robot = new Robot();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
for (final GraphicsDevice gd: ge.getScreenDevices()) {
if (!gd.isFullScreenSupported()) {
System.err.println("FullScreen mode is not supported,"+
" the test is considered passed.");
continue;
}
done = false;
DisplayMode currentDM = gd.getDisplayMode();
Frame frame = new Frame(gd.getDefaultConfiguration());
try {
frame.setSize(400, 400);
frame.setUndecorated(true);
CycleDMImage comp = new CycleDMImage();
frame.addKeyListener(comp);
frame.add(comp);
frame.setVisible(true);
// Sleep awaiting frame disposal
synchronized (CycleDMImage.class) {
while (!done) {
try {
CycleDMImage.class.wait(100);
} catch (InterruptedException e) {
}
}
}
} finally {
gd.setDisplayMode(currentDM);
gd.setFullScreenWindow(null);
frame.dispose();
}
if (errorMessage != null) {
throw new RuntimeException(errorMessage);
}
// delay a bit just to let the fullscreen window disposing complete
// before switching to next display
delay(10000);
}
}
}

View file

@ -0,0 +1,72 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8267430
* @key headful
* @summary verify setting a display mode with unknow refresh rate works
*/
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
public class UnknownRefrshRateTest {
public static void main(String[] args) throws Exception {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] devices = ge.getScreenDevices();
for (GraphicsDevice d : devices) {
if (!d.isDisplayChangeSupported()) {
continue;
}
DisplayMode odm = d.getDisplayMode();
System.out.println("device=" + d + " original mode=" + odm);
DisplayMode[] modes = d.getDisplayModes();
System.out.println("There are " + modes.length + " modes.");
try {
for (int i=0; i<modes.length; i++) {
DisplayMode mode = modes[i];
System.out.println("copying from mode " + i + " : " + mode);
int w = mode.getWidth();
int h = mode.getHeight();
int bpp = mode.getBitDepth();
int refRate = DisplayMode.REFRESH_RATE_UNKNOWN;
DisplayMode newMode = new DisplayMode(w, h, bpp, refRate);
d.setDisplayMode(newMode);
Thread.sleep(2000);
System.out.println("set " + d.getDisplayMode());
}
} finally {
System.out.println("restoring original mode"+odm);
d.setDisplayMode(odm);
Thread.sleep(10000);
}
}
}
}

View file

@ -0,0 +1,65 @@
/*
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
/**
* @test
* @key headful
* @bug 8359266
* @summary Tests for a race condition when setting a full-screen window
*/
public final class FullScreenWindowRace {
public static void main(String[] args) throws InterruptedException {
Window window = new Window(null);
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice();
Thread thread = new Thread(() -> {
while (gd.getFullScreenWindow() == null) {
// Busy wait - can be optimized away without volatile
}
});
thread.setDaemon(true);
thread.start();
// Give thread some time to start and begin the loop
Thread.sleep(2000);
gd.setFullScreenWindow(window);
thread.join(15000);
boolean alive = thread.isAlive();
gd.setFullScreenWindow(null);
window.dispose();
if (alive) {
throw new RuntimeException("Full screen window is NOT detected!");
}
}
}

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.awt.*;
import java.awt.image.BufferedImage;
/*
* @test
* @summary Check that GraphicsDevice methods do not throw unexpected
* exceptions in headless mode
* @run main/othervm -Djava.awt.headless=true HeadlessGraphicsDevice
*/
public class HeadlessGraphicsDevice {
public static void main(String args[]) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Graphics2D gd = ge.createGraphics(new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR));
GraphicsConfiguration gc = gd.getDeviceConfiguration();
GraphicsDevice gdev = gc.getDevice();
for (GraphicsConfiguration gcl : gdev.getConfigurations())
gcl.toString();
gdev.getDefaultConfiguration().toString();
gdev.getIDstring();
if (gdev.getType() != GraphicsDevice.TYPE_IMAGE_BUFFER)
throw new RuntimeException("Created GraphicsDevice that should be IMAGE_BUFFER but it isn't");
}
}

View file

@ -0,0 +1,100 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
/**
* @test
* @key headful
* @bug 8019587
* @author Sergey Bylokhov
* @library /lib/client/
* @build ExtendedRobot
* @run main IncorrectDisplayModeExitFullscreen
*/
public class IncorrectDisplayModeExitFullscreen {
static ExtendedRobot robot;
public static void main(final String[] args) {
final GraphicsDevice[] devices =
GraphicsEnvironment.getLocalGraphicsEnvironment()
.getScreenDevices();
if (devices.length < 2 || devices[0].getDisplayModes().length < 2
|| !devices[0].isDisplayChangeSupported()
|| !devices[0].isFullScreenSupported()
|| !devices[1].isFullScreenSupported()) {
System.err.println("Testcase is not applicable");
return;
}
final DisplayMode defaultDM = devices[0].getDisplayMode();
final DisplayMode[] dms = devices[0].getDisplayModes();
DisplayMode nonDefaultDM = null;
for (final DisplayMode dm : dms) {
if (!dm.equals(defaultDM)) {
nonDefaultDM = dm;
break;
}
}
if (nonDefaultDM == null) {
System.err.println("Testcase is not applicable");
return;
}
try {
robot = new ExtendedRobot();
}catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException("Unexpected failure");
}
final Frame frame = new Frame();
frame.setBackground(Color.GREEN);
frame.setUndecorated(true);
try {
devices[0].setFullScreenWindow(frame);
sleep();
devices[0].setDisplayMode(nonDefaultDM);
sleep();
devices[1].setFullScreenWindow(frame);
sleep();
if (!defaultDM.equals(devices[0].getDisplayMode())) {
throw new RuntimeException("DisplayMode is not restored");
}
} finally {
// cleaning up
devices[0].setFullScreenWindow(null);
devices[1].setFullScreenWindow(null);
frame.dispose();
}
}
private static void sleep() {
robot.waitForIdle(1500);
}
}