8314261: Make fields final in sun.net.www

Reviewed-by: redestad, jpai, dfuchs
This commit is contained in:
Andrey Turbanov 2023-08-17 17:54:02 +00:00
parent 3bb8afba69
commit a8ab3be371
13 changed files with 55 additions and 60 deletions

View File

@ -45,10 +45,10 @@ public class MimeTable implements FileNameMap {
private static final int HASH_MARK = '#';
/** Keyed by content type, returns MimeEntries */
private Hashtable<String, MimeEntry> entries = new Hashtable<>();
private final Hashtable<String, MimeEntry> entries = new Hashtable<>();
/** Keyed by file extension (with the .), returns MimeEntries */
private Hashtable<String, MimeEntry> extensionMap = new Hashtable<>();
private final Hashtable<String, MimeEntry> extensionMap = new Hashtable<>();
// Will be reset if in the platform-specific data file
@SuppressWarnings("removal")

View File

@ -261,7 +261,7 @@ public abstract class URLConnection extends java.net.URLConnection {
url = null;
}
private static HashMap<String,Void> proxiedHosts = new HashMap<>();
private static final HashMap<String,Void> proxiedHosts = new HashMap<>();
public static synchronized void setProxiedHost(String host) {
proxiedHosts.put(host.toLowerCase(Locale.ROOT), null);

View File

@ -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 <code>HttpClient</code> that should be notified when the chunked stream has
* completed.
*/
private HttpClient hc;
private final HttpClient hc;
/**
* The <code>MessageHeader</code> 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.

View File

@ -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 {

View File

@ -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;

View File

@ -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.

View File

@ -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<Integer>() {
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<Integer>() {
public Integer run() {
return NetProperties.getInteger(maxCapacityKey, MAX_CAPACITY);
return NetProperties.getInteger(maxCapacityKey, 10);
}}).intValue();
MAX_CAPACITY = maxCapacity;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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 :-

View File

@ -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);