This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/11.0.x by this push:
     new 6a98907df5 Better warning on Java 18 to 20
6a98907df5 is described below

commit 6a98907df5ccfa268e679f5af1946626cf63c3a6
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Feb 21 18:13:57 2025 +0000

    Better warning on Java 18 to 20
---
 java/org/apache/tomcat/util/compat/JreCompat.java          | 9 ++++++---
 java/org/apache/tomcat/util/compat/LocalStrings.properties | 3 ++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/tomcat/util/compat/JreCompat.java 
b/java/org/apache/tomcat/util/compat/JreCompat.java
index d40a6413c9..356b384957 100644
--- a/java/org/apache/tomcat/util/compat/JreCompat.java
+++ b/java/org/apache/tomcat/util/compat/JreCompat.java
@@ -312,16 +312,19 @@ public class JreCompat {
                 f.setAccessible(true);
 
                 /*
-                 * Need this in Java 17 (and it only works in Java 17) because 
the 'useCanonCaches' field is final.
+                 * Need this in Java 17 because the 'useCanonCaches' field is 
final.
                  *
                  * This will fail in Java 18 to 20 but since those versions 
are no longer supported it is acceptable for
                  * the attempt to set the 'useCanonCaches' field to fail. 
Users that really want to use Java 18 to 20
                  * will have to ensure that they do not explicitly enable the 
canonical file name cache.
                  */
-                VarHandle modifiers;
                 Lookup lookup = MethodHandles.privateLookupIn(Field.class, 
MethodHandles.lookup());
-                modifiers = lookup.findVarHandle(Field.class, "modifiers", 
int.class);
+                VarHandle modifiers = lookup.findVarHandle(Field.class, 
"modifiers", int.class);
                 modifiers.set(f, f.getModifiers() & ~Modifier.FINAL);
+            } catch (UnsupportedOperationException e) {
+                // Make sure field is not set.
+                f = null;
+                log.warn(sm.getString("jreCompat.useCanonCaches.java18"), e);
             } catch (InaccessibleObjectException | 
ReflectiveOperationException | IllegalArgumentException e) {
                 // Make sure field is not set.
                 f = null;
diff --git a/java/org/apache/tomcat/util/compat/LocalStrings.properties 
b/java/org/apache/tomcat/util/compat/LocalStrings.properties
index d538e562c6..a4da389b25 100644
--- a/java/org/apache/tomcat/util/compat/LocalStrings.properties
+++ b/java/org/apache/tomcat/util/compat/LocalStrings.properties
@@ -22,4 +22,5 @@ jre22Compat.javaPre22=Class not found so assuming code is 
running on a pre-Java
 
 jreCompat.useCanonCaches.failed=Failed to set the 
java.io.FileSystem.useCanonCaches static field
 jreCompat.useCanonCaches.init=Unable to create a reference to the 
java.io.FileSystem.useCanonCaches static field
-jreCompat.useCanonCaches.none=No reference to the 
java.io.FileSystem.useCanonCaches static field available. Enable debug logging 
for more information.
+jreCompat.useCanonCaches.java18=If using Java 18 to Java 20 inclusive, you 
must not enabled the canonical file name cache using 
-Dsun.io.useCanonCaches=true on the command line as Tomcat is unable to disable 
the cache via reflection on those Java versions
+jreCompat.useCanonCaches.none=No reference to the 
java.io.FileSystem.useCanonCaches static field available


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to