6822057: X11 and Win32GraphicsDevice don't clone arrays returned from getConfigurations()

Reviewed-by: prr, hawtin
This commit is contained in:
Andrew Brygin 2009-09-10 13:52:27 +04:00
parent e07c626a48
commit c26aec2e52
4 changed files with 122 additions and 4 deletions

View file

@ -134,7 +134,7 @@ public class X11GraphicsDevice
makeConfigurations(); makeConfigurations();
} }
} }
return configs; return configs.clone();
} }
private void makeConfigurations() { private void makeConfigurations() {

View file

@ -165,7 +165,7 @@ public class Win32GraphicsDevice extends GraphicsDevice implements
if (defaultConfig != null) { if (defaultConfig != null) {
configs = new GraphicsConfiguration[1]; configs = new GraphicsConfiguration[1];
configs[0] = defaultConfig; configs[0] = defaultConfig;
return configs; return configs.clone();
} }
} }
@ -196,7 +196,7 @@ public class Win32GraphicsDevice extends GraphicsDevice implements
configs = new GraphicsConfiguration[v.size()]; configs = new GraphicsConfiguration[v.size()];
v.copyInto(configs); v.copyInto(configs);
} }
return configs; return configs.clone();
} }
/** /**

View file

@ -426,7 +426,7 @@ public class D3DGraphicsDevice extends Win32GraphicsDevice {
if (defaultConfig != null) { if (defaultConfig != null) {
configs = new GraphicsConfiguration[1]; configs = new GraphicsConfiguration[1];
configs[0] = defaultConfig; configs[0] = defaultConfig;
return configs; return configs.clone();
} }
} }
} }

View file

@ -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.");
}
}
}