Skip to content

Commit

Permalink
8314877: Make fields final in 'java.net' package
Browse files Browse the repository at this point in the history
Reviewed-by: jpai
  • Loading branch information
Andrey Turbanov committed Sep 19, 2023
1 parent 86115c2 commit 283c360
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
private final String server;
private final Socket socket;
private InetSocketAddress external_address;
private HashMap<Integer, Object> optionsMap = new HashMap<>();
private final HashMap<Integer, Object> optionsMap = new HashMap<>();

static {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/net/HttpRetryException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2019, 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
Expand Down Expand Up @@ -42,7 +42,7 @@ public class HttpRetryException extends IOException {
/**
* The response code.
*/
private int responseCode;
private final int responseCode;

/**
* The URL to be redirected to.
Expand Down
8 changes: 5 additions & 3 deletions src/java.base/share/classes/java/net/IDN.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -242,9 +242,10 @@ public static String toUnicode(String input) {
private static final int MAX_LABEL_LENGTH = 63;

// single instance of nameprep
private static StringPrep namePrep = null;
private static final StringPrep namePrep;

static {
StringPrep stringPrep = null;
try {
final String IDN_PROFILE = "/sun/net/idn/uidna.spp";
@SuppressWarnings("removal")
Expand All @@ -255,12 +256,13 @@ public InputStream run() {
}})
: StringPrep.class.getResourceAsStream(IDN_PROFILE);

namePrep = new StringPrep(stream);
stringPrep = new StringPrep(stream);
stream.close();
} catch (IOException e) {
// should never reach here
assert false;
}
namePrep = stringPrep;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
Expand Down Expand Up @@ -39,8 +39,8 @@

public final class PasswordAuthentication {

private String userName;
private char[] password;
private final String userName;
private final char[] password;

/**
* Creates a new {@code PasswordAuthentication} object from the given
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/net/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public enum Type {
SOCKS
};

private Type type;
private SocketAddress sa;
private final Type type;
private final SocketAddress sa;

/**
* A proxy setting that represents a {@code DIRECT} connection,
Expand Down
10 changes: 2 additions & 8 deletions src/java.base/share/classes/java/net/SocketPermission.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.concurrent.ConcurrentHashMap;
import sun.net.util.IPAddressUtil;
import sun.net.PortConfig;
import sun.security.action.GetBooleanAction;
import sun.security.util.RegisteredDomain;
import sun.security.util.SecurityConstants;
import sun.security.util.Debug;
Expand Down Expand Up @@ -234,7 +235,7 @@ public final class SocketPermission extends Permission
private transient boolean trusted;

// true if the sun.net.trustNameService system property is set
private static boolean trustNameService;
private static final boolean trustNameService = GetBooleanAction.privilegedGetProperty("sun.net.trustNameService");

private static Debug debug = null;
private static boolean debugInit = false;
Expand All @@ -245,13 +246,6 @@ private static class EphemeralRange {
static final int high = initEphemeralPorts("high", PORT_MAX);
};

static {
@SuppressWarnings("removal")
Boolean tmp = java.security.AccessController.doPrivileged(
new sun.security.action.GetBooleanAction("sun.net.trustNameService"));
trustNameService = tmp.booleanValue();
}

private static synchronized Debug getDebug() {
if (!debugInit) {
debug = Debug.getInstance("access");
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/net/URI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
Expand Down Expand Up @@ -2977,7 +2977,7 @@ private static String decode(String s, boolean ignorePercentInBrackets) {

private class Parser {

private String input; // URI input string
private final String input; // URI input string
private boolean requireServerAuthority = false;

Parser(String s) {
Expand Down
8 changes: 4 additions & 4 deletions src/java.base/share/classes/java/net/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -1471,10 +1471,10 @@ private static URLStreamHandler lookupViaProperty(String protocol) {
private static Iterator<URLStreamHandlerProvider> providers() {
return new Iterator<>() {

ClassLoader cl = ClassLoader.getSystemClassLoader();
ServiceLoader<URLStreamHandlerProvider> sl =
final ClassLoader cl = ClassLoader.getSystemClassLoader();
final ServiceLoader<URLStreamHandlerProvider> sl =
ServiceLoader.load(URLStreamHandlerProvider.class, cl);
Iterator<URLStreamHandlerProvider> i = sl.iterator();
final Iterator<URLStreamHandlerProvider> i = sl.iterator();

URLStreamHandlerProvider next = null;

Expand Down Expand Up @@ -1589,7 +1589,7 @@ static boolean isOverrideable(String protocol) {
/**
* A table of protocol handlers.
*/
static Hashtable<String,URLStreamHandler> handlers = new Hashtable<>();
private static final Hashtable<String, URLStreamHandler> handlers = new Hashtable<>();
private static final Object streamHandlerLock = new Object();

/**
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/net/URLClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public URLClassLoader(String name, URL[] urls, ClassLoader parent,
* we have to keep a weak reference to each stream.
*/

private WeakHashMap<Closeable,Void>
private final WeakHashMap<Closeable,Void>
closeables = new WeakHashMap<>();

/**
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/net/URLConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public static FileNameMap getFileNameMap() {

if (map == null) {
fileNameMap = map = new FileNameMap() {
private FileNameMap internalMap =
private final FileNameMap internalMap =
sun.net.www.MimeTable.loadTable();

public String getContentTypeFor(String fileName) {
Expand Down

1 comment on commit 283c360

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.