4444import java .net .ServerSocket ;
4545import java .net .Socket ;
4646import java .net .SocketAddress ;
47- import java .security .AccessController ;
48- import java .security .PrivilegedAction ;
49- import java .security .PrivilegedExceptionAction ;
5047import java .text .DateFormat ;
5148import java .time .ZoneOffset ;
5249import java .time .ZonedDateTime ;
@@ -133,31 +130,17 @@ public class FtpClient extends sun.net.ftp.FtpClient {
133130 private DateFormat df = DateFormat .getDateInstance (DateFormat .MEDIUM , java .util .Locale .US );
134131 private static final boolean acceptPasvAddressVal ;
135132 static {
136- final int vals [] = {0 , 0 };
137- final String acceptPasvAddress [] = {null };
138- @ SuppressWarnings ("removal" )
139- final String enc = AccessController .doPrivileged (
140- new PrivilegedAction <String >() {
141- public String run () {
142- acceptPasvAddress [0 ] = System .getProperty ("jdk.net.ftp.trustPasvAddress" , "false" );
143- vals [0 ] = Integer .getInteger ("sun.net.client.defaultReadTimeout" , 300_000 ).intValue ();
144- vals [1 ] = Integer .getInteger ("sun.net.client.defaultConnectTimeout" , 300_000 ).intValue ();
145- return System .getProperty ("file.encoding" , "ISO8859_1" );
146- }
147- });
148- if (vals [0 ] == 0 ) {
133+ defaultSoTimeout = Integer .getInteger ("sun.net.client.defaultReadTimeout" , 300_000 ).intValue ();
134+ if (defaultSoTimeout == 0 ) {
149135 defaultSoTimeout = -1 ;
150- } else {
151- defaultSoTimeout = vals [0 ];
152136 }
153137
154- if (vals [1 ] == 0 ) {
138+ defaultConnectTimeout = Integer .getInteger ("sun.net.client.defaultConnectTimeout" , 300_000 ).intValue ();
139+ if (defaultConnectTimeout == 0 ) {
155140 defaultConnectTimeout = -1 ;
156- } else {
157- defaultConnectTimeout = vals [1 ];
158141 }
159142
160- encoding = enc ;
143+ encoding = System . getProperty ( "file.encoding" , "ISO8859_1" ) ;
161144 try {
162145 if (!isASCIISuperset (encoding )) {
163146 encoding = "ISO8859_1" ;
@@ -171,7 +154,7 @@ public String run() {
171154 patterns [i ] = Pattern .compile (patStrings [i ]);
172155 }
173156
174- acceptPasvAddressVal = Boolean .parseBoolean ( acceptPasvAddress [ 0 ] );
157+ acceptPasvAddressVal = Boolean .getBoolean ( "jdk.net.ftp.trustPasvAddress" );
175158 }
176159
177160 /**
@@ -662,20 +645,15 @@ private Socket openPassiveDataConnection(String cmd) throws sun.net.ftp.FtpProto
662645 Socket s ;
663646 if (proxy != null ) {
664647 if (proxy .type () == Proxy .Type .SOCKS ) {
665- PrivilegedAction <Socket > pa = () -> new Socket (proxy );
666- @ SuppressWarnings ("removal" )
667- var tmp = AccessController .doPrivileged (pa );
668- s = tmp ;
648+ s = new Socket (proxy );
669649 } else {
670650 s = new Socket (Proxy .NO_PROXY );
671651 }
672652 } else {
673653 s = new Socket ();
674654 }
675655
676- PrivilegedAction <InetAddress > pa = () -> server .getLocalAddress ();
677- @ SuppressWarnings ("removal" )
678- InetAddress serverAddress = AccessController .doPrivileged (pa );
656+ InetAddress serverAddress = server .getLocalAddress ();
679657
680658 // Bind the socket to the same address as the control channel. This
681659 // is needed in case of multi-homed systems.
@@ -761,11 +739,8 @@ private InetSocketAddress validatePasvAddress(int port, String s, InetAddress ad
761739 }
762740
763741 private static InetAddress privilegedLocalHost () throws FtpProtocolException {
764- PrivilegedExceptionAction <InetAddress > action = InetAddress ::getLocalHost ;
765742 try {
766- @ SuppressWarnings ("removal" )
767- var tmp = AccessController .doPrivileged (action );
768- return tmp ;
743+ return InetAddress .getLocalHost ();
769744 } catch (Exception e ) {
770745 var ftpEx = new FtpProtocolException (ERROR_MSG );
771746 ftpEx .initCause (e );
@@ -774,11 +749,8 @@ private static InetAddress privilegedLocalHost() throws FtpProtocolException {
774749 }
775750
776751 private static InetAddress [] privilegedGetAllByName (String hostName ) throws FtpProtocolException {
777- PrivilegedExceptionAction <InetAddress []> pAction = () -> InetAddress .getAllByName (hostName );
778752 try {
779- @ SuppressWarnings ("removal" )
780- var tmp =AccessController .doPrivileged (pAction );
781- return tmp ;
753+ return InetAddress .getAllByName (hostName );
782754 } catch (Exception e ) {
783755 var ftpEx = new FtpProtocolException (ERROR_MSG );
784756 ftpEx .initCause (e );
@@ -1021,10 +993,7 @@ private Socket doConnect(InetSocketAddress dest, int timeout) throws IOException
1021993 Socket s ;
1022994 if (proxy != null ) {
1023995 if (proxy .type () == Proxy .Type .SOCKS ) {
1024- PrivilegedAction <Socket > pa = () -> new Socket (proxy );
1025- @ SuppressWarnings ("removal" )
1026- var tmp = AccessController .doPrivileged (pa );
1027- s = tmp ;
996+ s = new Socket (proxy );
1028997 } else {
1029998 s = new Socket (Proxy .NO_PROXY );
1030999 }
0 commit comments