Bug 547036 - Make AntSecurityManager Java 11 compatible

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>
diff --git a/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF b/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF
index 6e857db..3e5ffaf 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 @@
 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 effa7e9..ad301cb 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 8f2309b..14ec979 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 @@
 		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 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkAccess(java.lang.Thread)
-	 */
 	@Override
 	public void checkAccess(Thread t) {
 		if (fSecurityManager != null) {
@@ -92,11 +90,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkAccess(java.lang.ThreadGroup)
-	 */
 	@Override
 	public void checkAccess(ThreadGroup g) {
 		if (fSecurityManager != null) {
@@ -104,23 +97,6 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkCreateClassLoader()
-	 */
 	@Override
 	public void checkCreateClassLoader() {
 		if (fSecurityManager != null) {
@@ -152,11 +118,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkDelete(java.lang.String)
-	 */
 	@Override
 	public void checkDelete(String file) {
 		if (fSecurityManager != null) {
@@ -164,11 +125,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkExec(java.lang.String)
-	 */
 	@Override
 	public void checkExec(String cmd) {
 		if (fSecurityManager != null) {
@@ -176,11 +132,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkLink(java.lang.String)
-	 */
 	@Override
 	public void checkLink(String lib) {
 		if (fSecurityManager != null) {
@@ -188,11 +139,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkListen(int)
-	 */
 	@Override
 	public void checkListen(int port) {
 		if (fSecurityManager != null) {
@@ -200,21 +146,8 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress)
-	 */
 	@Override
 	public void checkMulticast(InetAddress maddr) {
 		if (fSecurityManager != null) {
@@ -240,11 +168,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkPackageAccess(java.lang.String)
-	 */
 	@Override
 	public void checkPackageAccess(String pkg) {
 		if (fSecurityManager != null) {
@@ -252,11 +175,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkPackageDefinition(java.lang.String)
-	 */
 	@Override
 	public void checkPackageDefinition(String pkg) {
 		if (fSecurityManager != null) {
@@ -264,11 +182,6 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkPropertiesAccess()
-	 */
 	@Override
 	public void checkPropertiesAccess() {
 		if (fSecurityManager != null) {
@@ -317,11 +204,6 @@
 		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 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkRead(java.io.FileDescriptor)
-	 */
 	@Override
 	public void checkRead(FileDescriptor fd) {
 		if (fSecurityManager != null) {
@@ -341,11 +218,6 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkRead(java.lang.String)
-	 */
 	@Override
 	public void checkRead(String file) {
 		if (fSecurityManager != null) {
@@ -365,11 +232,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkSecurityAccess(java.lang.String)
-	 */
 	@Override
 	public void checkSecurityAccess(String target) {
 		if (fSecurityManager != null) {
@@ -377,11 +239,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkSetFactory()
-	 */
 	@Override
 	public void checkSetFactory() {
 		if (fSecurityManager != null) {
@@ -389,36 +246,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkSystemClipboardAccess()
-	 */
-	@Override
-	public void checkSystemClipboardAccess() {
-		if (fSecurityManager != null) {
-			fSecurityManager.checkSystemClipboardAccess();
-		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object)
-	 */
-	@Override
-	public boolean checkTopLevelWindow(Object window) {
-		if (fSecurityManager != null) {
-			return fSecurityManager.checkTopLevelWindow(window);
-		}
-		return super.checkTopLevelWindow(window);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor)
-	 */
 	@Override
 	public void checkWrite(FileDescriptor fd) {
 		if (fSecurityManager != null) {
@@ -426,11 +253,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkWrite(java.lang.String)
-	 */
 	@Override
 	public void checkWrite(String file) {
 		if (fSecurityManager != null) {
@@ -438,31 +260,6 @@
 		}
 	}
 
-	/**
-	 * @see java.lang.SecurityManager#getInCheck()
-	 * @deprecated
-	 */
-	@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();
-			}
-			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()
-	 */
 	@Override
 	public Object getSecurityContext() {
 		if (fSecurityManager != null) {
@@ -471,11 +268,6 @@
 		return super.getSecurityContext();
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#getThreadGroup()
-	 */
 	@Override
 	public ThreadGroup getThreadGroup() {
 		if (fSecurityManager != null) {
@@ -483,4 +275,149 @@
 		}
 		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.
+	// --------------------------------------------------------------------------------
+
+	/**
+	 * @deprecated super class method has been removed in JDK 10
+	 */
+	@Deprecated
+	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);
+			}
+		}
+	}
+
+	/**
+	 * @deprecated super class method has been removed in JDK 10
+	 */
+	@Deprecated
+	public void checkMemberAccess(Class<?> clazz, int which) {
+		if (fSecurityManager != null) {
+			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);
+			}
+		}
+	}
+
+	/**
+	 * @deprecated super class method has been removed in JDK 10
+	 */
+	@Deprecated
+	public void checkSystemClipboardAccess() {
+		if (fSecurityManager != null) {
+			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);
+			}
+		}
+	}
+
+	/**
+	 * @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 f5edc6a..5612433 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_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 97ffed2..099f95a 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-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 591d992..fc0b131 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 b6c0d1e..d32eb18 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 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 @@
 		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 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkAccess(java.lang.Thread)
-	 */
 	@Override
 	public void checkAccess(Thread t) {
 		if (fSecurityManager != null) {
@@ -92,11 +91,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkAccess(java.lang.ThreadGroup)
-	 */
 	@Override
 	public void checkAccess(ThreadGroup g) {
 		if (fSecurityManager != null) {
@@ -104,23 +98,6 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkCreateClassLoader()
-	 */
 	@Override
 	public void checkCreateClassLoader() {
 		if (fSecurityManager != null) {
@@ -152,11 +119,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkDelete(java.lang.String)
-	 */
 	@Override
 	public void checkDelete(String file) {
 		if (fSecurityManager != null) {
@@ -164,11 +126,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkExec(java.lang.String)
-	 */
 	@Override
 	public void checkExec(String cmd) {
 		if (fSecurityManager != null) {
@@ -176,11 +133,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkLink(java.lang.String)
-	 */
 	@Override
 	public void checkLink(String lib) {
 		if (fSecurityManager != null) {
@@ -188,11 +140,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkListen(int)
-	 */
 	@Override
 	public void checkListen(int port) {
 		if (fSecurityManager != null) {
@@ -200,21 +147,8 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress)
-	 */
 	@Override
 	public void checkMulticast(InetAddress maddr) {
 		if (fSecurityManager != null) {
@@ -240,11 +169,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkPackageAccess(java.lang.String)
-	 */
 	@Override
 	public void checkPackageAccess(String pkg) {
 		if (fSecurityManager != null) {
@@ -252,11 +176,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkPackageDefinition(java.lang.String)
-	 */
 	@Override
 	public void checkPackageDefinition(String pkg) {
 		if (fSecurityManager != null) {
@@ -264,11 +183,6 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkPropertiesAccess()
-	 */
 	@Override
 	public void checkPropertiesAccess() {
 		if (fSecurityManager != null) {
@@ -317,11 +205,6 @@
 		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 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkRead(java.io.FileDescriptor)
-	 */
 	@Override
 	public void checkRead(FileDescriptor fd) {
 		if (fSecurityManager != null) {
@@ -341,11 +219,6 @@
 		}
 	}
 
-	/*
-	 * (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 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkRead(java.lang.String)
-	 */
 	@Override
 	public void checkRead(String file) {
 		if (fSecurityManager != null) {
@@ -365,11 +233,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkSecurityAccess(java.lang.String)
-	 */
 	@Override
 	public void checkSecurityAccess(String target) {
 		if (fSecurityManager != null) {
@@ -377,11 +240,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkSetFactory()
-	 */
 	@Override
 	public void checkSetFactory() {
 		if (fSecurityManager != null) {
@@ -389,36 +247,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkSystemClipboardAccess()
-	 */
-	@Override
-	public void checkSystemClipboardAccess() {
-		if (fSecurityManager != null) {
-			fSecurityManager.checkSystemClipboardAccess();
-		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object)
-	 */
-	@Override
-	public boolean checkTopLevelWindow(Object window) {
-		if (fSecurityManager != null) {
-			return fSecurityManager.checkTopLevelWindow(window);
-		}
-		return super.checkTopLevelWindow(window);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor)
-	 */
 	@Override
 	public void checkWrite(FileDescriptor fd) {
 		if (fSecurityManager != null) {
@@ -426,11 +254,6 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#checkWrite(java.lang.String)
-	 */
 	@Override
 	public void checkWrite(String file) {
 		if (fSecurityManager != null) {
@@ -438,32 +261,6 @@
 		}
 	}
 
-	/**
-	 * @see java.lang.SecurityManager#getInCheck()
-	 * @deprecated
-	 */
-	@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();
-			}
-			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()
-	 */
 	@Override
 	public Object getSecurityContext() {
 		if (fSecurityManager != null) {
@@ -472,11 +269,6 @@
 		return super.getSecurityContext();
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.SecurityManager#getThreadGroup()
-	 */
 	@Override
 	public ThreadGroup getThreadGroup() {
 		if (fSecurityManager != null) {
@@ -484,4 +276,149 @@
 		}
 		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.
+	// --------------------------------------------------------------------------------
+
+	/**
+	 * @deprecated super class method has been removed in JDK 10
+	 */
+	@Deprecated
+	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);
+			}
+		}
+	}
+
+	/**
+	 * @deprecated super class method has been removed in JDK 10
+	 */
+	@Deprecated
+	public void checkMemberAccess(Class<?> clazz, int which) {
+		if (fSecurityManager != null) {
+			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);
+			}
+		}
+	}
+
+	/**
+	 * @deprecated super class method has been removed in JDK 10
+	 */
+	@Deprecated
+	public void checkSystemClipboardAccess() {
+		if (fSecurityManager != null) {
+			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);
+			}
+		}
+	}
+
+	/**
+	 * @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 683ce1f..cc0a4b4 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._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