mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
Reviewed-by: alanb, mchung, rriggs
This commit is contained in:
parent
749ad1ee03
commit
8f24dc87b1
5 changed files with 28 additions and 29 deletions
|
@ -67,7 +67,7 @@ public class BootLoader {
|
||||||
// ServiceCatalog for the boot class loader
|
// ServiceCatalog for the boot class loader
|
||||||
private static final ServicesCatalog SERVICES_CATALOG = ServicesCatalog.create();
|
private static final ServicesCatalog SERVICES_CATALOG = ServicesCatalog.create();
|
||||||
|
|
||||||
// ClassLoaderValue map for boot class loader
|
// ClassLoaderValue map for the boot class loader
|
||||||
private static final ConcurrentHashMap<?, ?> CLASS_LOADER_VALUE_MAP
|
private static final ConcurrentHashMap<?, ?> CLASS_LOADER_VALUE_MAP
|
||||||
= new ConcurrentHashMap<>();
|
= new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ public class BuiltinClassLoader
|
||||||
// parent ClassLoader
|
// parent ClassLoader
|
||||||
private final BuiltinClassLoader parent;
|
private final BuiltinClassLoader parent;
|
||||||
|
|
||||||
// the URL class path or null if there is no class path
|
// the URL class path, or null if there is no class path
|
||||||
private final URLClassPath ucp;
|
private final URLClassPath ucp;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,6 @@ import java.util.stream.Stream;
|
||||||
import jdk.internal.misc.SharedSecrets;
|
import jdk.internal.misc.SharedSecrets;
|
||||||
import jdk.internal.module.Resources;
|
import jdk.internal.module.Resources;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class loader that loads classes and resources from a collection of
|
* A class loader that loads classes and resources from a collection of
|
||||||
* modules, or from a single module where the class loader is a member
|
* modules, or from a single module where the class loader is a member
|
||||||
|
@ -111,7 +110,7 @@ public final class Loader extends SecureClassLoader {
|
||||||
private final Map<ModuleReference, ModuleReader> moduleToReader
|
private final Map<ModuleReference, ModuleReader> moduleToReader
|
||||||
= new ConcurrentHashMap<>();
|
= new ConcurrentHashMap<>();
|
||||||
|
|
||||||
// ACC used when loading classes and resources */
|
// ACC used when loading classes and resources
|
||||||
private final AccessControlContext acc;
|
private final AccessControlContext acc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -83,4 +83,3 @@ public final class LoaderPool {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ import java.security.AccessControlException;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.CodeSigner;
|
import java.security.CodeSigner;
|
||||||
import java.security.Permission;
|
import java.security.Permission;
|
||||||
|
import java.security.PrivilegedActionException;
|
||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
import java.security.cert.Certificate;
|
import java.security.cert.Certificate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -209,7 +210,7 @@ public class URLClassPath {
|
||||||
try {
|
try {
|
||||||
loader.close();
|
loader.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
result.add (e);
|
result.add(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closed = true;
|
closed = true;
|
||||||
|
@ -272,7 +273,7 @@ public class URLClassPath {
|
||||||
*
|
*
|
||||||
* @param name the name of the resource
|
* @param name the name of the resource
|
||||||
* @param check whether to perform a security check
|
* @param check whether to perform a security check
|
||||||
* @return a <code>URL</code> for the resource, or <code>null</code>
|
* @return a {@code URL} for the resource, or {@code null}
|
||||||
* if the resource could not be found.
|
* if the resource could not be found.
|
||||||
*/
|
*/
|
||||||
public URL findResource(String name, boolean check) {
|
public URL findResource(String name, boolean check) {
|
||||||
|
@ -465,8 +466,8 @@ public class URLClassPath {
|
||||||
*/
|
*/
|
||||||
private Loader getLoader(final URL url) throws IOException {
|
private Loader getLoader(final URL url) throws IOException {
|
||||||
try {
|
try {
|
||||||
return java.security.AccessController.doPrivileged(
|
return AccessController.doPrivileged(
|
||||||
new java.security.PrivilegedExceptionAction<>() {
|
new PrivilegedExceptionAction<>() {
|
||||||
public Loader run() throws IOException {
|
public Loader run() throws IOException {
|
||||||
String protocol = url.getProtocol(); // lower cased in URL
|
String protocol = url.getProtocol(); // lower cased in URL
|
||||||
String file = url.getFile();
|
String file = url.getFile();
|
||||||
|
@ -487,7 +488,7 @@ public class URLClassPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, acc);
|
}, acc);
|
||||||
} catch (java.security.PrivilegedActionException pae) {
|
} catch (PrivilegedActionException pae) {
|
||||||
throw (IOException)pae.getException();
|
throw (IOException)pae.getException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -512,8 +513,8 @@ public class URLClassPath {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check whether the resource URL should be returned.
|
* Checks whether the resource URL should be returned.
|
||||||
* Return null on security check failure.
|
* Returns null on security check failure.
|
||||||
* Called by java.net.URLClassLoader.
|
* Called by java.net.URLClassLoader.
|
||||||
*/
|
*/
|
||||||
public static URL checkURL(URL url) {
|
public static URL checkURL(URL url) {
|
||||||
|
@ -528,8 +529,8 @@ public class URLClassPath {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check whether the resource URL should be returned.
|
* Checks whether the resource URL should be returned.
|
||||||
* Throw exception on failure.
|
* Throws exception on failure.
|
||||||
* Called internally within this file.
|
* Called internally within this file.
|
||||||
*/
|
*/
|
||||||
public static void check(URL url) throws IOException {
|
public static void check(URL url) throws IOException {
|
||||||
|
@ -668,8 +669,8 @@ public class URLClassPath {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* close this loader and release all resources
|
* Closes this loader and release all resources.
|
||||||
* method overridden in sub-classes
|
* Method overridden in sub-classes.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
@ -740,8 +741,8 @@ public class URLClassPath {
|
||||||
private void ensureOpen() throws IOException {
|
private void ensureOpen() throws IOException {
|
||||||
if (jar == null) {
|
if (jar == null) {
|
||||||
try {
|
try {
|
||||||
java.security.AccessController.doPrivileged(
|
AccessController.doPrivileged(
|
||||||
new java.security.PrivilegedExceptionAction<>() {
|
new PrivilegedExceptionAction<>() {
|
||||||
public Void run() throws IOException {
|
public Void run() throws IOException {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
System.err.println("Opening " + csu);
|
System.err.println("Opening " + csu);
|
||||||
|
@ -757,7 +758,7 @@ public class URLClassPath {
|
||||||
// if the same URL occurs later on the main class path. We set
|
// if the same URL occurs later on the main class path. We set
|
||||||
// Loader to null here to avoid creating a Loader for each
|
// Loader to null here to avoid creating a Loader for each
|
||||||
// URL until we actually need to try to load something from them.
|
// URL until we actually need to try to load something from them.
|
||||||
for(int i = 0; i < jarfiles.length; i++) {
|
for (int i = 0; i < jarfiles.length; i++) {
|
||||||
try {
|
try {
|
||||||
URL jarURL = new URL(csu, jarfiles[i]);
|
URL jarURL = new URL(csu, jarfiles[i]);
|
||||||
// If a non-null loader already exists, leave it alone.
|
// If a non-null loader already exists, leave it alone.
|
||||||
|
@ -773,7 +774,7 @@ public class URLClassPath {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, acc);
|
}, acc);
|
||||||
} catch (java.security.PrivilegedActionException pae) {
|
} catch (PrivilegedActionException pae) {
|
||||||
throw (IOException)pae.getException();
|
throw (IOException)pae.getException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -876,7 +877,7 @@ public class URLClassPath {
|
||||||
boolean validIndex(final String name) {
|
boolean validIndex(final String name) {
|
||||||
String packageName = name;
|
String packageName = name;
|
||||||
int pos;
|
int pos;
|
||||||
if((pos = name.lastIndexOf('/')) != -1) {
|
if ((pos = name.lastIndexOf('/')) != -1) {
|
||||||
packageName = name.substring(0, pos);
|
packageName = name.substring(0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -886,7 +887,7 @@ public class URLClassPath {
|
||||||
while (enum_.hasMoreElements()) {
|
while (enum_.hasMoreElements()) {
|
||||||
entry = enum_.nextElement();
|
entry = enum_.nextElement();
|
||||||
entryName = entry.getName();
|
entryName = entry.getName();
|
||||||
if((pos = entryName.lastIndexOf('/')) != -1)
|
if ((pos = entryName.lastIndexOf('/')) != -1)
|
||||||
entryName = entryName.substring(0, pos);
|
entryName = entryName.substring(0, pos);
|
||||||
if (entryName.equals(packageName)) {
|
if (entryName.equals(packageName)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -933,7 +934,7 @@ public class URLClassPath {
|
||||||
* visited by linking through the index files. This helper method uses
|
* visited by linking through the index files. This helper method uses
|
||||||
* a HashSet to store the URLs of jar files that have been searched and
|
* a HashSet to store the URLs of jar files that have been searched and
|
||||||
* uses it to avoid going into an infinite loop, looking for a
|
* uses it to avoid going into an infinite loop, looking for a
|
||||||
* non-existent resource
|
* non-existent resource.
|
||||||
*/
|
*/
|
||||||
Resource getResource(final String name, boolean check,
|
Resource getResource(final String name, boolean check,
|
||||||
Set<String> visited) {
|
Set<String> visited) {
|
||||||
|
@ -945,14 +946,14 @@ public class URLClassPath {
|
||||||
/* If there no jar files in the index that can potential contain
|
/* If there no jar files in the index that can potential contain
|
||||||
* this resource then return immediately.
|
* this resource then return immediately.
|
||||||
*/
|
*/
|
||||||
if((jarFilesList = index.get(name)) == null)
|
if ((jarFilesList = index.get(name)) == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int size = jarFilesList.size();
|
int size = jarFilesList.size();
|
||||||
jarFiles = jarFilesList.toArray(new String[size]);
|
jarFiles = jarFilesList.toArray(new String[size]);
|
||||||
/* loop through the mapped jar file list */
|
/* loop through the mapped jar file list */
|
||||||
while(count < size) {
|
while (count < size) {
|
||||||
String jarName = jarFiles[count++];
|
String jarName = jarFiles[count++];
|
||||||
JarLoader newLoader;
|
JarLoader newLoader;
|
||||||
final URL url;
|
final URL url;
|
||||||
|
@ -977,7 +978,7 @@ public class URLClassPath {
|
||||||
* account the relative path.
|
* account the relative path.
|
||||||
*/
|
*/
|
||||||
JarIndex newIndex = newLoader.getIndex();
|
JarIndex newIndex = newLoader.getIndex();
|
||||||
if(newIndex != null) {
|
if (newIndex != null) {
|
||||||
int pos = jarName.lastIndexOf('/');
|
int pos = jarName.lastIndexOf('/');
|
||||||
newIndex.merge(this.index, (pos == -1 ?
|
newIndex.merge(this.index, (pos == -1 ?
|
||||||
null : jarName.substring(0, pos + 1)));
|
null : jarName.substring(0, pos + 1)));
|
||||||
|
@ -986,7 +987,7 @@ public class URLClassPath {
|
||||||
/* put it in the global hashtable */
|
/* put it in the global hashtable */
|
||||||
lmap.put(urlNoFragString, newLoader);
|
lmap.put(urlNoFragString, newLoader);
|
||||||
}
|
}
|
||||||
} catch (java.security.PrivilegedActionException pae) {
|
} catch (PrivilegedActionException pae) {
|
||||||
continue;
|
continue;
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1029,7 +1030,7 @@ public class URLClassPath {
|
||||||
|
|
||||||
/* Process the index of the new loader
|
/* Process the index of the new loader
|
||||||
*/
|
*/
|
||||||
if((res = newLoader.getResource(name, check, visited))
|
if ((res = newLoader.getResource(name, check, visited))
|
||||||
!= null) {
|
!= null) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -1039,7 +1040,7 @@ public class URLClassPath {
|
||||||
jarFilesList = index.get(name);
|
jarFilesList = index.get(name);
|
||||||
|
|
||||||
// If the count is unchanged, we are done.
|
// If the count is unchanged, we are done.
|
||||||
} while(count < jarFilesList.size());
|
} while (count < jarFilesList.size());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue