From 5e15415cb9c051531bbd610820cf3a5343c60228 Mon Sep 17 00:00:00 2001 From: Harshitha Onkar Date: Tue, 26 Nov 2024 20:10:48 +0000 Subject: [PATCH] 8344654: Some client tests still expect a SecurityManager after JEP486 Reviewed-by: prr, azvegint --- .../java/awt/Desktop/8064934/bug8064934.java | 9 +-- .../awt/TrayIcon/SystemTrayIconHelper.java | 17 +---- .../awt/a11y/AccessibleComponentTest.java | 1 - .../Independence/IndependenceAWTTest.java | 13 +--- .../Independence/IndependenceSwingTest.java | 13 +--- .../SystemSelectionAWTTest.java | 20 +----- .../SystemSelectionSwingTest.java | 20 +----- .../ButtonArraysEquality.java | 30 ++++---- .../CheckGetMaskForButton.java | 27 +++---- .../java/awt/print/PrinterJob/PrintToDir.java | 12 ---- test/jdk/java/awt/regtesthelpers/Util.java | 42 ++++------- .../MetadataFormatThreadTest.java | 16 +---- .../BadPluginConfigurationTest.sh | 7 +- .../swing/UIDefaults/6795356/bug6795356.java | 70 ------------------- 14 files changed, 46 insertions(+), 251 deletions(-) delete mode 100644 test/jdk/javax/swing/UIDefaults/6795356/bug6795356.java diff --git a/test/jdk/java/awt/Desktop/8064934/bug8064934.java b/test/jdk/java/awt/Desktop/8064934/bug8064934.java index f3a6b4658ad..6d4ffc08f34 100644 --- a/test/jdk/java/awt/Desktop/8064934/bug8064934.java +++ b/test/jdk/java/awt/Desktop/8064934/bug8064934.java @@ -32,23 +32,16 @@ * @build jdk.test.lib.Platform * @run main bug8064934 */ -import jdk.test.lib.Platform; + import java.awt.*; import java.io.File; import java.io.IOException; -import java.security.AccessController; -import java.security.PrivilegedAction; public class bug8064934 { private static final String NO_ASSOCIATION_ERROR_MESSAGE = "Error message: No application is associated with" + " the specified file for this operation."; public static void main(String[] args) { - // This test is intended only for Windows - if (!AccessController.doPrivileged((PrivilegedAction) Platform::isWindows)) { - System.out.println("The test is for Windows platform only"); - return; - } // Test whether Desktop is supported of not if (!Desktop.isDesktopSupported()) { diff --git a/test/jdk/java/awt/TrayIcon/SystemTrayIconHelper.java b/test/jdk/java/awt/TrayIcon/SystemTrayIconHelper.java index ac28281a10c..eaf60655441 100644 --- a/test/jdk/java/awt/TrayIcon/SystemTrayIconHelper.java +++ b/test/jdk/java/awt/TrayIcon/SystemTrayIconHelper.java @@ -27,9 +27,6 @@ import java.awt.geom.Point2D; import java.awt.image.BufferedImage; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -154,17 +151,9 @@ public class SystemTrayIconHelper { return null; } - static Field getField(final Class clz, final String fieldName) { - Field res = null; - try { - res = (Field)AccessController.doPrivileged((PrivilegedExceptionAction) () -> { - Field f = clz.getDeclaredField(fieldName); - f.setAccessible(true); - return f; - }); - } catch (PrivilegedActionException ex) { - ex.printStackTrace(); - } + static Field getField(final Class clz, final String fieldName) throws NoSuchFieldException { + Field res = clz.getDeclaredField(fieldName); + res.setAccessible(true); return res; } diff --git a/test/jdk/java/awt/a11y/AccessibleComponentTest.java b/test/jdk/java/awt/a11y/AccessibleComponentTest.java index 86d41574d6e..ae2943d6994 100644 --- a/test/jdk/java/awt/a11y/AccessibleComponentTest.java +++ b/test/jdk/java/awt/a11y/AccessibleComponentTest.java @@ -23,7 +23,6 @@ */ import java.awt.*; -import java.security.PublicKey; import java.util.concurrent.TimeUnit; import java.util.concurrent.CountDownLatch; diff --git a/test/jdk/java/awt/datatransfer/Independence/IndependenceAWTTest.java b/test/jdk/java/awt/datatransfer/Independence/IndependenceAWTTest.java index 8a1f5f4b19c..2ace3510d1f 100644 --- a/test/jdk/java/awt/datatransfer/Independence/IndependenceAWTTest.java +++ b/test/jdk/java/awt/datatransfer/Independence/IndependenceAWTTest.java @@ -78,17 +78,6 @@ public class IndependenceAWTTest { tf1.requestFocus(); } - public void checkSecurity() { - SecurityManager sm = System.getSecurityManager(); - if (sm == null) { - System.out.println("security manager is not there"); - getPrimaryClipboard(); - } else { - sm.checkPermission(new AWTPermission("accessClipboard")); - getPrimaryClipboard(); - } - } - // Get System Selection i.e. Primary Clipboard private void getPrimaryClipboard() { Properties ps = System.getProperties(); @@ -148,7 +137,7 @@ public class IndependenceAWTTest { } public void doTest() throws Exception { - checkSecurity(); + getPrimaryClipboard(); ExtendedRobot robot = new ExtendedRobot(); robot.waitForIdle(1000); frame.setLocation(100, 100); diff --git a/test/jdk/java/awt/datatransfer/Independence/IndependenceSwingTest.java b/test/jdk/java/awt/datatransfer/Independence/IndependenceSwingTest.java index 550151c0906..4ee7dea6a54 100644 --- a/test/jdk/java/awt/datatransfer/Independence/IndependenceSwingTest.java +++ b/test/jdk/java/awt/datatransfer/Independence/IndependenceSwingTest.java @@ -85,17 +85,6 @@ public class IndependenceSwingTest { tf1.requestFocus(); } - public void checkSecurity() { - SecurityManager sm = System.getSecurityManager(); - if (sm == null) { - System.out.println("security manager is not there"); - getPrimaryClipboard(); - } else { - sm.checkPermission(new AWTPermission("accessClipboard")); - getPrimaryClipboard(); - } - } - // Get System Selection i.e. Primary Clipboard private void getPrimaryClipboard() { Properties ps = System.getProperties(); @@ -155,7 +144,7 @@ public class IndependenceSwingTest { } public void doTest() throws Exception { - checkSecurity(); + getPrimaryClipboard(); ExtendedRobot robot = new ExtendedRobot(); robot.waitForIdle(1000); frame.setLocation(100, 100); diff --git a/test/jdk/java/awt/datatransfer/SystemSelection/SystemSelectionAWTTest.java b/test/jdk/java/awt/datatransfer/SystemSelection/SystemSelectionAWTTest.java index 281ee41f4c7..9d80f0bb676 100644 --- a/test/jdk/java/awt/datatransfer/SystemSelection/SystemSelectionAWTTest.java +++ b/test/jdk/java/awt/datatransfer/SystemSelection/SystemSelectionAWTTest.java @@ -74,24 +74,6 @@ public class SystemSelectionAWTTest { tf1.setText("Selection Testing"); } - // Check whether Security manager is there - public void checkSecurity() { - SecurityManager sm = System.getSecurityManager(); - - if (sm == null) { - System.out.println("security manager is not there"); - getPrimaryClipboard(); - } else { - try { - sm.checkPermission(new AWTPermission("accessClipboard")); - getPrimaryClipboard(); - } catch(SecurityException e) { - clip = null; - System.out.println("Access to System selection is not allowed"); - } - } - } - // Get the contents from the clipboard void getClipboardContent() throws Exception { t = clip.getContents(this); @@ -134,7 +116,7 @@ public class SystemSelectionAWTTest { Point tf1Location = tf1.getLocationOnScreen(); Dimension tf1Size = tf1.getSize(); - checkSecurity(); + getPrimaryClipboard(); if (clip != null) { robot.mouseMove(tf1Location.x + 5, tf1Location.y + tf1Size.height / 2); diff --git a/test/jdk/java/awt/datatransfer/SystemSelection/SystemSelectionSwingTest.java b/test/jdk/java/awt/datatransfer/SystemSelection/SystemSelectionSwingTest.java index 00ecf6fab77..4c409a66408 100644 --- a/test/jdk/java/awt/datatransfer/SystemSelection/SystemSelectionSwingTest.java +++ b/test/jdk/java/awt/datatransfer/SystemSelection/SystemSelectionSwingTest.java @@ -75,24 +75,6 @@ public class SystemSelectionSwingTest { jtf1.setText("Selection Testing"); } - // Check whether Security manager is there - public void checkSecurity() { - SecurityManager sm = System.getSecurityManager(); - - if (sm == null) { - System.out.println("security manager is not there"); - getPrimaryClipboard(); - } else { - try { - sm.checkPermission(new AWTPermission("accessClipboard")); - getPrimaryClipboard(); - } catch(SecurityException e) { - clip = null; - System.out.println("Access to System selection is not allowed"); - } - } - } - // Get the contents from the clipboard void getClipboardContent() throws Exception { t = clip.getContents(this); @@ -136,7 +118,7 @@ public class SystemSelectionSwingTest { Point tf1Location = jtf1.getLocationOnScreen(); Dimension tf1Size = jtf1.getSize(); - checkSecurity(); + getPrimaryClipboard(); if (clip != null) { robot.mouseMove(tf1Location.x + 5, tf1Location.y + tf1Size.height / 2); diff --git a/test/jdk/java/awt/event/InputEvent/ButtonArraysEquality/ButtonArraysEquality.java b/test/jdk/java/awt/event/InputEvent/ButtonArraysEquality/ButtonArraysEquality.java index 384a4ea43a6..718891c21fa 100644 --- a/test/jdk/java/awt/event/InputEvent/ButtonArraysEquality/ButtonArraysEquality.java +++ b/test/jdk/java/awt/event/InputEvent/ButtonArraysEquality/ButtonArraysEquality.java @@ -34,8 +34,6 @@ import java.awt.*; import java.awt.event.*; import java.lang.reflect.*; -import java.security.AccessController; -import java.security.PrivilegedAction; // get array InputEvent.BUTTON_MASK via reflection // get array InputEvent.BUTTON_DOWN_MASK via reflection @@ -52,22 +50,18 @@ public class ButtonArraysEquality { } // getButtonDownMasks() - Object obj = AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { - try { - Class clazz = Class.forName("java.awt.event.InputEvent"); - Method method = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {}); - if (method != null) { - method.setAccessible(true); - return method.invoke(null, (Object[])null); - } - }catch (Exception e){ - throw new RuntimeException("Test failed. Exception occured:", e); - } - return null; - } - }); + Object obj = null; + + try { + Class clazz = Class.forName("java.awt.event.InputEvent"); + Method method = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {}); + if (method != null) { + method.setAccessible(true); + obj = method.invoke(null, (Object[])null); + } + } catch (Exception e) { + throw new RuntimeException("Test failed. Exception occurred:", e); + } int [] buttonDownMasks = new int [Array.getLength(obj)]; checkNullAndPutValuesToArray(buttonDownMasks, obj); diff --git a/test/jdk/java/awt/event/MouseEvent/CheckGetMaskForButton/CheckGetMaskForButton.java b/test/jdk/java/awt/event/MouseEvent/CheckGetMaskForButton/CheckGetMaskForButton.java index 8770a72eae5..fa3f7d9b315 100644 --- a/test/jdk/java/awt/event/MouseEvent/CheckGetMaskForButton/CheckGetMaskForButton.java +++ b/test/jdk/java/awt/event/MouseEvent/CheckGetMaskForButton/CheckGetMaskForButton.java @@ -34,8 +34,6 @@ import java.awt.*; import java.awt.event.InputEvent; import java.lang.reflect.*; -import java.security.AccessController; -import java.security.PrivilegedAction; public class CheckGetMaskForButton{ static Robot robot; @@ -50,22 +48,17 @@ public class CheckGetMaskForButton{ } //get same array via reflection - Object obj = AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { - try { - Class clazz = Class.forName("java.awt.event.InputEvent"); - Method method = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {}); - if (method != null) { - method.setAccessible(true); - return method.invoke(null, (Object[])null); - } - }catch (Exception e){ - throw new RuntimeException("Test failed. Exception occured:", e); - } - return null; + Object obj = null; + try { + Class clazz = Class.forName("java.awt.event.InputEvent"); + Method method = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {}); + if (method != null) { + method.setAccessible(true); + obj = method.invoke(null, (Object[])null); } - }); + } catch (Exception e) { + throw new RuntimeException("Test failed. Exception occured:", e); + } if (obj == null){ throw new RuntimeException("Test failed. The value obtained via reflection is "+obj); diff --git a/test/jdk/java/awt/print/PrinterJob/PrintToDir.java b/test/jdk/java/awt/print/PrinterJob/PrintToDir.java index 4f76647b563..f451f8362e3 100644 --- a/test/jdk/java/awt/print/PrinterJob/PrintToDir.java +++ b/test/jdk/java/awt/print/PrinterJob/PrintToDir.java @@ -37,7 +37,6 @@ import java.awt.print.*; import javax.print.PrintService; import javax.print.attribute.*; import javax.print.attribute.standard.*; -import java.util.PropertyPermission; public class PrintToDir extends Frame implements Printable { @@ -122,17 +121,6 @@ public class PrintToDir extends Frame implements Printable { public static void main(String arg[]) { - SecurityManager security = System.getSecurityManager(); - if (security != null) { - System.out.println("Security manager detected"); - try { - security.checkPermission(new FilePermission("<>", "read,write")); - security.checkPermission(new PropertyPermission("user.dir", "read")); - } catch (SecurityException se) { - System.out.println("Security requirement not obtained. TEST PASSED"); - return; - } - } String[] testStr = {".", ""}; for (int i=0; i weakRef; - - public static void main(String[] args) throws Exception { - - ProtectionDomain domain = new ProtectionDomain(null, null); - - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - - // this initialize ProxyLazyValues - UIManager.getLookAndFeel(); - - return null; - } - }, new AccessControlContext(new ProtectionDomain[]{domain})); - - weakRef = new WeakReference(domain); - domain = null; - - Util.generateOOME(); - - if (weakRef.get() != null) { - throw new RuntimeException("Memory leak found!"); - } - System.out.println("Test passed"); - } -}