From f61ac12960af852b8237fe91f256dea27d898dca Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Thu, 17 Jun 2021 08:51:21 +0530 Subject: [PATCH] Remove practically no-op code which was calling System.setSecurityManager() Starting Java 17, System.setSecurityManager() usage is deprecated (for removal) as noted in https://openjdk.java.net/jeps/411. The code here was just calling getSecurityManager() and then in a finally block setting it back using setSecurityManager(). However, we aren't setting any other security manager in between these calls. Looking at the code history, it appears that at one point back in 2001, we were indeed setting a custom security manager (commit 41893fdb3052f79a2d09d7f8a86711912fc429e6) but that was then reverted in commit ff4e823ee29f5a6a0e1658ff8ff43f1076f7a559. So this current piece of code is practically doing nothing. --- src/main/org/apache/tools/ant/Main.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index 18feef827..bb07cabac 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -749,15 +749,6 @@ public class Main implements AntMain { final PrintStream savedErr = System.err; final PrintStream savedOut = System.out; final InputStream savedIn = System.in; - - // use a system manager that prevents from System.exit() - SecurityManager oldsm = null; - oldsm = System.getSecurityManager(); - - //SecurityManager can not be installed here for backwards - //compatibility reasons (PD). Needs to be loaded prior to - //ant class if we are going to implement it. - //System.setSecurityManager(new NoExitSecurityManager()); try { if (allowInput) { project.setDefaultInputStream(System.in); @@ -826,12 +817,6 @@ public class Main implements AntMain { project.executeTargets(targets); } finally { - // put back the original security manager - //The following will never eval to true. (PD) - if (oldsm != null) { - System.setSecurityManager(oldsm); - } - System.setOut(savedOut); System.setErr(savedErr); System.setIn(savedIn);