6822057: X11 and Win32GraphicsDevice don't clone arrays returned from getConfigurations()
Reviewed-by: prr, hawtin
--- a/jdk/src/solaris/classes/sun/awt/X11GraphicsDevice.java Thu Sep 10 13:35:28 2009 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11GraphicsDevice.java Thu Sep 10 13:52:27 2009 +0400
@@ -134,7 +134,7 @@
makeConfigurations();
}
}
- return configs;
+ return configs.clone();
}
private void makeConfigurations() {
--- a/jdk/src/windows/classes/sun/awt/Win32GraphicsDevice.java Thu Sep 10 13:35:28 2009 +0400
+++ b/jdk/src/windows/classes/sun/awt/Win32GraphicsDevice.java Thu Sep 10 13:52:27 2009 +0400
@@ -165,7 +165,7 @@
if (defaultConfig != null) {
configs = new GraphicsConfiguration[1];
configs[0] = defaultConfig;
- return configs;
+ return configs.clone();
}
}
@@ -196,7 +196,7 @@
configs = new GraphicsConfiguration[v.size()];
v.copyInto(configs);
}
- return configs;
+ return configs.clone();
}
/**
--- a/jdk/src/windows/classes/sun/java2d/d3d/D3DGraphicsDevice.java Thu Sep 10 13:35:28 2009 +0400
+++ b/jdk/src/windows/classes/sun/java2d/d3d/D3DGraphicsDevice.java Thu Sep 10 13:52:27 2009 +0400
@@ -426,7 +426,7 @@
if (defaultConfig != null) {
configs = new GraphicsConfiguration[1];
configs[0] = defaultConfig;
- return configs;
+ return configs.clone();
}
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/GraphicsDevice/CloneConfigsTest.java Thu Sep 10 13:52:27 2009 +0400
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6822057
+ *
+ * @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.opengl=True 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.");
+ }
+
+ }
+
+}