diff options
author | Paul Pazderski | 2019-06-24 16:16:40 +0000 |
---|---|---|
committer | Paul Pazderski | 2019-07-01 19:53:24 +0000 |
commit | fb73f2aa35729a8277ed9b65ea1e83fb3c35f0b9 (patch) | |
tree | 9ee0c69f6f3a5b9fbb3972404057b819627ec470 | |
parent | 80637e39ea0a087c2b5547f89e9eb4f69088b4e2 (diff) | |
download | eclipse.platform-I20190713-1105.tar.gz eclipse.platform-I20190713-1105.tar.xz eclipse.platform-I20190713-1105.zip |
Bug 547036 - Make AntSecurityManager Java 11 compatibleY20190730-0135Y20190730-0055Y20190729-0900Y20190725-0900Y20190722-0900Y20190718-0905Y20190718-0450Y20190715-2335Y20190715-0900Y20190711-2335Y20190711-0900Y20190708-0900Y20190705-0620Y20190704-0900S4_13_0_M1I20190729-1800I20190728-1800I20190727-1800I20190726-1800I20190725-1800I20190724-1800I20190723-1800I20190722-1800I20190721-1800I20190720-1800I20190719-1800I20190718-1800I20190717-1800I20190716-1800I20190715-1800I20190714-1800I20190713-1800I20190713-1105I20190713-0230I20190712-1800I20190712-0625I20190711-1805I20190711-1120I20190711-0825I20190710-1800I20190710-0610I20190709-1800I20190709-0610I20190708-1800I20190708-1035I20190708-0800I20190707-1800I20190707-0110I20190706-1800I20190705-1800I20190704-1800I20190704-0245I20190703-1800I20190703-0640I20190702-1800I20190702-0930I20190702-0610I20190701-1805
Java 11 removed some of the SecurityManager methods. This change should
make AntSecurityManager compilable with Java 11 and obtain Java 8
compatibility.
Change-Id: I4746064b8f8ef416d2d1369d04617f50fd71994a
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
8 files changed, 313 insertions, 439 deletions
diff --git a/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF b/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF index 6e857db68..3e5ffaf24 100644 --- a/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF +++ b/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.ant.core; singleton:=true -Bundle-Version: 3.5.400.qualifier +Bundle-Version: 3.5.500.qualifier Bundle-Activator: org.eclipse.ant.core.AntCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/ant/org.eclipse.ant.core/pom.xml b/ant/org.eclipse.ant.core/pom.xml index effa7e96c..ad301cb65 100644 --- a/ant/org.eclipse.ant.core/pom.xml +++ b/ant/org.eclipse.ant.core/pom.xml @@ -19,7 +19,7 @@ </parent> <groupId>org.eclipse.ant</groupId> <artifactId>org.eclipse.ant.core</artifactId> - <version>3.5.400-SNAPSHOT</version> + <version>3.5.500-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> <properties> <defaultSigning-excludeInnerJars>true</defaultSigning-excludeInnerJars> diff --git a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/AntSecurityManager.java b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/AntSecurityManager.java index 8f2309b9f..14ec979e6 100644 --- a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/AntSecurityManager.java +++ b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/AntSecurityManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,6 +14,8 @@ package org.eclipse.ant.internal.core; import java.io.FileDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.InetAddress; import java.net.SocketPermission; import java.security.Permission; @@ -50,11 +52,6 @@ public class AntSecurityManager extends SecurityManager { this(securityManager, restrictedThread, true); } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkExit(int) - */ @Override public void checkExit(int status) { // no exit allowed from the restricted thread...System.exit is being called @@ -68,11 +65,17 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkAccept(java.lang.String, int) - */ + @Override + public void checkPermission(Permission perm) { + if (!fAllowSettingSystemProperties && fgPropertyPermission.implies(perm) && fRestrictedThread == Thread.currentThread()) { + // attempting to write a system property + throw new AntSecurityException(); + } + if (fSecurityManager != null) { + fSecurityManager.checkPermission(perm); + } + } + @Override public void checkAccept(String host, int port) { if (fSecurityManager != null) { @@ -80,11 +83,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkAccess(java.lang.Thread) - */ @Override public void checkAccess(Thread t) { if (fSecurityManager != null) { @@ -92,11 +90,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkAccess(java.lang.ThreadGroup) - */ @Override public void checkAccess(ThreadGroup g) { if (fSecurityManager != null) { @@ -104,23 +97,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkAwtEventQueueAccess() - */ - @Override - public void checkAwtEventQueueAccess() { - if (fSecurityManager != null) { - fSecurityManager.checkAwtEventQueueAccess(); - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkConnect(java.lang.String, int, java.lang.Object) - */ @Override public void checkConnect(String host, int port, Object context) { if (fSecurityManager != null) { @@ -128,11 +104,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkConnect(java.lang.String, int) - */ @Override public void checkConnect(String host, int port) { if (fSecurityManager != null) { @@ -140,11 +111,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkCreateClassLoader() - */ @Override public void checkCreateClassLoader() { if (fSecurityManager != null) { @@ -152,11 +118,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkDelete(java.lang.String) - */ @Override public void checkDelete(String file) { if (fSecurityManager != null) { @@ -164,11 +125,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkExec(java.lang.String) - */ @Override public void checkExec(String cmd) { if (fSecurityManager != null) { @@ -176,11 +132,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkLink(java.lang.String) - */ @Override public void checkLink(String lib) { if (fSecurityManager != null) { @@ -188,11 +139,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkListen(int) - */ @Override public void checkListen(int port) { if (fSecurityManager != null) { @@ -200,21 +146,8 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkMemberAccess(java.lang.Class, int) - */ - @Override - public void checkMemberAccess(Class<?> clazz, int which) { - if (fSecurityManager != null) { - fSecurityManager.checkMemberAccess(clazz, which); - } - } - /** - * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress, byte) - * @deprecated + * @deprecated Use {@link #checkPermission(java.security.Permission)} instead */ @Deprecated @Override @@ -228,11 +161,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress) - */ @Override public void checkMulticast(InetAddress maddr) { if (fSecurityManager != null) { @@ -240,11 +168,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPackageAccess(java.lang.String) - */ @Override public void checkPackageAccess(String pkg) { if (fSecurityManager != null) { @@ -252,11 +175,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPackageDefinition(java.lang.String) - */ @Override public void checkPackageDefinition(String pkg) { if (fSecurityManager != null) { @@ -264,11 +182,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPermission(java.security.Permission, java.lang.Object) - */ @Override public void checkPermission(Permission perm, Object context) { if (fSecurityManager != null) { @@ -276,27 +189,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPermission(java.security.Permission) - */ - @Override - public void checkPermission(Permission perm) { - if (!fAllowSettingSystemProperties && fgPropertyPermission.implies(perm) && fRestrictedThread == Thread.currentThread()) { - // attempting to write a system property - throw new AntSecurityException(); - } - if (fSecurityManager != null) { - fSecurityManager.checkPermission(perm); - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPrintJobAccess() - */ @Override public void checkPrintJobAccess() { if (fSecurityManager != null) { @@ -304,11 +196,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPropertiesAccess() - */ @Override public void checkPropertiesAccess() { if (fSecurityManager != null) { @@ -317,11 +204,6 @@ public class AntSecurityManager extends SecurityManager { super.checkPropertiesAccess(); } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) - */ @Override public void checkPropertyAccess(String key) { if (fSecurityManager != null) { @@ -329,11 +211,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkRead(java.io.FileDescriptor) - */ @Override public void checkRead(FileDescriptor fd) { if (fSecurityManager != null) { @@ -341,11 +218,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkRead(java.lang.String, java.lang.Object) - */ @Override public void checkRead(String file, Object context) { if (fSecurityManager != null) { @@ -353,11 +225,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkRead(java.lang.String) - */ @Override public void checkRead(String file) { if (fSecurityManager != null) { @@ -365,11 +232,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkSecurityAccess(java.lang.String) - */ @Override public void checkSecurityAccess(String target) { if (fSecurityManager != null) { @@ -377,11 +239,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkSetFactory() - */ @Override public void checkSetFactory() { if (fSecurityManager != null) { @@ -389,98 +246,178 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkSystemClipboardAccess() - */ @Override - public void checkSystemClipboardAccess() { + public void checkWrite(FileDescriptor fd) { if (fSecurityManager != null) { - fSecurityManager.checkSystemClipboardAccess(); + fSecurityManager.checkWrite(fd); } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object) - */ @Override - public boolean checkTopLevelWindow(Object window) { + public void checkWrite(String file) { if (fSecurityManager != null) { - return fSecurityManager.checkTopLevelWindow(window); + fSecurityManager.checkWrite(file); } - return super.checkTopLevelWindow(window); } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor) - */ @Override - public void checkWrite(FileDescriptor fd) { + public Object getSecurityContext() { if (fSecurityManager != null) { - fSecurityManager.checkWrite(fd); + return fSecurityManager.getSecurityContext(); } + return super.getSecurityContext(); } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkWrite(java.lang.String) - */ @Override - public void checkWrite(String file) { + public ThreadGroup getThreadGroup() { if (fSecurityManager != null) { - fSecurityManager.checkWrite(file); + fSecurityManager.getThreadGroup(); } + return super.getThreadGroup(); } + // -------------------------------------------------------------------------------- + // Below are SecurityManager methods deprecated in Java 9 and removed in Java 10. + // They are accessed through reflections to support Java 8 and 11 at the same time. + // XXX: This also means you must not add @Override annotations even if Eclipse try to add them. + // -------------------------------------------------------------------------------- + /** - * @see java.lang.SecurityManager#getInCheck() - * @deprecated + * @deprecated super class method has been removed in JDK 10 */ @Deprecated - // @Override Super class method has been removed in JDK 10 - public boolean getInCheck() { - try { - SecurityManager.class.getDeclaredMethod("getInCheck", (Class[]) null); //$NON-NLS-1$ - if (fSecurityManager != null) { - return fSecurityManager.getInCheck(); + public void checkAwtEventQueueAccess() { + if (fSecurityManager != null) { + try { + final Method m = fSecurityManager.getClass().getMethod("checkAwtEventQueueAccess"); //$NON-NLS-1$ + m.invoke(fSecurityManager); + } + catch (NoSuchMethodException e) { + logDeprecatedAccess(e); + } + catch (InvocationTargetException e) { + if (e.getTargetException() instanceof RuntimeException) { + throw (RuntimeException) e.getTargetException(); + } + logException(e); + } + catch (IllegalAccessException | IllegalArgumentException e) { + logException(e); } - return super.getInCheck(); - } - catch (NoSuchMethodException | SecurityException e) { - Platform.getLog(AntCorePlugin.getPlugin().getBundle()).log(new Status(IStatus.WARNING, AntCorePlugin.PI_ANTCORE, InternalCoreAntMessages.AntSecurityManager_0)); - return false; } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#getSecurityContext() + /** + * @deprecated super class method has been removed in JDK 10 */ - @Override - public Object getSecurityContext() { + @Deprecated + public void checkMemberAccess(Class<?> clazz, int which) { if (fSecurityManager != null) { - return fSecurityManager.getSecurityContext(); + try { + final Method m = fSecurityManager.getClass().getMethod("checkMemberAccess", Class.class, int.class); //$NON-NLS-1$ + m.invoke(fSecurityManager, clazz, which); + } + catch (NoSuchMethodException e) { + logDeprecatedAccess(e); + } + catch (InvocationTargetException e) { + if (e.getTargetException() instanceof RuntimeException) { + throw (RuntimeException) e.getTargetException(); + } + logException(e); + } + catch (IllegalAccessException | IllegalArgumentException e) { + logException(e); + } } - return super.getSecurityContext(); } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#getThreadGroup() + /** + * @deprecated super class method has been removed in JDK 10 */ - @Override - public ThreadGroup getThreadGroup() { + @Deprecated + public void checkSystemClipboardAccess() { if (fSecurityManager != null) { - fSecurityManager.getThreadGroup(); + try { + final Method m = fSecurityManager.getClass().getMethod("checkSystemClipboardAccess"); //$NON-NLS-1$ + m.invoke(fSecurityManager); + } + catch (NoSuchMethodException e) { + logDeprecatedAccess(e); + } + catch (InvocationTargetException e) { + if (e.getTargetException() instanceof RuntimeException) { + throw (RuntimeException) e.getTargetException(); + } + logException(e); + } + catch (IllegalAccessException | IllegalArgumentException e) { + logException(e); + } } - return super.getThreadGroup(); + } + + /** + * @deprecated super class method has been removed in JDK 10 + */ + @Deprecated + public boolean checkTopLevelWindow(Object window) { + try { + if (fSecurityManager != null) { + final Method m = fSecurityManager.getClass().getMethod("checkTopLevelWindow", Object.class); //$NON-NLS-1$ + return (boolean) m.invoke(fSecurityManager, window); + } + final Method m = SecurityManager.class.getMethod("checkTopLevelWindow", Object.class); //$NON-NLS-1$ + return (boolean) m.invoke(new SecurityManager(), window); + } + catch (NoSuchMethodException e) { + logDeprecatedAccess(e); + } + catch (InvocationTargetException e) { + if (e.getTargetException() instanceof RuntimeException) { + throw (RuntimeException) e.getTargetException(); + } + logException(e); + } + catch (IllegalAccessException | IllegalArgumentException e) { + logException(e); + } + return false; + } + + /** + * @deprecated super class method has been removed in JDK 10 + */ + @Deprecated + public boolean getInCheck() { + try { + if (fSecurityManager != null) { + final Method m = fSecurityManager.getClass().getMethod("getInCheck"); //$NON-NLS-1$ + return (boolean) m.invoke(fSecurityManager); + } + final Method m = SecurityManager.class.getMethod("getInCheck"); //$NON-NLS-1$ + return (boolean) m.invoke(new SecurityManager()); + } + catch (NoSuchMethodException e) { + logDeprecatedAccess(e); + } + catch (InvocationTargetException e) { + if (e.getTargetException() instanceof RuntimeException) { + throw (RuntimeException) e.getTargetException(); + } + logException(e); + } + catch (IllegalAccessException | IllegalArgumentException e) { + logException(e); + } + return false; + } + + private static void logDeprecatedAccess(Throwable e) { + Platform.getLog(AntCorePlugin.getPlugin().getBundle()).log(new Status(IStatus.WARNING, AntCorePlugin.PI_ANTCORE, InternalCoreAntMessages.AntSecurityManager_0, e)); + } + + private static void logException(Throwable e) { + Platform.getLog(AntCorePlugin.getPlugin().getBundle()).log(new Status(IStatus.ERROR, AntCorePlugin.PI_ANTCORE, e.getLocalizedMessage(), e)); } } diff --git a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/InternalCoreAntMessages.properties b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/InternalCoreAntMessages.properties index f5edc6a43..561243320 100644 --- a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/InternalCoreAntMessages.properties +++ b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/InternalCoreAntMessages.properties @@ -26,4 +26,4 @@ AntRunner_Could_not_find_one_or_more_classes__Please_check_the_Ant_classpath__2= AntRunner_Build_Failed__3=BUILD FAILED AntRunner_Already_in_progess=Ant build {0} already in progress. Concurrent Ant builds are possible if you specify to build in a separate JRE. -AntSecurityManager_0=The method SecurityManager#getInCheck was removed in Java 10 +AntSecurityManager_0=The method was removed in Java 10 diff --git a/ant/org.eclipse.ant.launching/META-INF/MANIFEST.MF b/ant/org.eclipse.ant.launching/META-INF/MANIFEST.MF index 97ffed206..099f95a47 100644 --- a/ant/org.eclipse.ant.launching/META-INF/MANIFEST.MF +++ b/ant/org.eclipse.ant.launching/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Localization: plugin Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.ant.launching;singleton:=true -Bundle-Version: 1.2.500.qualifier +Bundle-Version: 1.2.600.qualifier Bundle-Activator: org.eclipse.ant.internal.launching.AntLaunching Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", org.eclipse.debug.core;bundle-version="[3.12.0,4.0.0)", diff --git a/ant/org.eclipse.ant.launching/pom.xml b/ant/org.eclipse.ant.launching/pom.xml index 591d9927b..fc0b131d6 100644 --- a/ant/org.eclipse.ant.launching/pom.xml +++ b/ant/org.eclipse.ant.launching/pom.xml @@ -19,7 +19,7 @@ </parent> <groupId>org.eclipse.ant</groupId> <artifactId>org.eclipse.ant.launching</artifactId> - <version>1.2.500-SNAPSHOT</version> + <version>1.2.600-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> <properties> <defaultSigning-excludeInnerJars>true</defaultSigning-excludeInnerJars> diff --git a/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/AntSecurityManager.java b/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/AntSecurityManager.java index b6c0d1e68..d32eb1890 100644 --- a/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/AntSecurityManager.java +++ b/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/AntSecurityManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,6 +14,8 @@ package org.eclipse.ant.internal.launching.remote; import java.io.FileDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.InetAddress; import java.net.SocketPermission; import java.security.Permission; @@ -21,6 +23,7 @@ import java.util.PropertyPermission; import org.eclipse.ant.core.AntCorePlugin; import org.eclipse.ant.core.AntSecurityException; +import org.eclipse.ant.internal.launching.AntLaunching; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; @@ -50,11 +53,6 @@ public class AntSecurityManager extends SecurityManager { this(securityManager, restrictedThread, true); } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkExit(int) - */ @Override public void checkExit(int status) { // no exit allowed from the restricted thread...System.exit is being called @@ -68,11 +66,17 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkAccept(java.lang.String, int) - */ + @Override + public void checkPermission(Permission perm) { + if (!fAllowSettingSystemProperties && fgPropertyPermission.implies(perm) && fRestrictedThread == Thread.currentThread()) { + // attempting to write a system property + throw new AntSecurityException(); + } + if (fSecurityManager != null) { + fSecurityManager.checkPermission(perm); + } + } + @Override public void checkAccept(String host, int port) { if (fSecurityManager != null) { @@ -80,11 +84,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkAccess(java.lang.Thread) - */ @Override public void checkAccess(Thread t) { if (fSecurityManager != null) { @@ -92,11 +91,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkAccess(java.lang.ThreadGroup) - */ @Override public void checkAccess(ThreadGroup g) { if (fSecurityManager != null) { @@ -104,23 +98,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkAwtEventQueueAccess() - */ - @Override - public void checkAwtEventQueueAccess() { - if (fSecurityManager != null) { - fSecurityManager.checkAwtEventQueueAccess(); - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkConnect(java.lang.String, int, java.lang.Object) - */ @Override public void checkConnect(String host, int port, Object context) { if (fSecurityManager != null) { @@ -128,11 +105,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkConnect(java.lang.String, int) - */ @Override public void checkConnect(String host, int port) { if (fSecurityManager != null) { @@ -140,11 +112,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkCreateClassLoader() - */ @Override public void checkCreateClassLoader() { if (fSecurityManager != null) { @@ -152,11 +119,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkDelete(java.lang.String) - */ @Override public void checkDelete(String file) { if (fSecurityManager != null) { @@ -164,11 +126,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkExec(java.lang.String) - */ @Override public void checkExec(String cmd) { if (fSecurityManager != null) { @@ -176,11 +133,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkLink(java.lang.String) - */ @Override public void checkLink(String lib) { if (fSecurityManager != null) { @@ -188,11 +140,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkListen(int) - */ @Override public void checkListen(int port) { if (fSecurityManager != null) { @@ -200,21 +147,8 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkMemberAccess(java.lang.Class, int) - */ - @Override - public void checkMemberAccess(Class<?> clazz, int which) { - if (fSecurityManager != null) { - fSecurityManager.checkMemberAccess(clazz, which); - } - } - /** - * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress, byte) - * @deprecated + * @deprecated Use {@link #checkPermission(java.security.Permission)} instead */ @Deprecated @Override @@ -228,11 +162,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress) - */ @Override public void checkMulticast(InetAddress maddr) { if (fSecurityManager != null) { @@ -240,11 +169,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPackageAccess(java.lang.String) - */ @Override public void checkPackageAccess(String pkg) { if (fSecurityManager != null) { @@ -252,11 +176,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPackageDefinition(java.lang.String) - */ @Override public void checkPackageDefinition(String pkg) { if (fSecurityManager != null) { @@ -264,11 +183,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPermission(java.security.Permission, java.lang.Object) - */ @Override public void checkPermission(Permission perm, Object context) { if (fSecurityManager != null) { @@ -276,27 +190,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPermission(java.security.Permission) - */ - @Override - public void checkPermission(Permission perm) { - if (!fAllowSettingSystemProperties && fgPropertyPermission.implies(perm) && fRestrictedThread == Thread.currentThread()) { - // attempting to write a system property - throw new AntSecurityException(); - } - if (fSecurityManager != null) { - fSecurityManager.checkPermission(perm); - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPrintJobAccess() - */ @Override public void checkPrintJobAccess() { if (fSecurityManager != null) { @@ -304,11 +197,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPropertiesAccess() - */ @Override public void checkPropertiesAccess() { if (fSecurityManager != null) { @@ -317,11 +205,6 @@ public class AntSecurityManager extends SecurityManager { super.checkPropertiesAccess(); } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) - */ @Override public void checkPropertyAccess(String key) { if (fSecurityManager != null) { @@ -329,11 +212,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkRead(java.io.FileDescriptor) - */ @Override public void checkRead(FileDescriptor fd) { if (fSecurityManager != null) { @@ -341,11 +219,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkRead(java.lang.String, java.lang.Object) - */ @Override public void checkRead(String file, Object context) { if (fSecurityManager != null) { @@ -353,11 +226,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkRead(java.lang.String) - */ @Override public void checkRead(String file) { if (fSecurityManager != null) { @@ -365,11 +233,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkSecurityAccess(java.lang.String) - */ @Override public void checkSecurityAccess(String target) { if (fSecurityManager != null) { @@ -377,11 +240,6 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkSetFactory() - */ @Override public void checkSetFactory() { if (fSecurityManager != null) { @@ -389,99 +247,178 @@ public class AntSecurityManager extends SecurityManager { } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkSystemClipboardAccess() - */ @Override - public void checkSystemClipboardAccess() { + public void checkWrite(FileDescriptor fd) { if (fSecurityManager != null) { - fSecurityManager.checkSystemClipboardAccess(); + fSecurityManager.checkWrite(fd); } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object) - */ @Override - public boolean checkTopLevelWindow(Object window) { + public void checkWrite(String file) { if (fSecurityManager != null) { - return fSecurityManager.checkTopLevelWindow(window); + fSecurityManager.checkWrite(file); } - return super.checkTopLevelWindow(window); } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor) - */ @Override - public void checkWrite(FileDescriptor fd) { + public Object getSecurityContext() { if (fSecurityManager != null) { - fSecurityManager.checkWrite(fd); + return fSecurityManager.getSecurityContext(); } + return super.getSecurityContext(); } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkWrite(java.lang.String) - */ @Override - public void checkWrite(String file) { + public ThreadGroup getThreadGroup() { if (fSecurityManager != null) { - fSecurityManager.checkWrite(file); + fSecurityManager.getThreadGroup(); } + return super.getThreadGroup(); } + // -------------------------------------------------------------------------------- + // Below are SecurityManager methods deprecated in Java 9 and removed in Java 10. + // They are accessed through reflections to support Java 8 and 11 at the same time. + // XXX: This also means you must not add @Override annotations even if Eclipse try to add them. + // -------------------------------------------------------------------------------- + /** - * @see java.lang.SecurityManager#getInCheck() - * @deprecated + * @deprecated super class method has been removed in JDK 10 */ @Deprecated - // @Override Super class method has been removed in JDK 10 - public boolean getInCheck() { - try { - SecurityManager.class.getDeclaredMethod("getInCheck", (Class[]) null); //$NON-NLS-1$ - if (fSecurityManager != null) { - return fSecurityManager.getInCheck(); + public void checkAwtEventQueueAccess() { + if (fSecurityManager != null) { + try { + final Method m = fSecurityManager.getClass().getMethod("checkAwtEventQueueAccess"); //$NON-NLS-1$ + m.invoke(fSecurityManager); + } + catch (NoSuchMethodException e) { + logDeprecatedAccess(e); + } + catch (InvocationTargetException e) { + if (e.getTargetException() instanceof RuntimeException) { + throw (RuntimeException) e.getTargetException(); + } + logException(e); + } + catch (IllegalAccessException | IllegalArgumentException e) { + logException(e); } - return super.getInCheck(); - } - catch (NoSuchMethodException | SecurityException e) { - Platform.getLog(AntCorePlugin.getPlugin().getBundle()).log(new Status(IStatus.WARNING, "org.eclipse.ant.launching", //$NON-NLS-1$ - RemoteAntMessages.getString("AntSecurityManager.getInCheck"))); //$NON-NLS-1$ - return false; } } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#getSecurityContext() + /** + * @deprecated super class method has been removed in JDK 10 */ - @Override - public Object getSecurityContext() { + @Deprecated + public void checkMemberAccess(Class<?> clazz, int which) { if (fSecurityManager != null) { - return fSecurityManager.getSecurityContext(); + try { + final Method m = fSecurityManager.getClass().getMethod("checkMemberAccess", Class.class, int.class); //$NON-NLS-1$ + m.invoke(fSecurityManager, clazz, which); + } + catch (NoSuchMethodException e) { + logDeprecatedAccess(e); + } + catch (InvocationTargetException e) { + if (e.getTargetException() instanceof RuntimeException) { + throw (RuntimeException) e.getTargetException(); + } + logException(e); + } + catch (IllegalAccessException | IllegalArgumentException e) { + logException(e); + } } - return super.getSecurityContext(); } - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#getThreadGroup() + /** + * @deprecated super class method has been removed in JDK 10 */ - @Override - public ThreadGroup getThreadGroup() { + @Deprecated + public void checkSystemClipboardAccess() { if (fSecurityManager != null) { - fSecurityManager.getThreadGroup(); + try { + final Method m = fSecurityManager.getClass().getMethod("checkSystemClipboardAccess"); //$NON-NLS-1$ + m.invoke(fSecurityManager); + } + catch (NoSuchMethodException e) { + logDeprecatedAccess(e); + } + catch (InvocationTargetException e) { + if (e.getTargetException() instanceof RuntimeException) { + throw (RuntimeException) e.getTargetException(); + } + logException(e); + } + catch (IllegalAccessException | IllegalArgumentException e) { + logException(e); + } } - return super.getThreadGroup(); + } + + /** + * @deprecated super class method has been removed in JDK 10 + */ + @Deprecated + public boolean checkTopLevelWindow(Object window) { + try { + if (fSecurityManager != null) { + final Method m = fSecurityManager.getClass().getMethod("checkTopLevelWindow", Object.class); //$NON-NLS-1$ + return (boolean) m.invoke(fSecurityManager, window); + } + final Method m = SecurityManager.class.getMethod("checkTopLevelWindow", Object.class); //$NON-NLS-1$ + return (boolean) m.invoke(new SecurityManager(), window); + } + catch (NoSuchMethodException e) { + logDeprecatedAccess(e); + } + catch (InvocationTargetException e) { + if (e.getTargetException() instanceof RuntimeException) { + throw (RuntimeException) e.getTargetException(); + } + logException(e); + } + catch (IllegalAccessException | IllegalArgumentException e) { + logException(e); + } + return false; + } + + /** + * @deprecated super class method has been removed in JDK 10 + */ + @Deprecated + public boolean getInCheck() { + try { + if (fSecurityManager != null) { + final Method m = fSecurityManager.getClass().getMethod("getInCheck"); //$NON-NLS-1$ + return (boolean) m.invoke(fSecurityManager); + } + final Method m = SecurityManager.class.getMethod("getInCheck"); //$NON-NLS-1$ + return (boolean) m.invoke(new SecurityManager()); + } + catch (NoSuchMethodException e) { + logDeprecatedAccess(e); + } + catch (InvocationTargetException e) { + if (e.getTargetException() instanceof RuntimeException) { + throw (RuntimeException) e.getTargetException(); + } + logException(e); + } + catch (IllegalAccessException | IllegalArgumentException e) { + logException(e); + } + return false; + } + + private static void logDeprecatedAccess(Throwable e) { + Platform.getLog(AntCorePlugin.getPlugin().getBundle()).log(new Status(IStatus.WARNING, AntLaunching.PLUGIN_ID, RemoteAntMessages.getString("AntSecurityManager.deprecatedMethod"), e)); //$NON-NLS-1$ + } + + private static void logException(Throwable e) { + Platform.getLog(AntCorePlugin.getPlugin().getBundle()).log(new Status(IStatus.ERROR, AntLaunching.PLUGIN_ID, e.getLocalizedMessage(), e)); } } diff --git a/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/RemoteAntMessages.properties b/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/RemoteAntMessages.properties index 683ce1fa8..cc0a4b4e2 100644 --- a/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/RemoteAntMessages.properties +++ b/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/RemoteAntMessages.properties @@ -79,4 +79,4 @@ RemoteAntBuildLogger._seconds_4=\ seconds RemoteAntBuildLogger._second_5=\ second RemoteAntBuildLogger._milliseconds_6=\ milliseconds -AntSecurityManager.getInCheck=The method SecurityManager#getInCheck was removed in Java 10 +AntSecurityManager.deprecatedMethod=The method was removed in Java 10 |