Skip to content

Commit

Permalink
Code clean-up. Formatting. No functional change.
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Jan 16, 2025
1 parent 4111137 commit ea7c2bd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 66 deletions.
10 changes: 4 additions & 6 deletions java/org/apache/tomcat/util/compat/Jre16Compat.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ static boolean isSupported() {
public SocketAddress getUnixDomainSocketAddress(String path) {
try {
return (SocketAddress) unixDomainSocketAddressOfMethod.invoke(null, path);
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new UnsupportedOperationException(e);
}
}
Expand All @@ -80,8 +79,8 @@ public SocketAddress getUnixDomainSocketAddress(String path) {
@Override
public ServerSocketChannel openUnixDomainServerSocketChannel() {
try {
return (ServerSocketChannel) openServerSocketChannelFamilyMethod.invoke
(null, StandardProtocolFamily.valueOf("UNIX"));
return (ServerSocketChannel) openServerSocketChannelFamilyMethod.invoke(null,
StandardProtocolFamily.valueOf("UNIX"));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new UnsupportedOperationException(e);
}
Expand All @@ -91,8 +90,7 @@ public ServerSocketChannel openUnixDomainServerSocketChannel() {
@Override
public SocketChannel openUnixDomainSocketChannel() {
try {
return (SocketChannel) openSocketChannelFamilyMethod.invoke
(null, StandardProtocolFamily.valueOf("UNIX"));
return (SocketChannel) openSocketChannelFamilyMethod.invoke(null, StandardProtocolFamily.valueOf("UNIX"));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new UnsupportedOperationException(e);
}
Expand Down
8 changes: 3 additions & 5 deletions java/org/apache/tomcat/util/compat/Jre19Compat.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ public Object getExecutor(Thread thread)
return null;
}

if (task!= null && task.getClass().getCanonicalName() != null &&
(task.getClass().getCanonicalName().equals(
"org.apache.tomcat.util.threads.ThreadPoolExecutor.Worker") ||
task.getClass().getCanonicalName().equals(
"java.util.concurrent.ThreadPoolExecutor.Worker"))) {
if (task != null && task.getClass().getCanonicalName() != null && (task.getClass().getCanonicalName()
.equals("org.apache.tomcat.util.threads.ThreadPoolExecutor.Worker") ||
task.getClass().getCanonicalName().equals("java.util.concurrent.ThreadPoolExecutor.Worker"))) {
Field executorField = task.getClass().getDeclaredField("this$0");
executorField.setAccessible(true);
result = executorField.get(task);
Expand Down
3 changes: 1 addition & 2 deletions java/org/apache/tomcat/util/compat/Jre9Compat.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ public void addBootModulePath(Deque<URL> classPathUrlsToProcess) {
@Override
public JarFile jarFileNewInstance(File f) throws IOException {
try {
return jarFileConstructor.newInstance(
f, Boolean.TRUE, Integer.valueOf(ZipFile.OPEN_READ), RUNTIME_VERSION);
return jarFileConstructor.newInstance(f, Boolean.TRUE, Integer.valueOf(ZipFile.OPEN_READ), RUNTIME_VERSION);
} catch (ReflectiveOperationException | IllegalArgumentException e) {
throw new IOException(e);
}
Expand Down
71 changes: 30 additions & 41 deletions java/org/apache/tomcat/util/compat/JreCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
import org.apache.tomcat.util.res.StringManager;

/**
* This is the base implementation class for JRE compatibility and provides an
* implementation based on Java 8. Sub-classes may extend this class and provide
* alternative implementations for later JRE versions
* This is the base implementation class for JRE compatibility and provides an implementation based on Java 8.
* Sub-classes may extend this class and provide alternative implementations for later JRE versions
*/
public class JreCompat {

Expand Down Expand Up @@ -181,13 +180,11 @@ public static boolean isJre22Available() {
// Java 8 implementation of Java 9 methods

/**
* Test if the provided exception is an instance of
* java.lang.reflect.InaccessibleObjectException.
* Test if the provided exception is an instance of java.lang.reflect.InaccessibleObjectException.
*
* @param t The exception to test
*
* @return {@code true} if the exception is an instance of
* InaccessibleObjectException, otherwise {@code false}
* @return {@code true} if the exception is an instance of InaccessibleObjectException, otherwise {@code false}
*/
public boolean isInstanceOfInaccessibleObjectException(Throwable t) {
// Exception does not exist prior to Java 9
Expand All @@ -199,8 +196,7 @@ public boolean isInstanceOfInaccessibleObjectException(Throwable t) {
* Set the application protocols the server will accept for ALPN
*
* @param sslParameters The SSL parameters for a connection
* @param protocols The application protocols to be allowed for that
* connection
* @param protocols The application protocols to be allowed for that connection
*/
public void setApplicationProtocols(SSLParameters sslParameters, String[] protocols) {
if (setApplicationProtocolsMethod != null) {
Expand All @@ -216,11 +212,9 @@ public void setApplicationProtocols(SSLParameters sslParameters, String[] protoc


/**
* Get the application protocol that has been negotiated for connection
* associated with the given SSLEngine.
* Get the application protocol that has been negotiated for connection associated with the given SSLEngine.
*
* @param sslEngine The SSLEngine for which to obtain the negotiated
* protocol
* @param sslEngine The SSLEngine for which to obtain the negotiated protocol
*
* @return The name of the negotiated protocol
*/
Expand All @@ -238,8 +232,8 @@ public String getApplicationProtocol(SSLEngine sslEngine) {


/**
* Disables caching for JAR URL connections. For Java 8 and earlier, this also disables
* caching for ALL URL connections.
* Disables caching for JAR URL connections. For Java 8 and earlier, this also disables caching for ALL URL
* connections.
*
* @throws IOException If a dummy JAR URLConnection can not be created
*/
Expand All @@ -253,42 +247,38 @@ public void disableCachingForJarUrlConnections() throws IOException {


/**
* Obtains the URLs for all the JARs on the module path when the JVM starts
* and adds them to the provided Deque.
* Obtains the URLs for all the JARs on the module path when the JVM starts and adds them to the provided Deque.
*
* @param classPathUrlsToProcess The Deque to which the modules should be
* added
* @param classPathUrlsToProcess The Deque to which the modules should be added
*/
public void addBootModulePath(Deque<URL> classPathUrlsToProcess) {
// NO-OP for Java 8. There is no module path.
}


/**
* Creates a new JarFile instance. When running on Java 9 and later, the
* JarFile will be multi-release JAR aware. While this isn't strictly
* required to be in this package, it is provided as a convenience method.
* Creates a new JarFile instance. When running on Java 9 and later, the JarFile will be multi-release JAR aware.
* While this isn't strictly required to be in this package, it is provided as a convenience method.
*
* @param s The JAR file to open
*
* @return A JarFile instance based on the provided path
*
* @throws IOException If an I/O error occurs creating the JarFile instance
* @throws IOException If an I/O error occurs creating the JarFile instance
*/
public final JarFile jarFileNewInstance(String s) throws IOException {
return jarFileNewInstance(new File(s));
}


/**
* Creates a new JarFile instance. When running on Java 9 and later, the
* JarFile will be multi-release JAR aware.
* Creates a new JarFile instance. When running on Java 9 and later, the JarFile will be multi-release JAR aware.
*
* @param f The JAR file to open
*
* @return A JarFile instance based on the provided file
*
* @throws IOException If an I/O error occurs creating the JarFile instance
* @throws IOException If an I/O error occurs creating the JarFile instance
*/
public JarFile jarFileNewInstance(File f) throws IOException {
return new JarFile(f);
Expand All @@ -298,10 +288,9 @@ public JarFile jarFileNewInstance(File f) throws IOException {
/**
* Is this JarFile a multi-release JAR file.
*
* @param jarFile The JarFile to test
* @param jarFile The JarFile to test
*
* @return {@code true} If it is a multi-release JAR file and is configured
* to behave as such.
* @return {@code true} If it is a multi-release JAR file and is configured to behave as such.
*/
public boolean jarFileIsMultiRelease(JarFile jarFile) {
// Java 8 doesn't support multi-release so default to false
Expand All @@ -315,14 +304,12 @@ public int jarFileRuntimeMajorVersion() {


/**
* Is the accessibleObject accessible (as a result of appropriate module
* exports) on the provided instance?
* Is the accessibleObject accessible (as a result of appropriate module exports) on the provided instance?
*
* @param base The specific instance to be tested.
* @param accessibleObject The method/field/constructor to be tested.
* @param base The specific instance to be tested.
* @param accessibleObject The method/field/constructor to be tested.
*
* @return {code true} if the AccessibleObject can be accessed otherwise
* {code false}
* @return {code true} if the AccessibleObject can be accessed otherwise {code false}
*/
public boolean canAccess(Object base, AccessibleObject accessibleObject) {
// Java 8 doesn't support modules so default to true
Expand All @@ -333,10 +320,9 @@ public boolean canAccess(Object base, AccessibleObject accessibleObject) {
/**
* Is the given class in an exported package?
*
* @param type The class to test
* @param type The class to test
*
* @return Always {@code true} for Java 8. {@code true} if the enclosing
* package is exported for Java 9+
* @return Always {@code true} for Java 8. {@code true} if the enclosing package is exported for Java 9+
*/
public boolean isExported(Class<?> type) {
return true;
Expand All @@ -346,10 +332,9 @@ public boolean isExported(Class<?> type) {
/**
* What is the module of the given class?
*
* @param type The class to test
* @param type The class to test
*
* @return Always {@code true} for Java 8. {@code true} if the enclosing
* package is exported for Java 9+
* @return Always {@code true} for Java 8. {@code true} if the enclosing package is exported for Java 9+
*/
public String getModuleName(Class<?> type) {
return "NO_MODULE_JAVA_8";
Expand All @@ -360,7 +345,9 @@ public String getModuleName(Class<?> type) {

/**
* Return Unix domain socket address for given path.
*
* @param path The path
*
* @return the socket address
*/
public SocketAddress getUnixDomainSocketAddress(String path) {
Expand All @@ -370,6 +357,7 @@ public SocketAddress getUnixDomainSocketAddress(String path) {

/**
* Create server socket channel using the Unix domain socket ProtocolFamily.
*
* @return the server socket channel
*/
public ServerSocketChannel openUnixDomainServerSocketChannel() {
Expand All @@ -379,6 +367,7 @@ public ServerSocketChannel openUnixDomainServerSocketChannel() {

/**
* Create socket channel using the Unix domain socket ProtocolFamily.
*
* @return the socket channel
*/
public SocketChannel openUnixDomainSocketChannel() {
Expand Down
13 changes: 6 additions & 7 deletions java/org/apache/tomcat/util/compat/JrePlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ public class JrePlatform {

static {
/*
* There are a few places where a) the behaviour of the Java API depends
* on the underlying platform and b) those behavioural differences have
* an impact on Tomcat.
* There are a few places where a) the behaviour of the Java API depends on the underlying platform and b) those
* behavioural differences have an impact on Tomcat.
*
* Tomcat therefore needs to be able to determine the platform it is
* running on to account for those differences.
* Tomcat therefore needs to be able to determine the platform it is running on to account for those
* differences.
*
* In an ideal world this code would not exist.
*/
Expand All @@ -41,8 +40,8 @@ public class JrePlatform {
if (System.getSecurityManager() == null) {
osName = System.getProperty(OS_NAME_PROPERTY);
} else {
osName = AccessController.doPrivileged(
(PrivilegedAction<String>) () -> System.getProperty(OS_NAME_PROPERTY));
osName = AccessController
.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(OS_NAME_PROPERTY));
}

IS_MAC_OS = osName.toLowerCase(Locale.ENGLISH).startsWith("mac os x");
Expand Down
8 changes: 3 additions & 5 deletions java/org/apache/tomcat/util/compat/JreVendor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ public class JreVendor {

static {
/*
* There are a few places where Tomcat either accesses JVM internals
* (e.g. the memory leak protection) or where feature support varies
* between JVMs (e.g. SPNEGO). These flags exist to enable Tomcat to
* adjust its behaviour based on the vendor of the JVM. In an ideal
* world this code would not exist.
* There are a few places where Tomcat either accesses JVM internals (e.g. the memory leak protection) or where
* feature support varies between JVMs (e.g. SPNEGO). These flags exist to enable Tomcat to adjust its behaviour
* based on the vendor of the JVM. In an ideal world this code would not exist.
*/
String vendor = System.getProperty("java.vendor", "");
vendor = vendor.toLowerCase(Locale.ENGLISH);
Expand Down

0 comments on commit ea7c2bd

Please sign in to comment.