From a8ab3be371ab84ad768d9788a1e7a8d1bb833426 Mon Sep 17 00:00:00 2001 From: Andrey Turbanov Date: Thu, 17 Aug 2023 17:54:02 +0000 Subject: [PATCH] 8314261: Make fields final in sun.net.www Reviewed-by: redestad, jpai, dfuchs --- .../share/classes/sun/net/www/MimeTable.java | 4 ++-- .../classes/sun/net/www/URLConnection.java | 2 +- .../sun/net/www/http/ChunkedInputStream.java | 6 ++--- .../sun/net/www/http/ChunkedOutputStream.java | 20 ++++++++--------- .../classes/sun/net/www/http/HttpCapture.java | 4 ++-- .../classes/sun/net/www/http/HttpClient.java | 6 ++--- .../net/www/http/KeepAliveStreamCleaner.java | 10 ++++----- .../www/protocol/file/FileURLConnection.java | 10 ++++----- .../www/protocol/ftp/FtpURLConnection.java | 8 ++----- .../protocol/http/AuthenticationHeader.java | 13 ++++++----- .../protocol/http/DigestAuthentication.java | 6 +---- .../www/protocol/http/HttpURLConnection.java | 22 ++++++++++--------- .../sun/net/www/protocol/jar/URLJarFile.java | 4 ++-- 13 files changed, 55 insertions(+), 60 deletions(-) diff --git a/src/java.base/share/classes/sun/net/www/MimeTable.java b/src/java.base/share/classes/sun/net/www/MimeTable.java index 926fe7d60b3..9da69d58aa7 100644 --- a/src/java.base/share/classes/sun/net/www/MimeTable.java +++ b/src/java.base/share/classes/sun/net/www/MimeTable.java @@ -45,10 +45,10 @@ public class MimeTable implements FileNameMap { private static final int HASH_MARK = '#'; /** Keyed by content type, returns MimeEntries */ - private Hashtable entries = new Hashtable<>(); + private final Hashtable entries = new Hashtable<>(); /** Keyed by file extension (with the .), returns MimeEntries */ - private Hashtable extensionMap = new Hashtable<>(); + private final Hashtable extensionMap = new Hashtable<>(); // Will be reset if in the platform-specific data file @SuppressWarnings("removal") diff --git a/src/java.base/share/classes/sun/net/www/URLConnection.java b/src/java.base/share/classes/sun/net/www/URLConnection.java index 6851367ad67..66005ab9b2a 100644 --- a/src/java.base/share/classes/sun/net/www/URLConnection.java +++ b/src/java.base/share/classes/sun/net/www/URLConnection.java @@ -261,7 +261,7 @@ public abstract class URLConnection extends java.net.URLConnection { url = null; } - private static HashMap proxiedHosts = new HashMap<>(); + private static final HashMap proxiedHosts = new HashMap<>(); public static synchronized void setProxiedHost(String host) { proxiedHosts.put(host.toLowerCase(Locale.ROOT), null); diff --git a/src/java.base/share/classes/sun/net/www/http/ChunkedInputStream.java b/src/java.base/share/classes/sun/net/www/http/ChunkedInputStream.java index b5809aaa86c..f229cf3a6eb 100644 --- a/src/java.base/share/classes/sun/net/www/http/ChunkedInputStream.java +++ b/src/java.base/share/classes/sun/net/www/http/ChunkedInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -50,13 +50,13 @@ public class ChunkedInputStream extends InputStream implements Hurryable { * The HttpClient that should be notified when the chunked stream has * completed. */ - private HttpClient hc; + private final HttpClient hc; /** * The MessageHeader that is populated with any optional trailer * that appear after the last chunk. */ - private MessageHeader responses; + private final MessageHeader responses; /** * The size, in bytes, of the chunk that is currently being read. diff --git a/src/java.base/share/classes/sun/net/www/http/ChunkedOutputStream.java b/src/java.base/share/classes/sun/net/www/http/ChunkedOutputStream.java index 4cf485cc33e..93584e641b4 100644 --- a/src/java.base/share/classes/sun/net/www/http/ChunkedOutputStream.java +++ b/src/java.base/share/classes/sun/net/www/http/ChunkedOutputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -46,7 +46,7 @@ public class ChunkedOutputStream extends OutputStream { private static final int EMPTY_CHUNK_HEADER_SIZE = getHeaderSize(0); /* internal buffer */ - private byte buf[]; + private final byte[] buf; /* size of data (excluding footers and headers) already stored in buf */ private int size; /* current index in buf (i.e. buf[count] */ @@ -59,11 +59,11 @@ public class ChunkedOutputStream extends OutputStream { private PrintStream out; /* the chunk size we use */ - private int preferredChunkDataSize; - private int preferedHeaderSize; - private int preferredChunkGrossSize; + private final int preferredChunkDataSize; + private final int preferredHeaderSize; + private final int preferredChunkGrossSize; /* header for a complete Chunk */ - private byte[] completeHeader; + private final byte[] completeHeader; private final Lock writeLock = new ReentrantLock(); @@ -119,8 +119,8 @@ public class ChunkedOutputStream extends OutputStream { getHeaderSize(DEFAULT_CHUNK_SIZE) - FOOTER_SIZE; } - preferedHeaderSize = getHeaderSize(preferredChunkDataSize); - preferredChunkGrossSize = preferedHeaderSize + preferredChunkDataSize + preferredHeaderSize = getHeaderSize(preferredChunkDataSize); + preferredChunkGrossSize = preferredHeaderSize + preferredChunkDataSize + FOOTER_SIZE; completeHeader = getHeader(preferredChunkDataSize); @@ -151,7 +151,7 @@ public class ChunkedOutputStream extends OutputStream { /* adjust a header start index in case the header of the last * chunk is shorter then preferedHeaderSize */ - int adjustedHeaderStartIndex = preferedHeaderSize - + int adjustedHeaderStartIndex = preferredHeaderSize - getHeaderSize(size); /* write header */ @@ -277,7 +277,7 @@ public class ChunkedOutputStream extends OutputStream { public void reset() { writeLock.lock(); try { - count = preferedHeaderSize; + count = preferredHeaderSize; size = 0; spaceInCurrentChunk = preferredChunkDataSize; } finally { diff --git a/src/java.base/share/classes/sun/net/www/http/HttpCapture.java b/src/java.base/share/classes/sun/net/www/http/HttpCapture.java index 1d2732e0473..ba7e5af6cdf 100644 --- a/src/java.base/share/classes/sun/net/www/http/HttpCapture.java +++ b/src/java.base/share/classes/sun/net/www/http/HttpCapture.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -56,7 +56,7 @@ import sun.util.logging.PlatformLogger; public class HttpCapture { // HttpCapture does blocking I/O operations while holding monitors. // This is not a concern because it is rarely used. - private File file; + private final File file; private boolean incoming = true; private BufferedWriter out; private static boolean initialized; diff --git a/src/java.base/share/classes/sun/net/www/http/HttpClient.java b/src/java.base/share/classes/sun/net/www/http/HttpClient.java index a1c9e972990..01c341401d8 100644 --- a/src/java.base/share/classes/sun/net/www/http/HttpClient.java +++ b/src/java.base/share/classes/sun/net/www/http/HttpClient.java @@ -98,13 +98,13 @@ public class HttpClient extends NetworkClient { protected int port; /* where we cache currently open, persistent connections */ - protected static KeepAliveCache kac = new KeepAliveCache(); + protected static final KeepAliveCache kac = new KeepAliveCache(); - private static boolean keepAliveProp = true; + private static final boolean keepAliveProp; // retryPostProp is true by default so as to preserve behavior // from previous releases. - private static boolean retryPostProp = true; + private static final boolean retryPostProp; /* Value of the system property jdk.ntlm.cache; if false, then NTLM connections will not be cached. diff --git a/src/java.base/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java b/src/java.base/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java index cc0b0cce0e9..79bdb8cc64f 100644 --- a/src/java.base/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java +++ b/src/java.base/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -51,10 +51,10 @@ class KeepAliveStreamCleaner implements Runnable { // maximum amount of remaining data that we will try to cleanup - protected static int MAX_DATA_REMAINING = 512; + protected static final int MAX_DATA_REMAINING; // maximum amount of KeepAliveStreams to be queued - protected static int MAX_CAPACITY = 10; + protected static final int MAX_CAPACITY; // timeout for both socket and poll on the queue protected static final int TIMEOUT = 5000; @@ -68,7 +68,7 @@ class KeepAliveStreamCleaner int maxData = AccessController.doPrivileged( new PrivilegedAction() { public Integer run() { - return NetProperties.getInteger(maxDataKey, MAX_DATA_REMAINING); + return NetProperties.getInteger(maxDataKey, 512); }}).intValue() * 1024; MAX_DATA_REMAINING = maxData; @@ -77,7 +77,7 @@ class KeepAliveStreamCleaner int maxCapacity = AccessController.doPrivileged( new PrivilegedAction() { public Integer run() { - return NetProperties.getInteger(maxCapacityKey, MAX_CAPACITY); + return NetProperties.getInteger(maxCapacityKey, 10); }}).intValue(); MAX_CAPACITY = maxCapacity; diff --git a/src/java.base/share/classes/sun/net/www/protocol/file/FileURLConnection.java b/src/java.base/share/classes/sun/net/www/protocol/file/FileURLConnection.java index 545dc4b69e5..a27a6137a37 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/file/FileURLConnection.java +++ b/src/java.base/share/classes/sun/net/www/protocol/file/FileURLConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,10 +42,10 @@ import java.text.SimpleDateFormat; public class FileURLConnection extends URLConnection { - static String CONTENT_LENGTH = "content-length"; - static String CONTENT_TYPE = "content-type"; - static String TEXT_PLAIN = "text/plain"; - static String LAST_MODIFIED = "last-modified"; + private static final String CONTENT_LENGTH = "content-length"; + private static final String CONTENT_TYPE = "content-type"; + private static final String TEXT_PLAIN = "text/plain"; + private static final String LAST_MODIFIED = "last-modified"; String contentType; InputStream is; diff --git a/src/java.base/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java b/src/java.base/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java index ecc17ea85ec..f559cc5b820 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java +++ b/src/java.base/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,10 +23,6 @@ * questions. */ -/** - * FTP stream opener. - */ - package sun.net.www.protocol.ftp; import java.io.IOException; @@ -84,7 +80,7 @@ public class FtpURLConnection extends URLConnection { // In case we have to use proxies, we use HttpURLConnection HttpURLConnection http = null; - private Proxy instProxy; + private final Proxy instProxy; InputStream is = null; OutputStream os = null; diff --git a/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java b/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java index bf237259e18..8083fb36f39 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java +++ b/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java @@ -91,14 +91,14 @@ public class AuthenticationHeader { // When set true, do not use Negotiate even if the response // headers suggest so. boolean dontUseNegotiate = false; - static String authPref=null; + private static final String authPref; public String toString() { return "AuthenticationHeader: prefer " + preferred_r; } static { - authPref = GetPropertyAction.privilegedGetProperty("http.auth.preference"); + String pref = GetPropertyAction.privilegedGetProperty("http.auth.preference"); // http.auth.preference can be set to SPNEGO or Kerberos. // In fact they means "Negotiate with SPNEGO" and "Negotiate with @@ -106,12 +106,13 @@ public class AuthenticationHeader { // Negotiate. Read NegotiateAuthentication.java to see how they // were used later. - if (authPref != null) { - authPref = authPref.toLowerCase(Locale.ROOT); - if(authPref.equals("spnego") || authPref.equals("kerberos")) { - authPref = "negotiate"; + if (pref != null) { + pref = pref.toLowerCase(Locale.ROOT); + if (pref.equals("spnego") || pref.equals("kerberos")) { + pref = "negotiate"; } } + authPref = pref; } String hdrname; // Name of the header to look for diff --git a/src/java.base/share/classes/sun/net/www/protocol/http/DigestAuthentication.java b/src/java.base/share/classes/sun/net/www/protocol/http/DigestAuthentication.java index 66e78c866b7..faee05b4dfd 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/http/DigestAuthentication.java +++ b/src/java.base/share/classes/sun/net/www/protocol/http/DigestAuthentication.java @@ -171,11 +171,7 @@ class DigestAuthentication extends AuthenticationInfo { private static final int cnoncelen = 40; /* number of characters in cnonce */ - private static Random random; - - static { - random = new Random(); - } + private static final Random random = new Random(); Parameters () { serverQop = false; diff --git a/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java b/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java index cbd24ee2f0b..f505ea4a59f 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java +++ b/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java @@ -162,15 +162,15 @@ public class HttpURLConnection extends java.net.HttpURLConnection { /* Should we enable buffering of error streams? */ - private static boolean enableESBuffer = false; + private static final boolean enableESBuffer; /* timeout waiting for read for buffered error stream; */ - private static int timeout4ESBuffer = 0; + private static final int timeout4ESBuffer; /* buffer size for buffered error stream; */ - private static int bufSize4ES = 0; + private static final int bufSize4ES; /* * Restrict setting of request headers through the public api @@ -264,17 +264,19 @@ public class HttpURLConnection extends java.net.HttpURLConnection { enableESBuffer = Boolean.parseBoolean( props.getProperty("sun.net.http.errorstream.enableBuffering")); - timeout4ESBuffer = GetIntegerAction.privilegedGetProperty( + int esBufferTimeout = GetIntegerAction.privilegedGetProperty( "sun.net.http.errorstream.timeout", 300); - if (timeout4ESBuffer <= 0) { - timeout4ESBuffer = 300; // use the default + if (esBufferTimeout <= 0) { + esBufferTimeout = 300; // use the default } + timeout4ESBuffer = esBufferTimeout; - bufSize4ES = GetIntegerAction.privilegedGetProperty( + int esBufSize = GetIntegerAction.privilegedGetProperty( "sun.net.http.errorstream.bufferSize", 4096); - if (bufSize4ES <= 0) { - bufSize4ES = 4096; // use the default + if (esBufSize <= 0) { + esBufSize = 4096; // use the default } + bufSize4ES = esBufSize; allowRestrictedHeaders = Boolean.parseBoolean( props.getProperty("sun.net.http.allowRestrictedHeaders")); @@ -349,7 +351,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection { /* The headers actually set by the user are recorded here also */ - private MessageHeader userHeaders; + private final MessageHeader userHeaders; /* Headers and request method cannot be changed * once this flag is set in :- diff --git a/src/java.base/share/classes/sun/net/www/protocol/jar/URLJarFile.java b/src/java.base/share/classes/sun/net/www/protocol/jar/URLJarFile.java index 47ac1f13064..c5216d87e6c 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/jar/URLJarFile.java +++ b/src/java.base/share/classes/sun/net/www/protocol/jar/URLJarFile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -246,7 +246,7 @@ public class URLJarFile extends JarFile { private class URLJarFileEntry extends JarEntry { - private JarEntry je; + private final JarEntry je; URLJarFileEntry(JarEntry je) { super(je);