Skip to content

Commit 578665f

Browse files
committed
Stop AntSecurityManager from impl methods removed in Java 10
As the projects are at Java 17 level now these are plain useless but generate warnings in "needless" test runs. Fixes #1601
1 parent 93a2f4b commit 578665f

File tree

4 files changed

+3
-337
lines changed

4 files changed

+3
-337
lines changed

ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/AntSecurityManager.java

Lines changed: 1 addition & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2019 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,18 +14,12 @@
1414
package org.eclipse.ant.internal.core;
1515

1616
import java.io.FileDescriptor;
17-
import java.lang.reflect.InvocationTargetException;
18-
import java.lang.reflect.Method;
1917
import java.net.InetAddress;
2018
import java.net.SocketPermission;
2119
import java.security.Permission;
2220
import java.util.PropertyPermission;
2321

24-
import org.eclipse.ant.core.AntCorePlugin;
2522
import org.eclipse.ant.core.AntSecurityException;
26-
import org.eclipse.core.runtime.ILog;
27-
import org.eclipse.core.runtime.IStatus;
28-
import org.eclipse.core.runtime.Status;
2923

3024
/**
3125
* A security manager that always throws an <code>AntSecurityException</code> if the calling thread attempts to cause the Java Virtual Machine to
@@ -277,148 +271,4 @@ public ThreadGroup getThreadGroup() {
277271
return super.getThreadGroup();
278272
}
279273

280-
// --------------------------------------------------------------------------------
281-
// Below are SecurityManager methods deprecated in Java 9 and removed in Java 10.
282-
// They are accessed through reflections to support Java 8 and 11 at the same time.
283-
// XXX: This also means you must not add @Override annotations even if Eclipse try to add them.
284-
// --------------------------------------------------------------------------------
285-
286-
/**
287-
* @deprecated super class method has been removed in JDK 10
288-
*/
289-
@Deprecated
290-
public void checkAwtEventQueueAccess() {
291-
if (fSecurityManager != null) {
292-
try {
293-
final Method m = fSecurityManager.getClass().getMethod("checkAwtEventQueueAccess"); //$NON-NLS-1$
294-
m.invoke(fSecurityManager);
295-
}
296-
catch (NoSuchMethodException e) {
297-
logDeprecatedAccess(e);
298-
}
299-
catch (InvocationTargetException e) {
300-
if (e.getTargetException() instanceof RuntimeException) {
301-
throw (RuntimeException) e.getTargetException();
302-
}
303-
logException(e);
304-
}
305-
catch (IllegalAccessException | IllegalArgumentException e) {
306-
logException(e);
307-
}
308-
}
309-
}
310-
311-
/**
312-
* @deprecated super class method has been removed in JDK 10
313-
*/
314-
@Deprecated
315-
public void checkMemberAccess(Class<?> clazz, int which) {
316-
if (fSecurityManager != null) {
317-
try {
318-
final Method m = fSecurityManager.getClass().getMethod("checkMemberAccess", Class.class, int.class); //$NON-NLS-1$
319-
m.invoke(fSecurityManager, clazz, which);
320-
}
321-
catch (NoSuchMethodException e) {
322-
logDeprecatedAccess(e);
323-
}
324-
catch (InvocationTargetException e) {
325-
if (e.getTargetException() instanceof RuntimeException) {
326-
throw (RuntimeException) e.getTargetException();
327-
}
328-
logException(e);
329-
}
330-
catch (IllegalAccessException | IllegalArgumentException e) {
331-
logException(e);
332-
}
333-
}
334-
}
335-
336-
/**
337-
* @deprecated super class method has been removed in JDK 10
338-
*/
339-
@Deprecated
340-
public void checkSystemClipboardAccess() {
341-
if (fSecurityManager != null) {
342-
try {
343-
final Method m = fSecurityManager.getClass().getMethod("checkSystemClipboardAccess"); //$NON-NLS-1$
344-
m.invoke(fSecurityManager);
345-
}
346-
catch (NoSuchMethodException e) {
347-
logDeprecatedAccess(e);
348-
}
349-
catch (InvocationTargetException e) {
350-
if (e.getTargetException() instanceof RuntimeException) {
351-
throw (RuntimeException) e.getTargetException();
352-
}
353-
logException(e);
354-
}
355-
catch (IllegalAccessException | IllegalArgumentException e) {
356-
logException(e);
357-
}
358-
}
359-
}
360-
361-
/**
362-
* @deprecated super class method has been removed in JDK 10
363-
*/
364-
@Deprecated
365-
public boolean checkTopLevelWindow(Object window) {
366-
try {
367-
if (fSecurityManager != null) {
368-
final Method m = fSecurityManager.getClass().getMethod("checkTopLevelWindow", Object.class); //$NON-NLS-1$
369-
return (boolean) m.invoke(fSecurityManager, window);
370-
}
371-
final Method m = SecurityManager.class.getMethod("checkTopLevelWindow", Object.class); //$NON-NLS-1$
372-
return (boolean) m.invoke(new SecurityManager(), window);
373-
}
374-
catch (NoSuchMethodException e) {
375-
logDeprecatedAccess(e);
376-
}
377-
catch (InvocationTargetException e) {
378-
if (e.getTargetException() instanceof RuntimeException) {
379-
throw (RuntimeException) e.getTargetException();
380-
}
381-
logException(e);
382-
}
383-
catch (IllegalAccessException | IllegalArgumentException e) {
384-
logException(e);
385-
}
386-
return false;
387-
}
388-
389-
/**
390-
* @deprecated super class method has been removed in JDK 10
391-
*/
392-
@Deprecated
393-
public boolean getInCheck() {
394-
try {
395-
if (fSecurityManager != null) {
396-
final Method m = fSecurityManager.getClass().getMethod("getInCheck"); //$NON-NLS-1$
397-
return (boolean) m.invoke(fSecurityManager);
398-
}
399-
final Method m = SecurityManager.class.getMethod("getInCheck"); //$NON-NLS-1$
400-
return (boolean) m.invoke(new SecurityManager());
401-
}
402-
catch (NoSuchMethodException e) {
403-
logDeprecatedAccess(e);
404-
}
405-
catch (InvocationTargetException e) {
406-
if (e.getTargetException() instanceof RuntimeException) {
407-
throw (RuntimeException) e.getTargetException();
408-
}
409-
logException(e);
410-
}
411-
catch (IllegalAccessException | IllegalArgumentException e) {
412-
logException(e);
413-
}
414-
return false;
415-
}
416-
417-
private static void logDeprecatedAccess(Throwable e) {
418-
ILog.of(AntCorePlugin.getPlugin().getBundle()).log(new Status(IStatus.WARNING, AntCorePlugin.PI_ANTCORE, InternalCoreAntMessages.AntSecurityManager_0, e));
419-
}
420-
421-
private static void logException(Throwable e) {
422-
ILog.of(AntCorePlugin.getPlugin().getBundle()).log(new Status(IStatus.ERROR, AntCorePlugin.PI_ANTCORE, e.getLocalizedMessage(), e));
423-
}
424274
}

ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/AntSecurityManager.java

