You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2025/03/24 13:23:46 UTC
(tomcat) branch main updated: jakarta.el cleanup
This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 20921725f2 jakarta.el cleanup
20921725f2 is described below
commit 20921725f201bc2749235ad8f9caf0ca86f0bf8b
Author: remm <re...@apache.org>
AuthorDate: Mon Mar 24 14:23:36 2025 +0100
jakarta.el cleanup
---
java/jakarta/el/BeanELResolver.java | 6 +-
java/jakarta/el/BeanNameELResolver.java | 26 +++-----
java/jakarta/el/BeanSupportFull.java | 18 +++---
java/jakarta/el/BeanSupportStandalone.java | 22 +++----
java/jakarta/el/ELContext.java | 12 +---
java/jakarta/el/ELContextEvent.java | 2 +
java/jakarta/el/ELException.java | 3 +
java/jakarta/el/ELProcessor.java | 78 +++++++++--------------
java/jakarta/el/ELResolver.java | 4 +-
java/jakarta/el/Expression.java | 2 +
java/jakarta/el/ExpressionFactory.java | 13 ++--
java/jakarta/el/ImportHandler.java | 25 +++-----
java/jakarta/el/ListELResolver.java | 9 +--
java/jakarta/el/MapELResolver.java | 3 +-
java/jakarta/el/MethodExpression.java | 3 +
java/jakarta/el/MethodInfo.java | 9 +--
java/jakarta/el/MethodNotFoundException.java | 3 +
java/jakarta/el/MethodReference.java | 9 +--
java/jakarta/el/OptionalELResolver.java | 6 +-
java/jakarta/el/PropertyNotFoundException.java | 3 +
java/jakarta/el/PropertyNotWritableException.java | 3 +
java/jakarta/el/RecordELResolver.java | 2 +-
java/jakarta/el/StaticFieldELResolver.java | 17 ++---
java/jakarta/el/Util.java | 36 +++--------
java/jakarta/el/ValueExpression.java | 3 +
java/jakarta/el/ValueReference.java | 2 +
26 files changed, 132 insertions(+), 187 deletions(-)
diff --git a/java/jakarta/el/BeanELResolver.java b/java/jakarta/el/BeanELResolver.java
index 7577163539..4d1b0ea210 100644
--- a/java/jakarta/el/BeanELResolver.java
+++ b/java/jakarta/el/BeanELResolver.java
@@ -138,7 +138,7 @@ public class BeanELResolver extends ELResolver {
Object[] parameters =
Util.buildParameters(context, matchingMethod.getParameterTypes(), matchingMethod.isVarArgs(), params);
- Object result = null;
+ Object result;
try {
result = matchingMethod.invoke(base, parameters);
} catch (IllegalArgumentException | IllegalAccessException e) {
@@ -222,7 +222,7 @@ public class BeanELResolver extends ELResolver {
this.write = Util.getMethod(this.owner, base, getWriteMethod());
if (this.write == null) {
throw new PropertyNotWritableException(
- Util.message(ctx, "propertyNotWritable", new Object[] { owner.getName(), getName() }));
+ Util.message(ctx, "propertyNotWritable", owner.getName(), getName()));
}
}
return this.write;
@@ -233,7 +233,7 @@ public class BeanELResolver extends ELResolver {
this.read = Util.getMethod(this.owner, base, getReadMethod());
if (this.read == null) {
throw new PropertyNotFoundException(
- Util.message(ctx, "propertyNotReadable", new Object[] { owner.getName(), getName() }));
+ Util.message(ctx, "propertyNotReadable", owner.getName(), getName()));
}
}
return this.read;
diff --git a/java/jakarta/el/BeanNameELResolver.java b/java/jakarta/el/BeanNameELResolver.java
index 9ef745150a..8331e310f4 100644
--- a/java/jakarta/el/BeanNameELResolver.java
+++ b/java/jakarta/el/BeanNameELResolver.java
@@ -32,16 +32,14 @@ public class BeanNameELResolver extends ELResolver {
@Override
public Object getValue(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
- if (base != null || !(property instanceof String)) {
+ if (base != null || !(property instanceof String beanName)) {
return null;
}
- String beanName = (String) property;
-
if (beanNameResolver.isNameResolved(beanName)) {
try {
Object result = beanNameResolver.getBean(beanName);
- context.setPropertyResolved(base, property);
+ context.setPropertyResolved(null, property);
return result;
} catch (Throwable t) {
Util.handleThrowable(t);
@@ -55,17 +53,15 @@ public class BeanNameELResolver extends ELResolver {
@Override
public void setValue(ELContext context, Object base, Object property, Object value) {
Objects.requireNonNull(context);
- if (base != null || !(property instanceof String)) {
+ if (base != null || !(property instanceof String beanName)) {
return;
}
- String beanName = (String) property;
-
boolean isResolved = context.isPropertyResolved();
boolean isReadOnly;
try {
- isReadOnly = isReadOnly(context, base, property);
+ isReadOnly = isReadOnly(context, null, property);
} catch (Throwable t) {
Util.handleThrowable(t);
throw new ELException(t);
@@ -80,7 +76,7 @@ public class BeanNameELResolver extends ELResolver {
if (beanNameResolver.isNameResolved(beanName) || beanNameResolver.canCreateBean(beanName)) {
try {
beanNameResolver.setBeanValue(beanName, value);
- context.setPropertyResolved(base, property);
+ context.setPropertyResolved(null, property);
} catch (Throwable t) {
Util.handleThrowable(t);
throw new ELException(t);
@@ -91,16 +87,14 @@ public class BeanNameELResolver extends ELResolver {
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
- if (base != null || !(property instanceof String)) {
+ if (base != null || !(property instanceof String beanName)) {
return null;
}
- String beanName = (String) property;
-
try {
if (beanNameResolver.isNameResolved(beanName)) {
Class<?> result = beanNameResolver.getBean(beanName).getClass();
- context.setPropertyResolved(base, property);
+ context.setPropertyResolved(null, property);
/*
* No resolver level isReadOnly property for this resolver
@@ -122,13 +116,11 @@ public class BeanNameELResolver extends ELResolver {
@Override
public boolean isReadOnly(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
- if (base != null || !(property instanceof String)) {
+ if (base != null || !(property instanceof String beanName)) {
// Return value undefined
return false;
}
- String beanName = (String) property;
-
if (beanNameResolver.isNameResolved(beanName)) {
boolean result;
try {
@@ -137,7 +129,7 @@ public class BeanNameELResolver extends ELResolver {
Util.handleThrowable(t);
throw new ELException(t);
}
- context.setPropertyResolved(base, property);
+ context.setPropertyResolved(null, property);
return result;
}
diff --git a/java/jakarta/el/BeanSupportFull.java b/java/jakarta/el/BeanSupportFull.java
index eea3e189e9..ac35a3b1ff 100644
--- a/java/jakarta/el/BeanSupportFull.java
+++ b/java/jakarta/el/BeanSupportFull.java
@@ -55,18 +55,16 @@ class BeanSupportFull extends BeanSupport {
}
private void populateFromInterfaces(Class<?> aClass) throws IntrospectionException {
- Class<?> interfaces[] = aClass.getInterfaces();
- if (interfaces.length > 0) {
- for (Class<?> ifs : interfaces) {
- BeanInfo info = Introspector.getBeanInfo(ifs);
- PropertyDescriptor[] pds = info.getPropertyDescriptors();
- for (PropertyDescriptor pd : pds) {
- if (!this.properties.containsKey(pd.getName())) {
- this.properties.put(pd.getName(), new BeanPropertyFull(this.type, pd));
- }
+ Class<?>[] interfaces = aClass.getInterfaces();
+ for (Class<?> ifs : interfaces) {
+ BeanInfo info = Introspector.getBeanInfo(ifs);
+ PropertyDescriptor[] pds = info.getPropertyDescriptors();
+ for (PropertyDescriptor pd : pds) {
+ if (!this.properties.containsKey(pd.getName())) {
+ this.properties.put(pd.getName(), new BeanPropertyFull(this.type, pd));
}
- populateFromInterfaces(ifs);
}
+ populateFromInterfaces(ifs);
}
Class<?> superclass = aClass.getSuperclass();
if (superclass != null) {
diff --git a/java/jakarta/el/BeanSupportStandalone.java b/java/jakarta/el/BeanSupportStandalone.java
index e4db4b5589..c32c89e2b8 100644
--- a/java/jakarta/el/BeanSupportStandalone.java
+++ b/java/jakarta/el/BeanSupportStandalone.java
@@ -84,7 +84,7 @@ class BeanSupportStandalone extends BeanSupport {
private static String getPropertyName(String input) {
- if (input.length() == 0) {
+ if (input.isEmpty()) {
return null;
}
if (!Character.isUpperCase(input.charAt(0))) {
@@ -104,7 +104,7 @@ class BeanSupportStandalone extends BeanSupport {
private boolean usesIs;
private Method readMethod;
private Method writeMethod;
- private List<Method> writeMethods = new ArrayList<>();
+ private final List<Method> writeMethods = new ArrayList<>();
String getName() {
return name;
@@ -146,7 +146,7 @@ class BeanSupportStandalone extends BeanSupport {
if (writeMethods.size() > 1) {
writeMethods.sort(WRITE_METHOD_COMPARATOR);
}
- type = writeMethods.get(0).getParameterTypes()[0];
+ type = writeMethods.getFirst().getParameterTypes()[0];
}
for (Method candidate : writeMethods) {
if (type.isAssignableFrom(candidate.getParameterTypes()[0])) {
@@ -179,17 +179,15 @@ class BeanSupportStandalone extends BeanSupport {
}
private void populateFromInterfaces(Class<?> aClass) {
- Class<?> interfaces[] = aClass.getInterfaces();
- if (interfaces.length > 0) {
- for (Class<?> ifs : interfaces) {
- PropertyDescriptor[] pds = getPropertyDescriptors(type);
- for (PropertyDescriptor pd : pds) {
- if (!this.properties.containsKey(pd.getName())) {
- this.properties.put(pd.getName(), new BeanPropertyStandalone(this.type, pd));
- }
+ Class<?>[] interfaces = aClass.getInterfaces();
+ for (Class<?> ifs : interfaces) {
+ PropertyDescriptor[] pds = getPropertyDescriptors(type);
+ for (PropertyDescriptor pd : pds) {
+ if (!this.properties.containsKey(pd.getName())) {
+ this.properties.put(pd.getName(), new BeanPropertyStandalone(this.type, pd));
}
- populateFromInterfaces(ifs);
}
+ populateFromInterfaces(ifs);
}
Class<?> superclass = aClass.getSuperclass();
if (superclass != null) {
diff --git a/java/jakarta/el/ELContext.java b/java/jakarta/el/ELContext.java
index 98f0856796..f99f82c0f7 100644
--- a/java/jakarta/el/ELContext.java
+++ b/java/jakarta/el/ELContext.java
@@ -365,22 +365,16 @@ public abstract class ELContext {
if ("equals".equals(method.getName())) {
if (method.getReturnType().equals(boolean.class)) {
if (method.getParameterCount() == 1) {
- if (method.getParameterTypes()[0].equals(Object.class)) {
- return true;
- }
+ return method.getParameterTypes()[0].equals(Object.class);
}
}
} else if ("hashCode".equals(method.getName())) {
if (method.getReturnType().equals(int.class)) {
- if (method.getParameterCount() == 0) {
- return true;
- }
+ return method.getParameterCount() == 0;
}
} else if ("toString".equals(method.getName())) {
if (method.getReturnType().equals(String.class)) {
- if (method.getParameterCount() == 0) {
- return true;
- }
+ return method.getParameterCount() == 0;
}
}
diff --git a/java/jakarta/el/ELContextEvent.java b/java/jakarta/el/ELContextEvent.java
index 651eeeab0a..b5bfda0e68 100644
--- a/java/jakarta/el/ELContextEvent.java
+++ b/java/jakarta/el/ELContextEvent.java
@@ -16,10 +16,12 @@
*/
package jakarta.el;
+import java.io.Serial;
import java.util.EventObject;
public class ELContextEvent extends EventObject {
+ @Serial
private static final long serialVersionUID = 1255131906285426769L;
/**
diff --git a/java/jakarta/el/ELException.java b/java/jakarta/el/ELException.java
index ab18aeeef6..315fd21abb 100644
--- a/java/jakarta/el/ELException.java
+++ b/java/jakarta/el/ELException.java
@@ -16,6 +16,8 @@
*/
package jakarta.el;
+import java.io.Serial;
+
/**
* Represents any of the exception conditions that can arise during expression evaluation.
*
@@ -23,6 +25,7 @@ package jakarta.el;
*/
public class ELException extends RuntimeException {
+ @Serial
private static final long serialVersionUID = -6228042809457459161L;
/**
diff --git a/java/jakarta/el/ELProcessor.java b/java/jakarta/el/ELProcessor.java
index 1e91022dc2..d3f10f17b9 100644
--- a/java/jakarta/el/ELProcessor.java
+++ b/java/jakarta/el/ELProcessor.java
@@ -100,12 +100,12 @@ public class ELProcessor {
MethodSignature sig = new MethodSignature(context, methodName, className);
- if (function.length() == 0) {
+ if (function.isEmpty()) {
function = sig.getName();
}
// Only returns public methods. Module access is checked below.
- Method methods[] = clazz.getMethods();
+ Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (!Modifier.isStatic(method.getModifiers())) {
@@ -130,28 +130,26 @@ public class ELProcessor {
} else {
Class<?>[] types = method.getParameterTypes();
String[] typeNames = sig.getParamTypeNames();
- if (types.length == typeNames.length) {
- boolean match = true;
- for (int i = 0; i < types.length; i++) {
- if (i == types.length - 1 && method.isVarArgs()) {
- String typeName = typeNames[i];
- if (typeName.endsWith("...")) {
- typeName = typeName.substring(0, typeName.length() - 3);
- if (!typeName.equals(types[i].getName())) {
- match = false;
- }
- } else {
+ boolean match = true;
+ for (int i = 0; i < types.length; i++) {
+ if (i == types.length - 1 && method.isVarArgs()) {
+ String typeName = typeNames[i];
+ if (typeName.endsWith("...")) {
+ typeName = typeName.substring(0, typeName.length() - 3);
+ if (!typeName.equals(types[i].getName())) {
match = false;
}
- } else if (!types[i].getName().equals(typeNames[i])) {
+ } else {
match = false;
- break;
}
+ } else if (!types[i].getName().equals(typeNames[i])) {
+ match = false;
+ break;
}
- if (match) {
- manager.mapFunction(prefix, function, method);
- return;
- }
+ }
+ if (match) {
+ manager.mapFunction(prefix, function, method);
+ return;
}
}
}
@@ -236,7 +234,7 @@ public class ELProcessor {
}
// Trim '(' and ')'
paramString = paramString.substring(1, paramString.length() - 1).trim();
- if (paramString.length() == 0) {
+ if (paramString.isEmpty()) {
parameterTypeNames = EMPTY_STRING_ARRAY;
} else {
parameterTypeNames = paramString.split(",");
@@ -263,33 +261,17 @@ public class ELProcessor {
if (isPrimitive && dimension > 0) {
// When in an array, class name changes for primitive
switch (parameterTypeName) {
- case "boolean":
- parameterTypeName = "Z";
- break;
- case "byte":
- parameterTypeName = "B";
- break;
- case "char":
- parameterTypeName = "C";
- break;
- case "double":
- parameterTypeName = "D";
- break;
- case "float":
- parameterTypeName = "F";
- break;
- case "int":
- parameterTypeName = "I";
- break;
- case "long":
- parameterTypeName = "J";
- break;
- case "short":
- parameterTypeName = "S";
- break;
- default:
+ case "boolean" -> parameterTypeName = "Z";
+ case "byte" -> parameterTypeName = "B";
+ case "char" -> parameterTypeName = "C";
+ case "double" -> parameterTypeName = "D";
+ case "float" -> parameterTypeName = "F";
+ case "int" -> parameterTypeName = "I";
+ case "long" -> parameterTypeName = "J";
+ case "short" -> parameterTypeName = "S";
+ default -> {
// Should never happen
- break;
+ }
}
} else if (!isPrimitive && !parameterTypeName.contains(".")) {
Class<?> clazz = importHandler.resolveClass(parameterTypeName);
@@ -303,9 +285,7 @@ public class ELProcessor {
if (dimension > 0) {
// Convert to array form of class name
StringBuilder sb = new StringBuilder();
- for (int j = 0; j < dimension; j++) {
- sb.append('[');
- }
+ sb.append("[".repeat(dimension));
if (!isPrimitive) {
sb.append('L');
}
diff --git a/java/jakarta/el/ELResolver.java b/java/jakarta/el/ELResolver.java
index 2bd3dd9280..0b9be0327a 100644
--- a/java/jakarta/el/ELResolver.java
+++ b/java/jakarta/el/ELResolver.java
@@ -39,7 +39,7 @@ public abstract class ELResolver {
public abstract Object getValue(ELContext context, Object base, Object property);
/**
- * Invokes a method on the the given object.
+ * Invokes a method on the given object.
*
* @param context The EL context for this evaluation
* @param base The base object on which the method is to be found
@@ -113,7 +113,7 @@ public abstract class ELResolver {
* @param context The context in which the examination takes place
* @param base The object to examine
*
- * @return {code null} if the most common type cannot be determine, otherwise the most common type
+ * @return {code null} if the most common type cannot be determined, otherwise the most common type
*/
public abstract Class<?> getCommonPropertyType(ELContext context, Object base);
diff --git a/java/jakarta/el/Expression.java b/java/jakarta/el/Expression.java
index bc8950a5d7..9c833768d4 100644
--- a/java/jakarta/el/Expression.java
+++ b/java/jakarta/el/Expression.java
@@ -16,6 +16,7 @@
*/
package jakarta.el;
+import java.io.Serial;
import java.io.Serializable;
/**
@@ -23,6 +24,7 @@ import java.io.Serializable;
*/
public abstract class Expression implements Serializable {
+ @Serial
private static final long serialVersionUID = -6663767980471823812L;
public abstract String getExpressionString();
diff --git a/java/jakarta/el/ExpressionFactory.java b/java/jakarta/el/ExpressionFactory.java
index b05488ea6c..bd48c822da 100644
--- a/java/jakarta/el/ExpressionFactory.java
+++ b/java/jakarta/el/ExpressionFactory.java
@@ -66,12 +66,11 @@ public abstract class ExpressionFactory {
* Create a new {@link ExpressionFactory} passing in the provided {@link Properties}. Search order is the same as
* {@link #newInstance()}.
*
- * @param properties the properties to be passed to the new instance (may be null)
+ * @param properties the properties to be passed to the new instance (might be null)
*
* @return the new ExpressionFactory
*/
public static ExpressionFactory newInstance(Properties properties) {
- ExpressionFactory result = null;
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
@@ -125,6 +124,8 @@ public abstract class ExpressionFactory {
}
}
+ ExpressionFactory result;
+
try {
Constructor<?> constructor = null;
// Do we need to look for a constructor that will take properties?
@@ -289,10 +290,8 @@ public abstract class ExpressionFactory {
* @return Class name. There is default, so it is never {@code null}.
*/
private static String discoverClassName(ClassLoader tccl) {
- String className = null;
-
// First services API
- className = getClassNameServices(tccl);
+ String className = getClassNameServices(tccl);
if (className == null) {
// Second el.properties file
className = getClassNameJreDir();
@@ -332,7 +331,7 @@ public abstract class ExpressionFactory {
Properties props = new Properties();
props.load(is);
String value = props.getProperty(PROPERTY_NAME);
- if (value != null && value.trim().length() > 0) {
+ if (value != null && !value.trim().isEmpty()) {
return value.trim();
}
} catch (FileNotFoundException e) {
@@ -346,7 +345,7 @@ public abstract class ExpressionFactory {
private static String getClassNameSysProp() {
String value = System.getProperty(PROPERTY_NAME);
- if (value != null && value.trim().length() > 0) {
+ if (value != null && !value.trim().isEmpty()) {
return value.trim();
}
return null;
diff --git a/java/jakarta/el/ImportHandler.java b/java/jakarta/el/ImportHandler.java
index 54b72f839b..ac2e9e492a 100644
--- a/java/jakarta/el/ImportHandler.java
+++ b/java/jakarta/el/ImportHandler.java
@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -279,10 +280,10 @@ public class ImportHandler {
}
- private Map<String,Set<String>> packageNames = new ConcurrentHashMap<>();
- private Map<String,String> classNames = new ConcurrentHashMap<>();
- private Map<String,Class<?>> clazzes = new ConcurrentHashMap<>();
- private Map<String,Class<?>> statics = new ConcurrentHashMap<>();
+ private final Map<String,Set<String>> packageNames = new ConcurrentHashMap<>();
+ private final Map<String,String> classNames = new ConcurrentHashMap<>();
+ private final Map<String,Class<?>> clazzes = new ConcurrentHashMap<>();
+ private final Map<String,Class<?>> statics = new ConcurrentHashMap<>();
public ImportHandler() {
@@ -369,11 +370,7 @@ public class ImportHandler {
// b) java.lang.Package.getPackage(name) is not reliable (BZ 57574),
// c) such check is not required by specification.
Set<String> preloaded = standardPackages.get(name);
- if (preloaded == null) {
- packageNames.put(name, Collections.emptySet());
- } else {
- packageNames.put(name, preloaded);
- }
+ packageNames.put(name, Objects.requireNonNullElse(preloaded, Collections.emptySet()));
}
@@ -425,13 +422,9 @@ public class ImportHandler {
result = clazz;
}
}
- if (result == null) {
- // Cache NotFound results to save repeated calls to findClass()
- // which is relatively slow
- clazzes.put(name, NotFound.class);
- } else {
- clazzes.put(name, result);
- }
+ // Cache NotFound results to save repeated calls to findClass()
+ // which is relatively slow
+ clazzes.put(name, Objects.requireNonNullElse(result, NotFound.class));
return result;
}
diff --git a/java/jakarta/el/ListELResolver.java b/java/jakarta/el/ListELResolver.java
index 6cbcab7b85..13c73e16f6 100644
--- a/java/jakarta/el/ListELResolver.java
+++ b/java/jakarta/el/ListELResolver.java
@@ -41,9 +41,8 @@ public class ListELResolver extends ELResolver {
public Class<?> getType(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
- if (base instanceof List<?>) {
+ if (base instanceof List<?> list) {
context.setPropertyResolved(base, property);
- List<?> list = (List<?>) base;
int idx = coerce(property);
if (idx < 0 || idx >= list.size()) {
throw new PropertyNotFoundException(new ArrayIndexOutOfBoundsException(idx).getMessage());
@@ -66,9 +65,8 @@ public class ListELResolver extends ELResolver {
public Object getValue(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
- if (base instanceof List<?>) {
+ if (base instanceof List<?> list) {
context.setPropertyResolved(base, property);
- List<?> list = (List<?>) base;
int idx = coerce(property);
if (idx < 0 || idx >= list.size()) {
return null;
@@ -108,9 +106,8 @@ public class ListELResolver extends ELResolver {
public boolean isReadOnly(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
- if (base instanceof List<?>) {
+ if (base instanceof List<?> list) {
context.setPropertyResolved(base, property);
- List<?> list = (List<?>) base;
try {
int idx = coerce(property);
if (idx < 0 || idx >= list.size()) {
diff --git a/java/jakarta/el/MapELResolver.java b/java/jakarta/el/MapELResolver.java
index 8b4dfa5cad..3609f16566 100644
--- a/java/jakarta/el/MapELResolver.java
+++ b/java/jakarta/el/MapELResolver.java
@@ -39,10 +39,9 @@ public class MapELResolver extends ELResolver {
public Class<?> getType(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
- if (base instanceof Map<?,?>) {
+ if (base instanceof Map<?, ?> map) {
context.setPropertyResolved(base, property);
- Map<?,?> map = (Map<?,?>) base;
if (readOnly || map.getClass() == UNMODIFIABLE) {
return null;
}
diff --git a/java/jakarta/el/MethodExpression.java b/java/jakarta/el/MethodExpression.java
index e8a91c4fb8..715cf43bb9 100644
--- a/java/jakarta/el/MethodExpression.java
+++ b/java/jakarta/el/MethodExpression.java
@@ -16,8 +16,11 @@
*/
package jakarta.el;
+import java.io.Serial;
+
public abstract class MethodExpression extends Expression {
+ @Serial
private static final long serialVersionUID = 8163925562047324656L;
/**
diff --git a/java/jakarta/el/MethodInfo.java b/java/jakarta/el/MethodInfo.java
index 8b977a6a9b..3dbcfe75a1 100644
--- a/java/jakarta/el/MethodInfo.java
+++ b/java/jakarta/el/MethodInfo.java
@@ -77,12 +77,9 @@ public class MethodInfo {
return false;
}
if (returnType == null) {
- if (other.returnType != null) {
- return false;
- }
- } else if (!returnType.equals(other.returnType)) {
- return false;
+ return other.returnType == null;
+ } else {
+ return returnType.equals(other.returnType);
}
- return true;
}
}
diff --git a/java/jakarta/el/MethodNotFoundException.java b/java/jakarta/el/MethodNotFoundException.java
index 74446f8346..8a92baf0f3 100644
--- a/java/jakarta/el/MethodNotFoundException.java
+++ b/java/jakarta/el/MethodNotFoundException.java
@@ -16,8 +16,11 @@
*/
package jakarta.el;
+import java.io.Serial;
+
public class MethodNotFoundException extends ELException {
+ @Serial
private static final long serialVersionUID = -3631968116081480328L;
public MethodNotFoundException() {
diff --git a/java/jakarta/el/MethodReference.java b/java/jakarta/el/MethodReference.java
index 30065c5768..6f86ffcbea 100644
--- a/java/jakarta/el/MethodReference.java
+++ b/java/jakarta/el/MethodReference.java
@@ -122,12 +122,9 @@ public class MethodReference {
return false;
}
if (methodInfo == null) {
- if (other.methodInfo != null) {
- return false;
- }
- } else if (!methodInfo.equals(other.methodInfo)) {
- return false;
+ return other.methodInfo == null;
+ } else {
+ return methodInfo.equals(other.methodInfo);
}
- return true;
}
}
diff --git a/java/jakarta/el/OptionalELResolver.java b/java/jakarta/el/OptionalELResolver.java
index 0d82293039..9600e1abca 100644
--- a/java/jakarta/el/OptionalELResolver.java
+++ b/java/jakarta/el/OptionalELResolver.java
@@ -175,11 +175,9 @@ public class OptionalELResolver extends ELResolver {
}
try {
- Object convertedValue = context.convertToType(value, type);
+ T convertedValue = context.convertToType(value, type);
context.setPropertyResolved(true);
- @SuppressWarnings("unchecked")
- T result = (T) convertedValue;
- return result;
+ return convertedValue;
} catch (ELException e) {
/*
* TODO: This isn't pretty but it works. Significant refactoring would be required to avoid the
diff --git a/java/jakarta/el/PropertyNotFoundException.java b/java/jakarta/el/PropertyNotFoundException.java
index 5c4b484c23..45aff2e48b 100644
--- a/java/jakarta/el/PropertyNotFoundException.java
+++ b/java/jakarta/el/PropertyNotFoundException.java
@@ -16,8 +16,11 @@
*/
package jakarta.el;
+import java.io.Serial;
+
public class PropertyNotFoundException extends ELException {
+ @Serial
private static final long serialVersionUID = -3799200961303506745L;
public PropertyNotFoundException() {
diff --git a/java/jakarta/el/PropertyNotWritableException.java b/java/jakarta/el/PropertyNotWritableException.java
index 63399845e2..58f28e9c34 100644
--- a/java/jakarta/el/PropertyNotWritableException.java
+++ b/java/jakarta/el/PropertyNotWritableException.java
@@ -16,8 +16,11 @@
*/
package jakarta.el;
+import java.io.Serial;
+
public class PropertyNotWritableException extends ELException {
+ @Serial
private static final long serialVersionUID = 827987155471214717L;
public PropertyNotWritableException() {
diff --git a/java/jakarta/el/RecordELResolver.java b/java/jakarta/el/RecordELResolver.java
index e9cbae380f..a09b22a293 100644
--- a/java/jakarta/el/RecordELResolver.java
+++ b/java/jakarta/el/RecordELResolver.java
@@ -28,7 +28,7 @@ import java.util.Objects;
* <p>
* This resolver is always read-only since {@link Record}s are always read-only.
* <p>
- * {@code ELResolver}s are combined together using {@link CompositeELResolver}s to define rich semantics for evaluating
+ * {@code ELResolver}s are combined using {@link CompositeELResolver}s to define rich semantics for evaluating
* an expression. See the javadocs for {@link ELResolver} for details.
*
* @since EL 6.0
diff --git a/java/jakarta/el/StaticFieldELResolver.java b/java/jakarta/el/StaticFieldELResolver.java
index 5b5c908392..c69e306005 100644
--- a/java/jakarta/el/StaticFieldELResolver.java
+++ b/java/jakarta/el/StaticFieldELResolver.java
@@ -32,11 +32,10 @@ public class StaticFieldELResolver extends ELResolver {
public Object getValue(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
- if (base instanceof ELClass && property instanceof String) {
+ if (base instanceof ELClass && property instanceof String name) {
context.setPropertyResolved(base, property);
Class<?> clazz = ((ELClass) base).getKlass();
- String name = (String) property;
Exception exception = null;
try {
Field field = clazz.getField(name);
@@ -62,9 +61,8 @@ public class StaticFieldELResolver extends ELResolver {
public void setValue(ELContext context, Object base, Object property, Object value) {
Objects.requireNonNull(context);
- if (base instanceof ELClass && property instanceof String) {
+ if (base instanceof ELClass && property instanceof String name) {
Class<?> clazz = ((ELClass) base).getKlass();
- String name = (String) property;
throw new PropertyNotWritableException(
Util.message(context, "staticFieldELResolver.notWritable", name, clazz.getName()));
@@ -76,11 +74,10 @@ public class StaticFieldELResolver extends ELResolver {
public Object invoke(ELContext context, Object base, Object method, Class<?>[] paramTypes, Object[] params) {
Objects.requireNonNull(context);
- if (base instanceof ELClass && method instanceof String) {
+ if (base instanceof ELClass && method instanceof String methodName) {
context.setPropertyResolved(base, method);
Class<?> clazz = ((ELClass) base).getKlass();
- String methodName = (String) method;
if ("<init>".equals(methodName)) {
Constructor<?> match = Util.findConstructor(context, clazz, paramTypes, params);
@@ -88,8 +85,7 @@ public class StaticFieldELResolver extends ELResolver {
Object[] parameters =
Util.buildParameters(context, match.getParameterTypes(), match.isVarArgs(), params);
- Object result = null;
-
+ Object result;
try {
result = match.newInstance(parameters);
} catch (InvocationTargetException e) {
@@ -113,7 +109,7 @@ public class StaticFieldELResolver extends ELResolver {
Object[] parameters =
Util.buildParameters(context, match.getParameterTypes(), match.isVarArgs(), params);
- Object result = null;
+ Object result;
try {
result = match.invoke(null, parameters);
} catch (IllegalArgumentException | IllegalAccessException e) {
@@ -133,11 +129,10 @@ public class StaticFieldELResolver extends ELResolver {
public Class<?> getType(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
- if (base instanceof ELClass && property instanceof String) {
+ if (base instanceof ELClass && property instanceof String name) {
context.setPropertyResolved(base, property);
Class<?> clazz = ((ELClass) base).getKlass();
- String name = (String) property;
Exception exception = null;
try {
Field field = clazz.getField(name);
diff --git a/java/jakarta/el/Util.java b/java/jakarta/el/Util.java
index 63f6f3fba3..2935bc88b2 100644
--- a/java/jakarta/el/Util.java
+++ b/java/jakarta/el/Util.java
@@ -420,7 +420,7 @@ class Util {
return EMPTY_CLASS_ARRAY;
}
- Class<?> result[] = new Class<?>[values.length];
+ Class<?>[] result = new Class<?>[values.length];
for (int i = 0; i < values.length; i++) {
if (values[i] == null) {
result[i] = null;
@@ -441,7 +441,7 @@ class Util {
return m;
}
Class<?>[] interfaces = type.getInterfaces();
- Method mp = null;
+ Method mp;
for (Class<?> iface : interfaces) {
try {
mp = iface.getMethod(m.getName(), m.getParameterTypes());
@@ -631,24 +631,8 @@ class Util {
/*
* This class duplicates code in org.apache.el.util.ReflectionUtil. When making changes keep the code in sync.
*/
- private static class MatchResult implements Comparable<MatchResult> {
-
- private final boolean varArgs;
- private final int exactCount;
- private final int assignableCount;
- private final int coercibleCount;
- private final int varArgsCount;
- private final boolean bridge;
-
- MatchResult(boolean varArgs, int exactCount, int assignableCount, int coercibleCount, int varArgsCount,
- boolean bridge) {
- this.varArgs = varArgs;
- this.exactCount = exactCount;
- this.assignableCount = assignableCount;
- this.coercibleCount = coercibleCount;
- this.varArgsCount = varArgsCount;
- this.bridge = bridge;
- }
+ private record MatchResult(boolean varArgs, int exactCount, int assignableCount, int coercibleCount, int varArgsCount,
+ boolean bridge) implements Comparable<MatchResult> {
public boolean isVarArgs() {
return varArgs;
@@ -716,12 +700,12 @@ class Util {
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + assignableCount;
- result = prime * result + (bridge ? 1231 : 1237);
- result = prime * result + coercibleCount;
- result = prime * result + exactCount;
- result = prime * result + (varArgs ? 1231 : 1237);
- result = prime * result + varArgsCount;
+ result = prime * result + getAssignableCount();
+ result = prime * result + (isBridge() ? 1231 : 1237);
+ result = prime * result + getCoercibleCount();
+ result = prime * result + getExactCount();
+ result = prime * result + (isVarArgs() ? 1231 : 1237);
+ result = prime * result + getVarArgsCount();
return result;
}
}
diff --git a/java/jakarta/el/ValueExpression.java b/java/jakarta/el/ValueExpression.java
index 33b04eb906..892c96128c 100644
--- a/java/jakarta/el/ValueExpression.java
+++ b/java/jakarta/el/ValueExpression.java
@@ -16,8 +16,11 @@
*/
package jakarta.el;
+import java.io.Serial;
+
public abstract class ValueExpression extends Expression {
+ @Serial
private static final long serialVersionUID = 8577809572381654673L;
/**
diff --git a/java/jakarta/el/ValueReference.java b/java/jakarta/el/ValueReference.java
index 9148f26443..b7b2cee9ed 100644
--- a/java/jakarta/el/ValueReference.java
+++ b/java/jakarta/el/ValueReference.java
@@ -16,6 +16,7 @@
*/
package jakarta.el;
+import java.io.Serial;
import java.io.Serializable;
/**
@@ -23,6 +24,7 @@ import java.io.Serializable;
*/
public class ValueReference implements Serializable {
+ @Serial
private static final long serialVersionUID = 1L;
private final Object base;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org