Skip to content

Commit a8ab3be

Browse files
author
Andrey Turbanov
committedAug 17, 2023
8314261: Make fields final in sun.net.www
Reviewed-by: redestad, jpai, dfuchs
1 parent 3bb8afb commit a8ab3be

13 files changed

+55
-60
lines changed
 

‎src/java.base/share/classes/sun/net/www/MimeTable.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public class MimeTable implements FileNameMap {
4545
private static final int HASH_MARK = '#';
4646

4747
/** Keyed by content type, returns MimeEntries */
48-
private Hashtable<String, MimeEntry> entries = new Hashtable<>();
48+
private final Hashtable<String, MimeEntry> entries = new Hashtable<>();
4949

5050
/** Keyed by file extension (with the .), returns MimeEntries */
51-
private Hashtable<String, MimeEntry> extensionMap = new Hashtable<>();
51+
private final Hashtable<String, MimeEntry> extensionMap = new Hashtable<>();
5252

5353
// Will be reset if in the platform-specific data file
5454
@SuppressWarnings("removal")

‎src/java.base/share/classes/sun/net/www/URLConnection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public void close() {
261261
url = null;
262262
}
263263

264-
private static HashMap<String,Void> proxiedHosts = new HashMap<>();
264+
private static final HashMap<String,Void> proxiedHosts = new HashMap<>();
265265

266266
public static synchronized void setProxiedHost(String host) {
267267
proxiedHosts.put(host.toLowerCase(Locale.ROOT), null);

‎src/java.base/share/classes/sun/net/www/http/ChunkedInputStream.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -50,13 +50,13 @@ public class ChunkedInputStream extends InputStream implements Hurryable {
5050
* The <code>HttpClient</code> that should be notified when the chunked stream has
5151
* completed.
5252
*/
53-
private HttpClient hc;
53+
private final HttpClient hc;
5454

5555
/**
5656
* The <code>MessageHeader</code> that is populated with any optional trailer
5757
* that appear after the last chunk.
5858
*/
59-
private MessageHeader responses;
59+
private final MessageHeader responses;
6060

6161
/**
6262
* The size, in bytes, of the chunk that is currently being read.

‎src/java.base/share/classes/sun/net/www/http/ChunkedOutputStream.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -46,7 +46,7 @@ public class ChunkedOutputStream extends OutputStream {
4646
private static final int EMPTY_CHUNK_HEADER_SIZE = getHeaderSize(0);
4747

4848
/* internal buffer */
49-
private byte buf[];
49+
private final byte[] buf;
5050
/* size of data (excluding footers and headers) already stored in buf */
5151
private int size;
5252
/* current index in buf (i.e. buf[count] */
@@ -59,11 +59,11 @@ public class ChunkedOutputStream extends OutputStream {
5959
private PrintStream out;
6060

6161
/* the chunk size we use */
62-
private int preferredChunkDataSize;
63-
private int preferedHeaderSize;
64-
private int preferredChunkGrossSize;
62+
private final int preferredChunkDataSize;
63+
private final int preferredHeaderSize;
64+
private final int preferredChunkGrossSize;
6565
/* header for a complete Chunk */
66-
private byte[] completeHeader;
66+
private final byte[] completeHeader;
6767

6868
private final Lock writeLock = new ReentrantLock();
6969

@@ -119,8 +119,8 @@ public ChunkedOutputStream(PrintStream o, int size) {
119119
getHeaderSize(DEFAULT_CHUNK_SIZE) - FOOTER_SIZE;
120120
}
121121

122-
preferedHeaderSize = getHeaderSize(preferredChunkDataSize);
123-
preferredChunkGrossSize = preferedHeaderSize + preferredChunkDataSize
122+
preferredHeaderSize = getHeaderSize(preferredChunkDataSize);
123+
preferredChunkGrossSize = preferredHeaderSize + preferredChunkDataSize
124124
+ FOOTER_SIZE;
125125
completeHeader = getHeader(preferredChunkDataSize);
126126

@@ -151,7 +151,7 @@ private void flush(boolean flushAll) {
151151
/* adjust a header start index in case the header of the last
152152
* chunk is shorter then preferedHeaderSize */
153153

154-
int adjustedHeaderStartIndex = preferedHeaderSize -
154+
int adjustedHeaderStartIndex = preferredHeaderSize -
155155
getHeaderSize(size);
156156

157157
/* write header */
@@ -277,7 +277,7 @@ public void write(int _b) throws IOException {
277277
public void reset() {
278278
writeLock.lock();
279279
try {
280-
count = preferedHeaderSize;
280+
count = preferredHeaderSize;
281281
size = 0;
282282
spaceInCurrentChunk = preferredChunkDataSize;
283283
} finally {

‎src/java.base/share/classes/sun/net/www/http/HttpCapture.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -56,7 +56,7 @@
5656
public class HttpCapture {
5757
// HttpCapture does blocking I/O operations while holding monitors.
5858
// This is not a concern because it is rarely used.
59-
private File file;
59+
private final File file;
6060
private boolean incoming = true;
6161
private BufferedWriter out;
6262
private static boolean initialized;

‎src/java.base/share/classes/sun/net/www/http/HttpClient.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ private static int getDefaultPort(String proto) {
9898
protected int port;
9999

100100
/* where we cache currently open, persistent connections */
101-
protected static KeepAliveCache kac = new KeepAliveCache();
101+
protected static final KeepAliveCache kac = new KeepAliveCache();
102102

103-
private static boolean keepAliveProp = true;
103+
private static final boolean keepAliveProp;
104104

105105
// retryPostProp is true by default so as to preserve behavior
106106
// from previous releases.
107-
private static boolean retryPostProp = true;
107+
private static final boolean retryPostProp;
108108

109109
/* Value of the system property jdk.ntlm.cache;
110110
if false, then NTLM connections will not be cached.

‎src/java.base/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -51,10 +51,10 @@ class KeepAliveStreamCleaner
5151
implements Runnable
5252
{
5353
// maximum amount of remaining data that we will try to cleanup
54-
protected static int MAX_DATA_REMAINING = 512;
54+
protected static final int MAX_DATA_REMAINING;
5555

5656
// maximum amount of KeepAliveStreams to be queued
57-
protected static int MAX_CAPACITY = 10;
57+
protected static final int MAX_CAPACITY;
5858

5959
// timeout for both socket and poll on the queue
6060
protected static final int TIMEOUT = 5000;
@@ -68,7 +68,7 @@ class KeepAliveStreamCleaner
6868
int maxData = AccessController.doPrivileged(
6969
new PrivilegedAction<Integer>() {
7070
public Integer run() {
71-
return NetProperties.getInteger(maxDataKey, MAX_DATA_REMAINING);
71+
return NetProperties.getInteger(maxDataKey, 512);
7272
}}).intValue() * 1024;
7373
MAX_DATA_REMAINING = maxData;
7474

@@ -77,7 +77,7 @@ public Integer run() {
7777
int maxCapacity = AccessController.doPrivileged(
7878
new PrivilegedAction<Integer>() {
7979
public Integer run() {
80-
return NetProperties.getInteger(maxCapacityKey, MAX_CAPACITY);
80+
return NetProperties.getInteger(maxCapacityKey, 10);
8181
}}).intValue();
8282
MAX_CAPACITY = maxCapacity;
8383

‎src/java.base/share/classes/sun/net/www/protocol/file/FileURLConnection.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -42,10 +42,10 @@
4242

4343
public class FileURLConnection extends URLConnection {
4444

45-
static String CONTENT_LENGTH = "content-length";
46-
static String CONTENT_TYPE = "content-type";
47-
static String TEXT_PLAIN = "text/plain";
48-
static String LAST_MODIFIED = "last-modified";
45+
private static final String CONTENT_LENGTH = "content-length";
46+
private static final String CONTENT_TYPE = "content-type";
47+
private static final String TEXT_PLAIN = "text/plain";
48+
private static final String LAST_MODIFIED = "last-modified";
4949

5050
String contentType;
5151
InputStream is;

‎src/java.base/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,10 +23,6 @@
2323
* questions.
2424
*/
2525

26-
/**
27-
* FTP stream opener.
28-
*/
29-
3026
package sun.net.www.protocol.ftp;
3127

3228
import java.io.IOException;
@@ -84,7 +80,7 @@ public class FtpURLConnection extends URLConnection {
8480

8581
// In case we have to use proxies, we use HttpURLConnection
8682
HttpURLConnection http = null;
87-
private Proxy instProxy;
83+
private final Proxy instProxy;
8884

8985
InputStream is = null;
9086
OutputStream os = null;

‎src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,28 @@ public class AuthenticationHeader {
9191
// When set true, do not use Negotiate even if the response
9292
// headers suggest so.
9393
boolean dontUseNegotiate = false;
94-
static String authPref=null;
94+
private static final String authPref;
9595

9696
public String toString() {
9797
return "AuthenticationHeader: prefer " + preferred_r;
9898
}
9999

100100
static {
101-
authPref = GetPropertyAction.privilegedGetProperty("http.auth.preference");
101+
String pref = GetPropertyAction.privilegedGetProperty("http.auth.preference");
102102

103103
// http.auth.preference can be set to SPNEGO or Kerberos.
104104
// In fact they means "Negotiate with SPNEGO" and "Negotiate with
105105
// Kerberos" separately, so here they are all translated into
106106
// Negotiate. Read NegotiateAuthentication.java to see how they
107107
// were used later.
108108

109-
if (authPref != null) {
110-
authPref = authPref.toLowerCase(Locale.ROOT);
111-
if(authPref.equals("spnego") || authPref.equals("kerberos")) {
112-
authPref = "negotiate";
109+
if (pref != null) {
110+
pref = pref.toLowerCase(Locale.ROOT);
111+
if (pref.equals("spnego") || pref.equals("kerberos")) {
112+
pref = "negotiate";
113113
}
114114
}
115+
authPref = pref;
115116
}
116117

117118
String hdrname; // Name of the header to look for

‎src/java.base/share/classes/sun/net/www/protocol/http/DigestAuthentication.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,7 @@ static class Parameters implements java.io.Serializable {
171171

172172
private static final int cnoncelen = 40; /* number of characters in cnonce */
173173

174-
private static Random random;
175-
176-
static {
177-
random = new Random();
178-
}
174+
private static final Random random = new Random();
179175

180176
Parameters () {
181177
serverQop = false;

‎src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
162162

163163

164164
/* Should we enable buffering of error streams? */
165-
private static boolean enableESBuffer = false;
165+
private static final boolean enableESBuffer;
166166

167167
/* timeout waiting for read for buffered error stream;
168168
*/
169-
private static int timeout4ESBuffer = 0;
169+
private static final int timeout4ESBuffer;
170170

171171
/* buffer size for buffered error stream;
172172
*/
173-
private static int bufSize4ES = 0;
173+
private static final int bufSize4ES;
174174

175175
/*
176176
* Restrict setting of request headers through the public api
@@ -264,17 +264,19 @@ private static Set<String> schemesListToSet(String list) {
264264

265265
enableESBuffer = Boolean.parseBoolean(
266266
props.getProperty("sun.net.http.errorstream.enableBuffering"));
267-
timeout4ESBuffer = GetIntegerAction.privilegedGetProperty(
267+
int esBufferTimeout = GetIntegerAction.privilegedGetProperty(
268268
"sun.net.http.errorstream.timeout", 300);
269-
if (timeout4ESBuffer <= 0) {
270-
timeout4ESBuffer = 300; // use the default
269+
if (esBufferTimeout <= 0) {
270+
esBufferTimeout = 300; // use the default
271271
}
272+
timeout4ESBuffer = esBufferTimeout;
272273

273-
bufSize4ES = GetIntegerAction.privilegedGetProperty(
274+
int esBufSize = GetIntegerAction.privilegedGetProperty(
274275
"sun.net.http.errorstream.bufferSize", 4096);
275-
if (bufSize4ES <= 0) {
276-
bufSize4ES = 4096; // use the default
276+
if (esBufSize <= 0) {
277+
esBufSize = 4096; // use the default
277278
}
279+
bufSize4ES = esBufSize;
278280

279281
allowRestrictedHeaders = Boolean.parseBoolean(
280282
props.getProperty("sun.net.http.allowRestrictedHeaders"));
@@ -349,7 +351,7 @@ private static Set<String> schemesListToSet(String list) {
349351

350352
/* The headers actually set by the user are recorded here also
351353
*/
352-
private MessageHeader userHeaders;
354+
private final MessageHeader userHeaders;
353355

354356
/* Headers and request method cannot be changed
355357
* once this flag is set in :-

‎src/java.base/share/classes/sun/net/www/protocol/jar/URLJarFile.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -246,7 +246,7 @@ public static void setCallBack(URLJarFileCallBack cb)
246246

247247

248248
private class URLJarFileEntry extends JarEntry {
249-
private JarEntry je;
249+
private final JarEntry je;
250250

251251
URLJarFileEntry(JarEntry je) {
252252
super(je);

0 commit comments

Comments
 (0)
Please sign in to comment.