You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2024/08/09 14:21:45 UTC
(tomcat) 05/06: Code clean-up - no functional change
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 27d25ec2545a45abb02e64c392b7176af1a8e96b
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Aug 9 15:19:52 2024 +0100
Code clean-up - no functional change
---
java/org/apache/el/util/ConcurrentCache.java | 2 +-
java/org/apache/el/util/ExceptionUtils.java | 11 +-
java/org/apache/el/util/ReflectionUtil.java | 146 ++++++++++++---------------
java/org/apache/el/util/Validation.java | 24 ++---
4 files changed, 82 insertions(+), 101 deletions(-)
diff --git a/java/org/apache/el/util/ConcurrentCache.java b/java/org/apache/el/util/ConcurrentCache.java
index 1be17abaa8..ae37cfb9e6 100644
--- a/java/org/apache/el/util/ConcurrentCache.java
+++ b/java/org/apache/el/util/ConcurrentCache.java
@@ -20,7 +20,7 @@ import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
-public final class ConcurrentCache<K,V> {
+public final class ConcurrentCache<K, V> {
private final int size;
diff --git a/java/org/apache/el/util/ExceptionUtils.java b/java/org/apache/el/util/ExceptionUtils.java
index 7c3c054d9f..f8e7dafb10 100644
--- a/java/org/apache/el/util/ExceptionUtils.java
+++ b/java/org/apache/el/util/ExceptionUtils.java
@@ -25,8 +25,8 @@ package org.apache.el.util;
public class ExceptionUtils {
/**
- * Checks whether the supplied Throwable is one that needs to be
- * rethrown and swallows all others.
+ * Checks whether the supplied Throwable is one that needs to be rethrown and swallows all others.
+ *
* @param t the Throwable to check
*/
public static void handleThrowable(Throwable t) {
@@ -42,10 +42,9 @@ public class ExceptionUtils {
/**
- * NO-OP method provided to enable simple pre-loading of this class. Since
- * the class is used extensively in error handling, it is prudent to
- * pre-load it to avoid any failure to load this class masking the true
- * problem during error handling.
+ * NO-OP method provided to enable simple pre-loading of this class. Since the class is used extensively in error
+ * handling, it is prudent to pre-load it to avoid any failure to load this class masking the true problem during
+ * error handling.
*/
public static void preload() {
// NO-OP
diff --git a/java/org/apache/el/util/ReflectionUtil.java b/java/org/apache/el/util/ReflectionUtil.java
index 9d9d0f4d93..6693d46648 100644
--- a/java/org/apache/el/util/ReflectionUtil.java
+++ b/java/org/apache/el/util/ReflectionUtil.java
@@ -38,12 +38,11 @@ import org.apache.el.lang.EvaluationContext;
*/
public class ReflectionUtil {
- protected static final String[] PRIMITIVE_NAMES = new String[] { "boolean",
- "byte", "char", "double", "float", "int", "long", "short", "void" };
+ protected static final String[] PRIMITIVE_NAMES =
+ new String[] { "boolean", "byte", "char", "double", "float", "int", "long", "short", "void" };
- protected static final Class<?>[] PRIMITIVES = new Class[] { boolean.class,
- byte.class, char.class, double.class, float.class, int.class,
- long.class, short.class, Void.TYPE };
+ protected static final Class<?>[] PRIMITIVES = new Class[] { boolean.class, byte.class, char.class, double.class,
+ float.class, int.class, long.class, short.class, Void.TYPE };
private ReflectionUtil() {
super();
@@ -78,10 +77,12 @@ public class ReflectionUtil {
/**
* Converts an array of Class names to Class types.
- * @param s The array of class names
- * @return An array of Class instance where the element at index i in the
- * result is an instance of the class with the name at index i in
- * the input
+ *
+ * @param s The array of class names
+ *
+ * @return An array of Class instance where the element at index i in the result is an instance of the class with
+ * the name at index i in the input
+ *
* @throws ClassNotFoundException If a class of a given name cannot be found
*/
public static Class<?>[] toTypeArray(String[] s) throws ClassNotFoundException {
@@ -97,9 +98,11 @@ public class ReflectionUtil {
/**
* Converts an array of Class types to Class names.
+ *
* @param c The array of class instances
- * @return An array of Class names where the element at index i in the
- * result is the name of the class instance at index i in the input
+ *
+ * @return An array of Class names where the element at index i in the result is the name of the class instance at
+ * index i in the input
*/
public static String[] toTypeNameArray(Class<?>[] c) {
if (c == null) {
@@ -114,32 +117,30 @@ public class ReflectionUtil {
/**
* Returns a method based on the criteria.
- * @param ctx the context in which the expression is being evaluated
- * @param base the object that owns the method
- * @param property the name of the method
- * @param paramTypes the parameter types to use
+ *
+ * @param ctx the context in which the expression is being evaluated
+ * @param base the object that owns the method
+ * @param property the name of the method
+ * @param paramTypes the parameter types to use
* @param paramValues the parameter values
+ *
* @return the method specified
- * @throws MethodNotFoundException If a method cannot be found that matches
- * the given criteria
+ *
+ * @throws MethodNotFoundException If a method cannot be found that matches the given criteria
*/
/*
- * This class duplicates code in jakarta.el.Util. When making changes keep
- * the code in sync.
+ * This class duplicates code in jakarta.el.Util. When making changes keep the code in sync.
*/
@SuppressWarnings("null")
- public static Method getMethod(EvaluationContext ctx, Object base, Object property,
- Class<?>[] paramTypes, Object[] paramValues)
- throws MethodNotFoundException {
+ public static Method getMethod(EvaluationContext ctx, Object base, Object property, Class<?>[] paramTypes,
+ Object[] paramValues) throws MethodNotFoundException {
if (base == null || property == null) {
- throw new MethodNotFoundException(MessageFactory.get(
- "error.method.notfound", base, property,
- paramString(paramTypes)));
+ throw new MethodNotFoundException(
+ MessageFactory.get("error.method.notfound", base, property, paramString(paramTypes)));
}
- String methodName = (property instanceof String) ? (String) property
- : property.toString();
+ String methodName = (property instanceof String) ? (String) property : property.toString();
int paramCount;
if (paramTypes == null) {
@@ -166,17 +167,16 @@ public class ReflectionUtil {
// Method has wrong number of parameters
continue;
}
- if (m.isVarArgs() && paramCount < mParamCount -1) {
+ if (m.isVarArgs() && paramCount < mParamCount - 1) {
// Method has wrong number of parameters
continue;
}
- if (m.isVarArgs() && paramCount == mParamCount && paramValues != null &&
- paramValues.length > paramCount && !paramTypes[mParamCount -1].isArray()) {
+ if (m.isVarArgs() && paramCount == mParamCount && paramValues != null && paramValues.length > paramCount &&
+ !paramTypes[mParamCount - 1].isArray()) {
// Method arguments don't match
continue;
}
- if (m.isVarArgs() && paramCount > mParamCount && paramValues != null &&
- paramValues.length != paramCount) {
+ if (m.isVarArgs() && paramCount > mParamCount && paramValues != null && paramValues.length != paramCount) {
// Might match a different varargs method
continue;
}
@@ -252,15 +252,14 @@ public class ReflectionUtil {
if (exactMatch == paramCount && varArgsMatch == 0) {
Method result = getMethod(base.getClass(), base, m);
if (result == null) {
- throw new MethodNotFoundException(MessageFactory.get(
- "error.method.notfound", base, property,
- paramString(paramTypes)));
+ throw new MethodNotFoundException(
+ MessageFactory.get("error.method.notfound", base, property, paramString(paramTypes)));
}
return result;
}
- candidates.put(m, new MatchResult(
- m.isVarArgs(), exactMatch, assignableMatch, coercibleMatch, varArgsMatch, m.isBridge()));
+ candidates.put(m, new MatchResult(m.isVarArgs(), exactMatch, assignableMatch, coercibleMatch, varArgsMatch,
+ m.isBridge()));
}
// Look for the method that has the highest number of parameters where
@@ -268,7 +267,7 @@ public class ReflectionUtil {
MatchResult bestMatch = new MatchResult(true, 0, 0, 0, 0, true);
Method match = null;
boolean multiple = false;
- for (Map.Entry<Method, MatchResult> entry : candidates.entrySet()) {
+ for (Map.Entry<Method,MatchResult> entry : candidates.entrySet()) {
int cmp = entry.getValue().compareTo(bestMatch);
if (cmp > 0 || match == null) {
bestMatch = entry.getValue();
@@ -290,34 +289,29 @@ public class ReflectionUtil {
if (match == null) {
// If multiple methods have the same matching number of parameters
// the match is ambiguous so throw an exception
- throw new MethodNotFoundException(MessageFactory.get(
- "error.method.ambiguous", base, property,
- paramString(paramTypes)));
- }
+ throw new MethodNotFoundException(
+ MessageFactory.get("error.method.ambiguous", base, property, paramString(paramTypes)));
+ }
}
// Handle case where no match at all was found
if (match == null) {
- throw new MethodNotFoundException(MessageFactory.get(
- "error.method.notfound", base, property,
- paramString(paramTypes)));
+ throw new MethodNotFoundException(
+ MessageFactory.get("error.method.notfound", base, property, paramString(paramTypes)));
}
Method result = getMethod(base.getClass(), base, match);
if (result == null) {
- throw new MethodNotFoundException(MessageFactory.get(
- "error.method.notfound", base, property,
- paramString(paramTypes)));
+ throw new MethodNotFoundException(
+ MessageFactory.get("error.method.notfound", base, property, paramString(paramTypes)));
}
return result;
}
/*
- * This class duplicates code in jakarta.el.Util. When making changes keep
- * the code in sync.
+ * This class duplicates code in jakarta.el.Util. When making changes keep the code in sync.
*/
- private static Method resolveAmbiguousMethod(Set<Method> candidates,
- Class<?>[] paramTypes) {
+ private static Method resolveAmbiguousMethod(Set<Method> candidates, Class<?>[] paramTypes) {
// Identify which parameter isn't an exact match
Method m = candidates.iterator().next();
@@ -338,12 +332,11 @@ public class ReflectionUtil {
}
for (Method c : candidates) {
- if (c.getParameterTypes()[nonMatchIndex] ==
- paramTypes[nonMatchIndex]) {
- // Methods have different non-matching parameters
- // Result is ambiguous
- return null;
- }
+ if (c.getParameterTypes()[nonMatchIndex] == paramTypes[nonMatchIndex]) {
+ // Methods have different non-matching parameters
+ // Result is ambiguous
+ return null;
+ }
}
// Can't be null
@@ -363,8 +356,7 @@ public class ReflectionUtil {
if (Number.class.isAssignableFrom(nonMatchClass)) {
for (Method c : candidates) {
Class<?> candidateType = c.getParameterTypes()[nonMatchIndex];
- if (Number.class.isAssignableFrom(candidateType) ||
- candidateType.isPrimitive()) {
+ if (Number.class.isAssignableFrom(candidateType) || candidateType.isPrimitive()) {
if (match == null) {
match = c;
} else {
@@ -381,8 +373,7 @@ public class ReflectionUtil {
/*
- * This class duplicates code in jakarta.el.Util. When making changes keep
- * the code in sync.
+ * This class duplicates code in jakarta.el.Util. When making changes keep the code in sync.
*/
private static boolean isAssignableFrom(Class<?> src, Class<?> target) {
// src will always be an object
@@ -419,12 +410,11 @@ public class ReflectionUtil {
/*
- * This class duplicates code in jakarta.el.Util. When making changes keep
- * the code in sync.
+ * This class duplicates code in jakarta.el.Util. When making changes keep the code in sync.
*/
private static boolean isCoercibleFrom(EvaluationContext ctx, Object src, Class<?> target) {
// TODO: This isn't pretty but it works. Significant refactoring would
- // be required to avoid the exception.
+ // be required to avoid the exception.
try {
ELSupport.coerceToType(ctx, src, target);
} catch (ELException e) {
@@ -435,13 +425,11 @@ public class ReflectionUtil {
/*
- * This class duplicates code in jakarta.el.Util. When making changes keep
- * the code in sync.
+ * This class duplicates code in jakarta.el.Util. When making changes keep the code in sync.
*/
private static Method getMethod(Class<?> type, Object base, Method m) {
- if (m == null ||
- (Modifier.isPublic(type.getModifiers()) &&
- (Modifier.isStatic(m.getModifiers()) && m.canAccess(null) || m.canAccess(base)))) {
+ if (m == null || (Modifier.isPublic(type.getModifiers()) &&
+ (Modifier.isStatic(m.getModifiers()) && m.canAccess(null) || m.canAccess(base)))) {
return m;
}
Class<?>[] interfaces = type.getInterfaces();
@@ -493,8 +481,7 @@ public class ReflectionUtil {
/*
- * This class duplicates code in jakarta.el.Util. When making changes keep
- * the code in sync.
+ * This class duplicates code in jakarta.el.Util. When making changes keep the code in sync.
*/
private static class MatchResult implements Comparable<MatchResult> {
@@ -568,14 +555,13 @@ public class ReflectionUtil {
@Override
public boolean equals(Object o) {
- return o == this || (null != o &&
- this.getClass().equals(o.getClass()) &&
- ((MatchResult)o).getExactCount() == this.getExactCount() &&
- ((MatchResult)o).getAssignableCount() == this.getAssignableCount() &&
- ((MatchResult)o).getCoercible() == this.getCoercible() &&
- ((MatchResult)o).getVarArgsCount() == this.getVarArgsCount() &&
- ((MatchResult)o).isVarArgs() == this.isVarArgs() &&
- ((MatchResult)o).isBridge() == this.isBridge());
+ return o == this || (null != o && this.getClass().equals(o.getClass()) &&
+ ((MatchResult) o).getExactCount() == this.getExactCount() &&
+ ((MatchResult) o).getAssignableCount() == this.getAssignableCount() &&
+ ((MatchResult) o).getCoercible() == this.getCoercible() &&
+ ((MatchResult) o).getVarArgsCount() == this.getVarArgsCount() &&
+ ((MatchResult) o).isVarArgs() == this.isVarArgs() &&
+ ((MatchResult) o).isBridge() == this.isBridge());
}
@Override
diff --git a/java/org/apache/el/util/Validation.java b/java/org/apache/el/util/Validation.java
index 0b6142b226..b9c60df265 100644
--- a/java/org/apache/el/util/Validation.java
+++ b/java/org/apache/el/util/Validation.java
@@ -19,17 +19,15 @@ package org.apache.el.util;
public class Validation {
// Java keywords, boolean literals & the null literal in alphabetical order
- private static final String invalidIdentifiers[] = { "abstract", "assert",
- "boolean", "break", "byte", "case", "catch", "char", "class", "const",
- "continue", "default", "do", "double", "else", "enum", "extends",
- "false", "final", "finally", "float", "for", "goto", "if", "implements",
- "import", "instanceof", "int", "interface", "long", "native", "new",
- "null", "package", "private", "protected", "public", "return", "short",
- "static", "strictfp", "super", "switch", "synchronized", "this",
- "throw", "throws", "transient", "true", "try", "void", "volatile",
- "while" };
+ private static final String invalidIdentifiers[] = { "abstract", "assert", "boolean", "break", "byte", "case",
+ "catch", "char", "class", "const", "continue", "default", "do", "double", "else", "enum", "extends",
+ "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int",
+ "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return",
+ "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient",
+ "true", "try", "void", "volatile", "while" };
- private static final boolean SKIP_IDENTIFIER_CHECK = Boolean.getBoolean("org.apache.el.parser.SKIP_IDENTIFIER_CHECK");
+ private static final boolean SKIP_IDENTIFIER_CHECK =
+ Boolean.getBoolean("org.apache.el.parser.SKIP_IDENTIFIER_CHECK");
private Validation() {
@@ -37,14 +35,12 @@ public class Validation {
}
/**
- * Test whether a string is a Java identifier. Note that the behaviour of
- * this method depend on the system property
+ * Test whether a string is a Java identifier. Note that the behaviour of this method depend on the system property
* {@code org.apache.el.parser.SKIP_IDENTIFIER_CHECK}
*
* @param key The string to test
*
- * @return {@code true} if the provided String should be treated as a Java
- * identifier, otherwise false
+ * @return {@code true} if the provided String should be treated as a Java identifier, otherwise false
*/
public static boolean isIdentifier(String key) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org