Lines changed: 1 addition & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2019 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,8 +14,6 @@
1414
package org.eclipse.ant.internal.launching.remote;
1515

1616
import java.io.FileDescriptor;
17-
import java.lang.reflect.InvocationTargetException;
18-
import java.lang.reflect.Method;
1917
import java.net.InetAddress;
2018
import java.net.SocketPermission;
2119
import java.security.Permission;
@@ -270,165 +268,4 @@ public ThreadGroup getThreadGroup() {
270268
}
271269
return super.getThreadGroup();
272270
}
273-
274-
// --------------------------------------------------------------------------------
275-
// Below are SecurityManager methods deprecated in Java 9 and removed in Java 10.
276-
// They are accessed through reflections to support Java 8 and 11 at the same time.
277-
// XXX: This also means you must not add @Override annotations even if Eclipse try to add them.
278-
// --------------------------------------------------------------------------------
279-
280-
/**
281-
* @deprecated super class method has been removed in JDK 10
282-
*/
283-
@Deprecated
284-
public void checkAwtEventQueueAccess() {
285-
if (fSecurityManager != null) {
286-
try {
287-
final Method m = fSecurityManager.getClass().getMethod("checkAwtEventQueueAccess"); //$NON-NLS-1$
288-
m.invoke(fSecurityManager);
289-
}
290-
catch (NoSuchMethodException e) {
291-
logDeprecatedAccess(e);
292-
}
293-
catch (InvocationTargetException e) {
294-
if (e.getTargetException() instanceof RuntimeException) {
295-
throw (RuntimeException) e.getTargetException();
296-
}
297-
logException(e);
298-
}
299-
catch (IllegalArgumentException e) {
300-
logException(e);
301-
}
302-
catch (IllegalAccessException e) {
303-
logException(e);
304-
}
305-
}
306-
}
307-
308-
/**
309-
* @deprecated super class method has been removed in JDK 10
310-
*/
311-
@Deprecated
312-
public void checkMemberAccess(Class<?> clazz, int which) {
313-
if (fSecurityManager != null) {
314-
try {
315-
final Method m = fSecurityManager.getClass().getMethod("checkMemberAccess", Class.class, int.class); //$NON-NLS-1$
316-
m.invoke(fSecurityManager, clazz, which);
317-
}
318-
catch (NoSuchMethodException e) {
319-
logDeprecatedAccess(e);
320-
}
321-
catch (InvocationTargetException e) {
322-
if (e.getTargetException() instanceof RuntimeException) {
323-
throw (RuntimeException) e.getTargetException();
324-
}
325-
logException(e);
326-
}
327-
catch (IllegalAccessException e) {
328-
logException(e);
329-
}
330-
catch (IllegalArgumentException e) {
331-
logException(e);
332-
}
333-
}
334-
}
335-
336-
/**
337-
* @deprecated super class method has been removed in JDK 10
338-
*/
339-
@Deprecated
340-
public void checkSystemClipboardAccess() {
341-
if (fSecurityManager != null) {
342-
try {
343-
final Method m = fSecurityManager.getClass().getMethod("checkSystemClipboardAccess"); //$NON-NLS-1$
344-
m.invoke(fSecurityManager);
345-
}
346-
catch (NoSuchMethodException e) {
347-
logDeprecatedAccess(e);
348-
}
349-
catch (InvocationTargetException e) {
350-
if (e.getTargetException() instanceof RuntimeException) {
351-
throw (RuntimeException) e.getTargetException();
352-
}
353-
logException(e);
354-
}
355-
catch (IllegalAccessException e) {
356-
logException(e);
357-
}
358-
catch (IllegalArgumentException e) {
359-
logException(e);
360-
}
361-
}
362-
}
363-
364-
/**
365-
* @deprecated super class method has been removed in JDK 10
366-
*/
367-
@Deprecated
368-
public boolean checkTopLevelWindow(Object window) {
369-
try {
370-
if (fSecurityManager != null) {
371-
final Method m = fSecurityManager.getClass().getMethod("checkTopLevelWindow", Object.class); //$NON-NLS-1$
372-
return (Boolean) m.invoke(fSecurityManager, window);
373-
}
374-
final Method m = SecurityManager.class.getMethod("checkTopLevelWindow", Object.class); //$NON-NLS-1$
375-
return (Boolean) m.invoke(new SecurityManager(), window);
376-
}
377-
catch (NoSuchMethodException e) {
378-
logDeprecatedAccess(e);
379-
}
380-
catch (InvocationTargetException e) {
381-
if (e.getTargetException() instanceof RuntimeException) {
382-
throw (RuntimeException) e.getTargetException();
383-
}
384-
logException(e);
385-
}
386-
catch (IllegalAccessException e) {
387-
logException(e);
388-
}
389-
catch (IllegalArgumentException e) {
390-
logException(e);
391-
}
392-
return false;
393-
}
394-
395-
/**
396-
* @deprecated super class method has been removed in JDK 10
397-
*/
398-
@Deprecated
399-
public boolean getInCheck() {
400-
try {
401-
if (fSecurityManager != null) {
402-
final Method m = fSecurityManager.getClass().getMethod("getInCheck"); //$NON-NLS-1$
403-
return (Boolean) m.invoke(fSecurityManager);
404-
}
405-
final Method m = SecurityManager.class.getMethod("getInCheck"); //$NON-NLS-1$
406-
return (Boolean) m.invoke(new SecurityManager());
407-
}
408-
catch (NoSuchMethodException e) {
409-
logDeprecatedAccess(e);
410-
}
411-
catch (InvocationTargetException e) {
412-
if (e.getTargetException() instanceof RuntimeException) {
413-
throw (RuntimeException) e.getTargetException();
414-
}
415-
logException(e);
416-
}
417-
catch (IllegalAccessException e) {
418-
logException(e);
419-
}
420-
catch (IllegalArgumentException e) {
421-
logException(e);
422-
}
423-
return false;
424-
}
425-
426-
private static void logDeprecatedAccess(Throwable e) {
427-
System.err.println(RemoteAntMessages.getString("AntSecurityManager.deprecatedMethod")); //$NON-NLS-1$
428-
e.printStackTrace();
429-
}
430-
431-
private static void logException(Throwable e) {
432-
e.printStackTrace();
433-
}
434271
}

ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/AutomatedAntSuite.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2011 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,7 +13,6 @@
1313
*******************************************************************************/
1414
package org.eclipse.ant.tests.core;
1515

16-
import org.eclipse.ant.tests.core.tests.AntSecurityManagerTest;
1716
import org.eclipse.ant.tests.core.tests.FrameworkTests;
1817
import org.eclipse.ant.tests.core.tests.OptionTests;
1918
import org.eclipse.ant.tests.core.tests.ProjectTests;
@@ -44,7 +43,6 @@
4443
TaskTests.class, //
4544
TypeTests.class, //
4645
PropertyTests.class, //
47-
AntSecurityManagerTest.class //
4846
})
4947
public class AutomatedAntSuite {
5048
//

ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/AntSecurityManagerTest.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)