This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 87d0167c53 Prepare to backport trim() -> strip() changes
87d0167c53 is described below
commit 87d0167c539281be48e42c98c8319884c2c7e765
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Oct 28 12:08:11 2026 +0000
Prepare to backport trim() -> strip() changes
---
java/javax/el/Jre11Compat.java | 52 ++++++++++++++
java/javax/el/JreCompat.java | 19 ++++-
java/org/apache/el/util/JreCompat.java | 2 +-
.../org/apache/tomcat/util/compat/Jre11Compat.java | 80 ++++++++++++++++++++++
.../org/apache/tomcat/util/compat/Jre12Compat.java | 2 +-
java/org/apache/tomcat/util/compat/JreCompat.java | 50 +++++++++++++-
6 files changed, 200 insertions(+), 5 deletions(-)
diff --git a/java/javax/el/Jre11Compat.java b/java/javax/el/Jre11Compat.java
new file mode 100644
index 0000000000..3c6ae93e79
--- /dev/null
+++ b/java/javax/el/Jre11Compat.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package javax.el;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+class Jre11Compat extends Jre9Compat {
+
+ private static final Method stripMethod;
+
+ static {
+ Method m1 = null;
+
+ try {
+ m1 = String.class.getMethod("strip");
+ } catch (NoSuchMethodException e) {
+ // Must be pre-Java 11
+ }
+
+ stripMethod = m1;
+ }
+
+
+ public static boolean isSupported() {
+ return stripMethod != null;
+ }
+
+
+ @Override
+ public String strip(String input) {
+ try {
+ return (String) stripMethod.invoke(input);
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new UnsupportedOperationException(e);
+ }
+ }
+}
diff --git a/java/javax/el/JreCompat.java b/java/javax/el/JreCompat.java
index bed8e91dc7..eabed0b78a 100644
--- a/java/javax/el/JreCompat.java
+++ b/java/javax/el/JreCompat.java
@@ -23,14 +23,16 @@ import java.lang.reflect.AccessibleObject;
* only the methods required by the EL implementation.
*
* This class is duplicated in org.apache.el.util
- * When making changes keep the two in sync.
+ * When making changes keep the two in sync if required.
*/
class JreCompat {
private static final JreCompat instance;
static {
- if (Jre9Compat.isSupported()) {
+ if (Jre11Compat.isSupported()) {
+ instance = new Jre11Compat();
+ } else if (Jre9Compat.isSupported()) {
instance = new Jre9Compat();
} else {
instance = new JreCompat();
@@ -67,4 +69,17 @@ class JreCompat {
public boolean isExported(Class<?> type) {
return true;
}
+
+
+ public String strip(String input) {
+ int start = 0;
+ int end = input.length();
+ while (start < end && Character.isWhitespace(input.charAt(start))) {
+ start++;
+ }
+ while (end > start && Character.isWhitespace(input.charAt(end - 1))) {
+ end--;
+ }
+ return input.substring(start, end);
+ }
}
diff --git a/java/org/apache/el/util/JreCompat.java
b/java/org/apache/el/util/JreCompat.java
index 114e07d601..42531d5edb 100644
--- a/java/org/apache/el/util/JreCompat.java
+++ b/java/org/apache/el/util/JreCompat.java
@@ -23,7 +23,7 @@ import java.lang.reflect.AccessibleObject;
* only the methods required by the EL implementation.
*
* This class is duplicated in javax.el
- * When making changes keep the two in sync.
+ * When making changes keep the two in sync if required.
*/
public class JreCompat {
diff --git a/java/org/apache/tomcat/util/compat/Jre11Compat.java
b/java/org/apache/tomcat/util/compat/Jre11Compat.java
new file mode 100644
index 0000000000..37dc35b7c9
--- /dev/null
+++ b/java/org/apache/tomcat/util/compat/Jre11Compat.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.util.compat;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public class Jre11Compat extends Jre9Compat {
+
+ private static final Method stripMethod;
+ private static final Method stripLeadingMethod;
+ private static final Method stripTrailingMethod;
+
+ static {
+ Method m1 = null;
+ Method m2 = null;
+ Method m3 = null;
+
+ try {
+ m1 = String.class.getMethod("strip");
+ m2 = String.class.getMethod("stripLeading");
+ m3 = String.class.getMethod("stripTrailing");
+ } catch (NoSuchMethodException e) {
+ // Must be pre-Java 11
+ }
+
+ stripMethod = m1;
+ stripLeadingMethod = m2;
+ stripTrailingMethod = m3;
+ }
+
+
+ static boolean isSupported() {
+ return stripMethod != null;
+ }
+
+
+ @Override
+ public String strip(String input) {
+ try {
+ return (String) stripMethod.invoke(input);
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new UnsupportedOperationException(e);
+ }
+ }
+
+
+ @Override
+ public String stripLeading(String input) {
+ try {
+ return (String) stripLeadingMethod.invoke(input);
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new UnsupportedOperationException(e);
+ }
+ }
+
+
+ @Override
+ public String stripTrailing(String input) {
+ try {
+ return (String) stripTrailingMethod.invoke(input);
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new UnsupportedOperationException(e);
+ }
+ }
+}
diff --git a/java/org/apache/tomcat/util/compat/Jre12Compat.java
b/java/org/apache/tomcat/util/compat/Jre12Compat.java
index 45080aff45..9d0e5f2174 100644
--- a/java/org/apache/tomcat/util/compat/Jre12Compat.java
+++ b/java/org/apache/tomcat/util/compat/Jre12Compat.java
@@ -30,7 +30,7 @@ import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.ExceptionUtils;
import org.apache.tomcat.util.res.StringManager;
-public class Jre12Compat extends Jre9Compat {
+public class Jre12Compat extends Jre11Compat {
private static final Log log = LogFactory.getLog(Jre12Compat.class);
private static final StringManager sm =
StringManager.getManager(Jre12Compat.class);
diff --git a/java/org/apache/tomcat/util/compat/JreCompat.java
b/java/org/apache/tomcat/util/compat/JreCompat.java
index 1dca693970..d20a40aed4 100644
--- a/java/org/apache/tomcat/util/compat/JreCompat.java
+++ b/java/org/apache/tomcat/util/compat/JreCompat.java
@@ -102,6 +102,7 @@ public class JreCompat {
jre19Available = true;
jre16Available = true;
jre12Available = true;
+ jre11Available = true;
jre9Available = true;
} else if (Jre21Compat.isSupported()) {
instance = new Jre21Compat();
@@ -111,6 +112,7 @@ public class JreCompat {
jre19Available = true;
jre16Available = true;
jre12Available = true;
+ jre11Available = true;
jre9Available = true;
} else if (Jre20Compat.isSupported()) {
instance = new Jre20Compat();
@@ -120,6 +122,7 @@ public class JreCompat {
jre19Available = true;
jre16Available = true;
jre12Available = true;
+ jre11Available = true;
jre9Available = true;
} else if (Jre19Compat.isSupported()) {
instance = new Jre19Compat();
@@ -129,6 +132,7 @@ public class JreCompat {
jre19Available = true;
jre16Available = true;
jre12Available = true;
+ jre11Available = true;
jre9Available = true;
} else if (Jre16Compat.isSupported()) {
instance = new Jre16Compat();
@@ -138,6 +142,7 @@ public class JreCompat {
jre19Available = false;
jre16Available = true;
jre12Available = true;
+ jre11Available = true;
jre9Available = true;
} else if (Jre12Compat.isSupported()) {
instance = new Jre12Compat();
@@ -147,6 +152,17 @@ public class JreCompat {
jre19Available = false;
jre16Available = false;
jre12Available = true;
+ jre11Available = true;
+ jre9Available = true;
+ } else if (Jre11Compat.isSupported()) {
+ instance = new Jre11Compat();
+ jre22Available = false;
+ jre21Available = false;
+ jre20Available = false;
+ jre19Available = false;
+ jre16Available = false;
+ jre12Available = false;
+ jre11Available = true;
jre9Available = true;
} else if (Jre9Compat.isSupported()) {
instance = new Jre9Compat();
@@ -156,6 +172,7 @@ public class JreCompat {
jre19Available = false;
jre16Available = false;
jre12Available = false;
+ jre11Available = false;
jre9Available = true;
} else {
instance = new JreCompat();
@@ -165,9 +182,9 @@ public class JreCompat {
jre19Available = false;
jre16Available = false;
jre12Available = false;
+ jre11Available = false;
jre9Available = false;
}
- jre11Available = instance.jarFileRuntimeMajorVersion() >= 11;
Method m1 = null;
Method m2 = null;
@@ -676,4 +693,35 @@ public class JreCompat {
throw new
UnsupportedOperationException(sm.getString("jreCompat.noNamedGroups"));
}
+
+ public String strip(String input) {
+ return strip(input, true, true);
+ }
+
+
+ public String stripLeading(String input) {
+ return strip(input, true, false);
+ }
+
+
+ public String stripTrailing(String input) {
+ return strip(input, false, true);
+ }
+
+
+ private String strip(String input, boolean leading, boolean trailing) {
+ int start = 0;
+ int end = input.length();
+ if (leading) {
+ while (start < end && Character.isWhitespace(input.charAt(start)))
{
+ start++;
+ }
+ }
+ if (trailing) {
+ while (end > start && Character.isWhitespace(input.charAt(end -
1))) {
+ end--;
+ }
+ }
+ return input.substring(start, end);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]