From ba799e09f64a0fc09c56107ce53127d9f9220704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Tue, 13 Feb 2024 13:17:22 +0100 Subject: [PATCH] tests: ignore deprecated java.security --- .../osgi/tests/bundles/BundleInstaller.java | 2 +- .../bundles/EquinoxBundleAdaptTests.java | 1 + .../osgi/tests/bundles/SystemBundleTests.java | 2 +- .../securityadmin/SecurityAdminUnitTests.java | 2 +- .../securityadmin/SecurityManagerTests.java | 51 ++++++++++--------- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java index 49cad28d3b5..518e53fd019 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java @@ -42,7 +42,7 @@ import org.osgi.service.startlevel.StartLevel; import org.osgi.util.tracker.ServiceTracker; -@SuppressWarnings("deprecation") +@SuppressWarnings({ "deprecation", "removal" }) // AccessController public class BundleInstaller { private BundleContext context; private String rootLocation; diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/EquinoxBundleAdaptTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/EquinoxBundleAdaptTests.java index 7cc19ef035c..9aba6c32d3f 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/EquinoxBundleAdaptTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/EquinoxBundleAdaptTests.java @@ -38,6 +38,7 @@ public void testAdapt_Module() throws Exception { } @Test + @SuppressWarnings({ "deprecation", "removal" }) // SecurityManager public void testAdapt_ProtectionDomain() throws Exception { Bundle bundle = installer.installBundle("test"); SecurityManager previousSM = System.getSecurityManager(); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java index dc2cda9f6b6..c639b250574 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java @@ -136,6 +136,7 @@ import org.osgi.service.url.URLConstants; import org.osgi.service.url.URLStreamHandlerService; +@SuppressWarnings({ "deprecation", "removal" }) // SecurityManager public class SystemBundleTests extends AbstractBundleTests { @Test @@ -1981,7 +1982,6 @@ private void doTestJavaProfile(String javaSpecVersion, String expectedEEName, St configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()); Equinox equinox = new Equinox(configuration); equinox.init(); - @SuppressWarnings("deprecation") String osgiEE = equinox.getBundleContext().getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT); // don't do anything; just put the framework back to the RESOLVED state stop(equinox); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityAdminUnitTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityAdminUnitTests.java index dbf284a9dcf..5a5703cdf7a 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityAdminUnitTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityAdminUnitTests.java @@ -51,7 +51,7 @@ import org.osgi.service.permissionadmin.PermissionAdmin; import org.osgi.service.permissionadmin.PermissionInfo; -@SuppressWarnings("deprecation") +@SuppressWarnings({ "deprecation", "removal" }) // AccessControlContext public class SecurityAdminUnitTests extends AbstractBundleTests { private static final PermissionInfo[] SOCKET_INFOS = new PermissionInfo[] { diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java index 5b0ca3ba4d1..1dbb9d04b74 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java @@ -67,6 +67,7 @@ import org.osgi.service.permissionadmin.PermissionInfo; import org.osgi.service.startlevel.StartLevel; +@SuppressWarnings({ "deprecation", "removal" }) // Policy public class SecurityManagerTests extends AbstractBundleTests { private static final PermissionInfo hostFragmentPermission = new PermissionInfo(BundlePermission.class.getName(), "*", "host,fragment"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -82,7 +83,7 @@ public class SecurityManagerTests extends AbstractBundleTests { @Override public void setUp() throws Exception { - assertNull("Cannot test with security manager set", System.getSecurityManager()); + assertNull("Cannot test with security manager set", getSecurityManager()); previousPolicy = Policy.getPolicy(); final Permission allPermission = new AllPermission(); final PermissionCollection allPermissions = new PermissionCollection() { @@ -140,7 +141,7 @@ public void refresh() { @Override public void tearDown() throws Exception { super.tearDown(); - if (System.getSecurityManager() != null) + if (getSecurityManager() != null) System.setSecurityManager(null); Policy.setPolicy(previousPolicy); } @@ -154,7 +155,7 @@ public void testEnableSecurityManager01() throws BundleException { Equinox equinox = new Equinox(configuration); equinox.init(); - assertNotNull("SecurityManager is null", System.getSecurityManager()); //$NON-NLS-1$ + assertNotNull("SecurityManager is null", getSecurityManager()); //$NON-NLS-1$ // should be in the STARTING state assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState()); //$NON-NLS-1$ equinox.start(); @@ -163,7 +164,7 @@ public void testEnableSecurityManager01() throws BundleException { // put the framework back to the RESOLVED state stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ - assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ + assertNull("SecurityManager is not null", getSecurityManager()); //$NON-NLS-1$ } @Test @@ -176,7 +177,7 @@ public void testEnableSecurityManager02() throws BundleException { Equinox equinox = new Equinox(configuration); equinox.init(); - assertNotNull("SecurityManager is null", System.getSecurityManager()); //$NON-NLS-1$ + assertNotNull("SecurityManager is null", getSecurityManager()); //$NON-NLS-1$ // should be in the STARTING state assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState()); //$NON-NLS-1$ @@ -207,7 +208,7 @@ public void testEnableSecurityManager02() throws BundleException { stop(equinox); } assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ - assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ + assertNull("SecurityManager is not null", getSecurityManager()); //$NON-NLS-1$ } @Test @@ -219,7 +220,7 @@ public void testEnableSecurityManager03() throws BundleException { Equinox equinox = new Equinox(configuration); equinox.init(); - assertNotNull("SecurityManager is null", System.getSecurityManager()); //$NON-NLS-1$ + assertNotNull("SecurityManager is null", getSecurityManager()); //$NON-NLS-1$ // should be in the STARTING state assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState()); //$NON-NLS-1$ @@ -273,7 +274,7 @@ public void testEnableSecurityManager03() throws BundleException { stop(equinox); } assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ - assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ + assertNull("SecurityManager is not null", getSecurityManager()); //$NON-NLS-1$ } @Test @@ -285,7 +286,7 @@ public void testEnableSecurityManager04() throws Exception { Equinox equinox = new Equinox(configuration); equinox.init(); - assertNotNull("SecurityManager is null", System.getSecurityManager()); //$NON-NLS-1$ + assertNotNull("SecurityManager is null", getSecurityManager()); //$NON-NLS-1$ // should be in the STARTING state assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState()); //$NON-NLS-1$ @@ -345,7 +346,7 @@ public void testEnableSecurityManager04() throws Exception { stop(equinox); } assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ - assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ + assertNull("SecurityManager is not null", getSecurityManager()); //$NON-NLS-1$ } @Test @@ -357,7 +358,7 @@ public void testEnableSecurityManager05() throws BundleException { Equinox equinox = new Equinox(configuration); equinox.init(); - assertNotNull("SecurityManager is null", System.getSecurityManager()); //$NON-NLS-1$ + assertNotNull("SecurityManager is null", getSecurityManager()); //$NON-NLS-1$ // should be in the STARTING state assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState()); //$NON-NLS-1$ @@ -386,7 +387,11 @@ public void testEnableSecurityManager05() throws BundleException { stop(equinox); } assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ - assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ + assertNull("SecurityManager is not null", getSecurityManager()); //$NON-NLS-1$ + } + + private SecurityManager getSecurityManager() { + return System.getSecurityManager(); } @Test @@ -398,7 +403,7 @@ public void testLocalization01() throws BundleException { configuration.put(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI); Equinox equinox = new Equinox(configuration); equinox.init(); - assertNotNull("SecurityManager is null", System.getSecurityManager()); //$NON-NLS-1$ + assertNotNull("SecurityManager is null", getSecurityManager()); //$NON-NLS-1$ // should be in the STARTING state assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState()); //$NON-NLS-1$ @@ -436,7 +441,7 @@ public void testLocalization01() throws BundleException { stop(equinox); } assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ - assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ + assertNull("SecurityManager is not null", getSecurityManager()); //$NON-NLS-1$ } @Test @@ -447,7 +452,7 @@ public void testBug254600() throws BundleException { configuration.put(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI); Equinox equinox = new Equinox(configuration); equinox.init(); - assertNotNull("SecurityManager is null", System.getSecurityManager()); //$NON-NLS-1$ + assertNotNull("SecurityManager is null", getSecurityManager()); //$NON-NLS-1$ // should be in the STARTING state assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState()); //$NON-NLS-1$ equinox.start(); @@ -482,7 +487,7 @@ public void testBug254600() throws BundleException { stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ - assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ + assertNull("SecurityManager is not null", getSecurityManager()); //$NON-NLS-1$ } @Test @@ -493,7 +498,7 @@ public void testBug287750() throws BundleException { configuration.put(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI); Equinox equinox = new Equinox(configuration); equinox.init(); - assertNotNull("SecurityManager is null", System.getSecurityManager()); //$NON-NLS-1$ + assertNotNull("SecurityManager is null", getSecurityManager()); //$NON-NLS-1$ // should be in the STARTING state assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState()); //$NON-NLS-1$ equinox.start(); @@ -517,7 +522,7 @@ public void testBug287750() throws BundleException { assertEquals("Wrong startlevel", 10, sl.getStartLevel()); //$NON-NLS-1$ stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ - assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ + assertNull("SecurityManager is not null", getSecurityManager()); //$NON-NLS-1$ } @Test @@ -528,7 +533,7 @@ public void testBug367614() throws BundleException { configuration.put(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI); Equinox equinox = new Equinox(configuration); equinox.init(); - assertNotNull("SecurityManager is null", System.getSecurityManager()); //$NON-NLS-1$ + assertNotNull("SecurityManager is null", getSecurityManager()); //$NON-NLS-1$ // should be in the STARTING state assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState()); //$NON-NLS-1$ equinox.start(); @@ -572,7 +577,7 @@ public void testBug367614() throws BundleException { // put the framework back to the RESOLVED state stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ - assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ + assertNull("SecurityManager is not null", getSecurityManager()); //$NON-NLS-1$ } @Test @@ -636,7 +641,7 @@ public void end() { // put the framework back to the RESOLVED state stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ - assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ + assertNull("SecurityManager is not null", getSecurityManager()); //$NON-NLS-1$ } @Test @@ -671,9 +676,9 @@ public void doJava12SecurityManagerSetting(String managerValue, boolean isSecuri try { equinox.init(); if (isSecurityManager) { - assertNotNull("SecurityManager is null", System.getSecurityManager()); //$NON-NLS-1$ + assertNotNull("SecurityManager is null", getSecurityManager()); //$NON-NLS-1$ } else { - assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ + assertNull("SecurityManager is not null", getSecurityManager()); //$NON-NLS-1$ } } catch (BundleException e) { if (isSecurityManager && e.getCause() instanceof UnsupportedOperationException) {