internalFac
public T create(InternalContext context) {
T instance = internalFactory.create(context);
if (Initializable.class.isAssignableFrom(instance.getClass())) {
- Initializable.class.cast(instance).init();
+ ((Initializable) instance).init();
} else {
LOG.error("Class {} is not marked as {}!", internalFactory.getClass().getName(), Initializable.class.getName());
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/inject/Inject.java b/core/src/main/java/com/opensymphony/xwork2/inject/Inject.java
index e97cb48def..c661882c70 100644
--- a/core/src/main/java/com/opensymphony/xwork2/inject/Inject.java
+++ b/core/src/main/java/com/opensymphony/xwork2/inject/Inject.java
@@ -1,12 +1,12 @@
/**
* Copyright (C) 2006 Google Inc.
- *
+ *
* Licensed 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
- *
+ *
+ * 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.
@@ -16,13 +16,16 @@
package com.opensymphony.xwork2.inject;
-import static com.opensymphony.xwork2.inject.Container.DEFAULT_NAME;
-
-import static java.lang.annotation.ElementType.*;
import java.lang.annotation.Retention;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import static com.opensymphony.xwork2.inject.Container.DEFAULT_NAME;
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
/**
*
Annotates members and parameters which should have their value[s]
* injected.
@@ -34,14 +37,14 @@
@Retention(RUNTIME)
public @interface Inject {
- /**
- * @return Dependency name. Defaults to {@link Container#DEFAULT_NAME}.
- */
- String value() default DEFAULT_NAME;
+ /**
+ * @return Dependency name. Defaults to {@link Container#DEFAULT_NAME}.
+ */
+ String value() default DEFAULT_NAME;
- /**
- * @return Whether or not injection is required. Applicable only to methods and
- * fields (not constructors or parameters).
- */
- boolean required() default true;
+ /**
+ * @return Whether or not injection is required. Applicable only to methods and
+ * fields (not constructors or parameters).
+ */
+ boolean required() default true;
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/inject/InternalContext.java b/core/src/main/java/com/opensymphony/xwork2/inject/InternalContext.java
index a383721364..8a85f5705e 100644
--- a/core/src/main/java/com/opensymphony/xwork2/inject/InternalContext.java
+++ b/core/src/main/java/com/opensymphony/xwork2/inject/InternalContext.java
@@ -1,12 +1,12 @@
/**
* Copyright (C) 2006 Google Inc.
- *
+ *
* Licensed 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
- *
+ *
+ * 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.
@@ -27,51 +27,51 @@
*/
class InternalContext {
- final ContainerImpl container;
- final Map> constructionContexts = new HashMap>();
- Scope.Strategy scopeStrategy;
- ExternalContext> externalContext;
+ final ContainerImpl container;
+ final Map> constructionContexts = new HashMap<>();
+ Scope.Strategy scopeStrategy;
+ ExternalContext> externalContext;
+
+ InternalContext(ContainerImpl container) {
+ this.container = container;
+ }
- InternalContext(ContainerImpl container) {
- this.container = container;
- }
+ public Container getContainer() {
+ return container;
+ }
- public Container getContainer() {
- return container;
- }
+ ContainerImpl getContainerImpl() {
+ return container;
+ }
- ContainerImpl getContainerImpl() {
- return container;
- }
+ Scope.Strategy getScopeStrategy() {
+ if (scopeStrategy == null) {
+ scopeStrategy = (Scope.Strategy) container.localScopeStrategy.get();
- Scope.Strategy getScopeStrategy() {
- if (scopeStrategy == null) {
- scopeStrategy = (Scope.Strategy) container.localScopeStrategy.get();
+ if (scopeStrategy == null) {
+ throw new IllegalStateException("Scope strategy not set. Please call Container.setScopeStrategy().");
+ }
+ }
- if (scopeStrategy == null) {
- throw new IllegalStateException("Scope strategy not set. Please call Container.setScopeStrategy().");
- }
+ return scopeStrategy;
}
- return scopeStrategy;
- }
-
- @SuppressWarnings("unchecked")
- ConstructionContext getConstructionContext(Object key) {
- ConstructionContext constructionContext = (ConstructionContext) constructionContexts.get(key);
- if (constructionContext == null) {
- constructionContext = new ConstructionContext();
- constructionContexts.put(key, constructionContext);
+ @SuppressWarnings("unchecked")
+ ConstructionContext getConstructionContext(Object key) {
+ ConstructionContext constructionContext = (ConstructionContext) constructionContexts.get(key);
+ if (constructionContext == null) {
+ constructionContext = new ConstructionContext<>();
+ constructionContexts.put(key, constructionContext);
+ }
+ return constructionContext;
}
- return constructionContext;
- }
- @SuppressWarnings("unchecked")
- ExternalContext getExternalContext() {
- return (ExternalContext) externalContext;
- }
+ @SuppressWarnings("unchecked")
+ ExternalContext getExternalContext() {
+ return (ExternalContext) externalContext;
+ }
- void setExternalContext(ExternalContext> externalContext) {
- this.externalContext = externalContext;
- }
+ void setExternalContext(ExternalContext> externalContext) {
+ this.externalContext = externalContext;
+ }
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/inject/Key.java b/core/src/main/java/com/opensymphony/xwork2/inject/Key.java
index 1789b23bf4..6aff2a5bdb 100644
--- a/core/src/main/java/com/opensymphony/xwork2/inject/Key.java
+++ b/core/src/main/java/com/opensymphony/xwork2/inject/Key.java
@@ -60,13 +60,12 @@ public int hashCode() {
@Override
public boolean equals(Object o) {
- if (!(o instanceof Key)) {
+ if (!(o instanceof Key other)) {
return false;
}
if (o == this) {
return true;
}
- Key other = (Key) o;
return name.equals(other.name) && type.equals(other.type);
}
@@ -76,6 +75,6 @@ public String toString() {
}
static Key newInstance(Class type, String name) {
- return new Key(type, name);
+ return new Key<>(type, name);
}
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/inject/Scope.java b/core/src/main/java/com/opensymphony/xwork2/inject/Scope.java
index 8f74b3a766..3b354cb986 100644
--- a/core/src/main/java/com/opensymphony/xwork2/inject/Scope.java
+++ b/core/src/main/java/com/opensymphony/xwork2/inject/Scope.java
@@ -43,7 +43,7 @@ InternalFactory extends T> scopeFactory(Class type, String name,
SINGLETON {
@Override
InternalFactory extends T> scopeFactory(Class type, String name, final InternalFactory extends T> factory) {
- return new InternalFactory() {
+ return new InternalFactory<>() {
volatile T instance;
public T create(InternalContext context) {
@@ -84,7 +84,7 @@ public String toString() {
THREAD {
@Override
InternalFactory extends T> scopeFactory(Class type, String name, final InternalFactory extends T> factory) {
- return new InternalFactory() {
+ return new InternalFactory<>() {
final ThreadLocal threadLocal = new ThreadLocal<>();
public T create(final InternalContext context) {
@@ -115,7 +115,7 @@ public String toString() {
REQUEST {
@Override
InternalFactory extends T> scopeFactory(final Class type, final String name, final InternalFactory extends T> factory) {
- return new InternalFactory() {
+ return new InternalFactory<>() {
public T create(InternalContext context) {
Strategy strategy = context.getScopeStrategy();
try {
@@ -145,7 +145,7 @@ public String toString() {
SESSION {
@Override
InternalFactory extends T> scopeFactory(final Class type, final String name, final InternalFactory extends T> factory) {
- return new InternalFactory() {
+ return new InternalFactory<>() {
public T create(InternalContext context) {
Strategy strategy = context.getScopeStrategy();
try {
@@ -175,7 +175,7 @@ public String toString() {
WIZARD {
@Override
InternalFactory extends T> scopeFactory(final Class type, final String name, final InternalFactory extends T> factory) {
- return new InternalFactory() {
+ return new InternalFactory<>() {
public T create(InternalContext context) {
Strategy strategy = context.getScopeStrategy();
try {
@@ -205,21 +205,14 @@ Callable extends T> toCallable(final InternalContext context,
}
public static Scope fromString(String scopeStr) {
- switch (scopeStr) {
- case "prototype":
- return Scope.PROTOTYPE;
- case "request":
- return Scope.REQUEST;
- case "session":
- return Scope.SESSION;
- case "thread":
- return Scope.THREAD;
- case "wizard":
- return Scope.WIZARD;
- case "singleton":
- default:
- return Scope.SINGLETON;
- }
+ return switch (scopeStr) {
+ case "prototype" -> Scope.PROTOTYPE;
+ case "request" -> Scope.REQUEST;
+ case "session" -> Scope.SESSION;
+ case "thread" -> Scope.THREAD;
+ case "wizard" -> Scope.WIZARD;
+ default -> Scope.SINGLETON;
+ };
}
/**
diff --git a/core/src/main/java/com/opensymphony/xwork2/inject/Scoped.java b/core/src/main/java/com/opensymphony/xwork2/inject/Scoped.java
index f5c272b705..9a72d1aa84 100644
--- a/core/src/main/java/com/opensymphony/xwork2/inject/Scoped.java
+++ b/core/src/main/java/com/opensymphony/xwork2/inject/Scoped.java
@@ -1,12 +1,12 @@
/**
* Copyright (C) 2006 Google Inc.
- *
+ *
* Licensed 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
- *
+ *
+ * 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.
@@ -18,9 +18,10 @@
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
/**
* Annotates a scoped implementation class.
*
@@ -30,8 +31,8 @@
@Retention(RUNTIME)
public @interface Scoped {
- /**
- * @return scope
- */
- Scope value();
+ /**
+ * @return scope
+ */
+ Scope value();
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/inject/util/ReferenceCache.java b/core/src/main/java/com/opensymphony/xwork2/inject/util/ReferenceCache.java
index d80b457010..212e735ecb 100644
--- a/core/src/main/java/com/opensymphony/xwork2/inject/util/ReferenceCache.java
+++ b/core/src/main/java/com/opensymphony/xwork2/inject/util/ReferenceCache.java
@@ -22,7 +22,13 @@
import java.io.IOException;
import java.io.ObjectInputStream;
-import java.util.concurrent.*;
+import java.io.Serial;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
import static com.opensymphony.xwork2.inject.util.ReferenceType.STRONG;
@@ -34,6 +40,7 @@
*/
public abstract class ReferenceCache extends ReferenceMap {
+ @Serial
private static final long serialVersionUID = 0;
transient ConcurrentMap> futures = new ConcurrentHashMap<>();
@@ -177,18 +184,19 @@ public static ReferenceCache of(
ReferenceType valueReferenceType,
final Function super K, ? extends V> function) {
ensureNotNull(function);
- return new ReferenceCache(keyReferenceType, valueReferenceType) {
+ return new ReferenceCache<>(keyReferenceType, valueReferenceType) {
@Override
protected V create(K key) {
return function.apply(key);
}
+ @Serial
private static final long serialVersionUID = 0;
};
}
- private void readObject(ObjectInputStream in) throws IOException,
- ClassNotFoundException {
+ @Serial
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
this.futures = new ConcurrentHashMap<>();
this.localFuture = new ThreadLocal<>();
diff --git a/core/src/main/java/com/opensymphony/xwork2/inject/util/ReferenceMap.java b/core/src/main/java/com/opensymphony/xwork2/inject/util/ReferenceMap.java
index 755b6fc56c..ce37624254 100644
--- a/core/src/main/java/com/opensymphony/xwork2/inject/util/ReferenceMap.java
+++ b/core/src/main/java/com/opensymphony/xwork2/inject/util/ReferenceMap.java
@@ -23,9 +23,15 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.Serial;
import java.io.Serializable;
import java.lang.ref.Reference;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -58,6 +64,7 @@
@SuppressWarnings("unchecked")
public class ReferenceMap implements Map, Serializable {
+ @Serial
private static final long serialVersionUID = 0;
transient ConcurrentMap delegate;
@@ -87,7 +94,7 @@ public ReferenceMap(ReferenceType keyReferenceType,
V internalGet(K key) {
Object valueReference = delegate.get(makeKeyReferenceAware(key));
- return valueReference == null ? null : (V) dereferenceValue(valueReference);
+ return valueReference == null ? null : dereferenceValue(valueReference);
}
public V get(final Object key) {
@@ -99,7 +106,7 @@ V execute(Strategy strategy, K key, V value) {
ensureNotNull(key, value);
Object keyReference = referenceKey(key);
Object valueReference = strategy.execute(this, keyReference, referenceValue(keyReference, value));
- return valueReference == null ? null : (V) dereferenceValue(valueReference);
+ return valueReference == null ? null : dereferenceValue(valueReference);
}
public V put(K key, V value) {
@@ -110,7 +117,7 @@ public V remove(Object key) {
ensureNotNull(key);
Object referenceAwareKey = makeKeyReferenceAware(key);
Object valueReference = delegate.remove(referenceAwareKey);
- return valueReference == null ? null : (V) dereferenceValue(valueReference);
+ return valueReference == null ? null : dereferenceValue(valueReference);
}
public int size() {
@@ -218,16 +225,12 @@ Entry dereferenceEntry(Map.Entry entry) {
* Creates a reference for a key.
*/
Object referenceKey(K key) {
- switch (keyReferenceType) {
- case STRONG:
- return key;
- case SOFT:
- return new SoftKeyReference(key);
- case WEAK:
- return new WeakKeyReference(key);
- default:
- throw new AssertionError();
- }
+ return switch (keyReferenceType) {
+ case STRONG -> key;
+ case SOFT -> new SoftKeyReference(key);
+ case WEAK -> new WeakKeyReference(key);
+ default -> throw new AssertionError();
+ };
}
/**
@@ -255,16 +258,12 @@ Object dereference(ReferenceType referenceType, Object reference) {
* Creates a reference for a value.
*/
Object referenceValue(Object keyReference, Object value) {
- switch (valueReferenceType) {
- case STRONG:
- return value;
- case SOFT:
- return new SoftValueReference(keyReference, value);
- case WEAK:
- return new WeakValueReference(keyReference, value);
- default:
- throw new AssertionError();
- }
+ return switch (valueReferenceType) {
+ case STRONG -> value;
+ case SOFT -> new SoftValueReference(keyReference, value);
+ case WEAK -> new WeakValueReference(keyReference, value);
+ default -> throw new AssertionError();
+ };
}
/**
@@ -476,7 +475,7 @@ public boolean equals(Object obj) {
}
protected interface Strategy {
- public Object execute(ReferenceMap map, Object keyReference, Object valueReference);
+ Object execute(ReferenceMap map, Object keyReference, Object valueReference);
}
protected Strategy putStrategy() {
@@ -508,7 +507,7 @@ public Object execute(ReferenceMap map, Object keyReference, Object valueReferen
public Object execute(ReferenceMap map, Object keyReference, Object valueReference) {
return map.delegate.putIfAbsent(keyReference, valueReference);
}
- };
+ }
}
private static PutStrategy defaultPutStrategy;
@@ -575,6 +574,7 @@ static void ensureNotNull(Object... array) {
}
}
+ @Serial
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeInt(size());
@@ -591,11 +591,11 @@ private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(null);
}
- private void readObject(ObjectInputStream in) throws IOException,
- ClassNotFoundException {
+ @Serial
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
int size = in.readInt();
- this.delegate = new ConcurrentHashMap(size);
+ this.delegate = new ConcurrentHashMap<>(size);
while (true) {
K key = (K) in.readObject();
if (key == null) {
diff --git a/core/src/main/java/com/opensymphony/xwork2/inject/util/ReferenceType.java b/core/src/main/java/com/opensymphony/xwork2/inject/util/ReferenceType.java
index 474b10f33c..b9662732ce 100644
--- a/core/src/main/java/com/opensymphony/xwork2/inject/util/ReferenceType.java
+++ b/core/src/main/java/com/opensymphony/xwork2/inject/util/ReferenceType.java
@@ -51,5 +51,5 @@ public enum ReferenceType {
*
* @see java.lang.ref.PhantomReference
*/
- PHANTOM;
+ PHANTOM
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/AbstractInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/AbstractInterceptor.java
index 21e459c291..13bf646d47 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/AbstractInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/AbstractInterceptor.java
@@ -30,18 +30,21 @@ public abstract class AbstractInterceptor implements ConditionalInterceptor {
/**
* Does nothing
*/
+ @Override
public void init() {
}
/**
* Does nothing
*/
+ @Override
public void destroy() {
}
/**
* Override to handle interception
*/
+ @Override
public abstract String intercept(ActionInvocation invocation) throws Exception;
/**
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java
index c57df3dabf..28109cbf9a 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java
@@ -160,7 +160,7 @@ public void setAliasesKey(String aliasesKey) {
ValueStack stack = ac.getValueStack();
Object obj = stack.findValue(aliasExpression);
- if (obj instanceof Map) {
+ if (obj instanceof Map aliases) {
//get secure stack
ValueStack newStack = valueStackFactory.createValueStack(stack);
boolean clearableStack = newStack instanceof ClearableValueStack;
@@ -178,7 +178,6 @@ public void setAliasesKey(String aliasesKey) {
}
// override
- Map aliases = (Map) obj;
for (Object o : aliases.entrySet()) {
Map.Entry entry = (Map.Entry) o;
String name = entry.getKey().toString();
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
index 31b0075a35..7e7d132f6e 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
@@ -23,16 +23,21 @@
import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.Unchainable;
import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.util.ProxyUtil;
import com.opensymphony.xwork2.util.CompoundRoot;
+import com.opensymphony.xwork2.util.ProxyUtil;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.ValueStack;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.LogManager;
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsConstants;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
/**
@@ -180,7 +185,7 @@ private Collection prepareExcludes() {
Collection localExcludes = excludes;
if (!copyErrors || !copyMessages ||!copyFieldErrors) {
if (localExcludes == null) {
- localExcludes = new HashSet();
+ localExcludes = new HashSet<>();
if (!copyErrors) {
localExcludes.add(ACTION_ERRORS);
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ConversionErrorInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ConversionErrorInterceptor.java
index ee8e392815..a30d81a004 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ConversionErrorInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ConversionErrorInterceptor.java
@@ -41,13 +41,13 @@
* display the original string ("abc") again rather than the int value (likely 0, which would make very little sense to
* the user).
*
- *
+ *
*
* Note: Since 2.5.2, this interceptor extends {@link MethodFilterInterceptor}, therefore being
* able to deal with excludeMethods / includeMethods parameters. See [Workflow Interceptor]
* (class {@link DefaultWorkflowInterceptor}) for documentation and examples on how to use this feature.
*
- *
+ *
*
*
* Interceptor parameters:
@@ -114,8 +114,7 @@ public String doIntercept(ActionInvocation invocation) throws Exception {
String message = XWorkConverter.getConversionErrorMessage(propertyName, conversionData.getToClass(), stack);
Object action = invocation.getAction();
- if (action instanceof ValidationAware) {
- ValidationAware va = (ValidationAware) action;
+ if (action instanceof ValidationAware va) {
va.addFieldError(propertyName, message);
}
@@ -130,13 +129,11 @@ public String doIntercept(ActionInvocation invocation) throws Exception {
if (fakie != null) {
// if there were some errors, put the original (fake) values in place right before the result
stack.getContext().put(ORIGINAL_PROPERTY_OVERRIDE, fakie);
- invocation.addPreResultListener(new PreResultListener() {
- public void beforeResult(ActionInvocation invocation, String resultCode) {
- Map fakie = (Map) invocation.getInvocationContext().get(ORIGINAL_PROPERTY_OVERRIDE);
+ invocation.addPreResultListener((invocation1, resultCode) -> {
+ var fakie1 = (Map) invocation1.getInvocationContext().get(ORIGINAL_PROPERTY_OVERRIDE);
- if (fakie != null) {
- invocation.getStack().setExprOverrides(fakie);
- }
+ if (fakie1 != null) {
+ invocation1.getStack().setExprOverrides(fakie1);
}
});
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java
index d2cbd0b780..118811a59a 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java
@@ -26,10 +26,12 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import java.io.Serial;
+
/**
*
*
- * An interceptor that makes sure there are not validation, conversion or action errors before allowing the interceptor chain to continue.
+ * An interceptor that makes sure there are not validation, conversion or action errors before allowing the interceptor chain to continue.
* If a single FieldError or ActionError (including the ones replicated by the Message Store Interceptor in a redirection) is found, the INPUT result will be triggered.
* This interceptor does not perform any validation .
*
@@ -132,6 +134,7 @@
*/
public class DefaultWorkflowInterceptor extends MethodFilterInterceptor {
+ @Serial
private static final long serialVersionUID = 7563014655616490865L;
private static final Logger LOG = LogManager.getLogger(DefaultWorkflowInterceptor.class);
@@ -161,8 +164,7 @@ public void setInputResultName(String inputResultName) {
protected String doIntercept(ActionInvocation invocation) throws Exception {
Object action = invocation.getAction();
- if (action instanceof ValidationAware) {
- ValidationAware validationAwareAction = (ValidationAware) action;
+ if (action instanceof ValidationAware validationAwareAction) {
if (validationAwareAction.hasErrors()) {
LOG.debug("Errors on action [{}], returning result name [{}]", validationAwareAction, inputResultName);
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionHolder.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionHolder.java
index 9ba05ea0cf..ff813dbca5 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionHolder.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionHolder.java
@@ -20,8 +20,9 @@
import java.io.IOException;
import java.io.PrintWriter;
-import java.io.StringWriter;
+import java.io.Serial;
import java.io.Serializable;
+import java.io.StringWriter;
/**
*
@@ -35,8 +36,9 @@
*/
public class ExceptionHolder implements Serializable {
+ @Serial
private static final long serialVersionUID = 1L;
- private Exception exception;
+ private final Exception exception;
/**
* Holds the given exception
@@ -76,5 +78,5 @@ public String getExceptionStack() {
return exceptionStack;
}
-
+
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java
index e60550ca69..db6dadec93 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.java
@@ -20,8 +20,8 @@
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig;
-import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.struts2.dispatcher.HttpParameters;
import java.util.List;
@@ -273,12 +273,11 @@ protected ExceptionMappingConfig findMappingFromExceptions(List= 0 && depth < deepest) {
deepest = depth;
- config = exceptionMappingConfig;
+ config = exceptionMapping;
}
}
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/LoggingInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/LoggingInterceptor.java
index 6ba498b3cb..271ed05bed 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/LoggingInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/LoggingInterceptor.java
@@ -78,7 +78,7 @@ private void logMessage(ActionInvocation invocation, String baseMessage) {
StringBuilder message = new StringBuilder(baseMessage);
String namespace = invocation.getProxy().getNamespace();
- if ((namespace != null) && (namespace.trim().length() > 0)) {
+ if (namespace != null && !namespace.trim().isEmpty()) {
message.append(namespace).append("/");
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/MethodFilterInterceptorUtil.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/MethodFilterInterceptorUtil.java
index beacb87844..ac5acee652 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/MethodFilterInterceptorUtil.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/MethodFilterInterceptorUtil.java
@@ -24,18 +24,20 @@
import java.util.HashMap;
import java.util.Set;
+import static java.util.Objects.requireNonNullElse;
+
/**
- * Utility class contains common methods used by
+ * Utility class contains common methods used by
* {@link com.opensymphony.xwork2.interceptor.MethodFilterInterceptor}.
- *
+ *
* @author tm_jee
*/
public class MethodFilterInterceptorUtil {
/**
* Static method to decide if the specified method
should be
- * apply (not filtered) depending on the set of excludeMethods
and
- * includeMethods
.
+ * apply (not filtered) depending on the set of excludeMethods
and
+ * includeMethods
.
*
*
*
@@ -50,7 +52,7 @@ public class MethodFilterInterceptorUtil {
* @return true if the method should be applied.
*/
public static boolean applyMethod(Set excludeMethods, Set includeMethods, String method) {
-
+
// quick check to see if any actual pattern matching is needed
boolean needsPatternMatch = false;
for (String includeMethod : includeMethods) {
@@ -59,7 +61,7 @@ public static boolean applyMethod(Set excludeMethods, Set includ
break;
}
}
-
+
for (String excludeMethod : excludeMethods) {
if (!"*".equals(excludeMethod) && excludeMethod.contains("*")) {
needsPatternMatch = true;
@@ -67,25 +69,19 @@ public static boolean applyMethod(Set excludeMethods, Set includ
}
}
- // this section will try to honor the original logic, while
+ // this section will try to honor the original logic, while
// still allowing for wildcards later
- if (!needsPatternMatch && (includeMethods.contains("*") || includeMethods.size() == 0) ) {
- if (excludeMethods != null
- && excludeMethods.contains(method)
- && !includeMethods.contains(method) ) {
+ if (!needsPatternMatch && (includeMethods.contains("*") || includeMethods.isEmpty()) ) {
+ if (excludeMethods.contains(method) && !includeMethods.contains(method)) {
return false;
}
}
-
+
// test the methods using pattern matching
WildcardHelper wildcard = new WildcardHelper();
String methodCopy ;
- if (method == null ) { // no method specified
- methodCopy = "";
- }
- else {
- methodCopy = new String(method);
- }
+ // no method specified
+ methodCopy = requireNonNullElse(method, "");
for (String pattern : includeMethods) {
if (pattern.contains("*")) {
int[] compiledPattern = wildcard.compilePattern(pattern);
@@ -105,7 +101,7 @@ public static boolean applyMethod(Set excludeMethods, Set includ
return false;
}
- // CHECK ME: Previous implementation used include method
+ // CHECK ME: Previous implementation used include method
for ( String pattern : excludeMethods) {
if (pattern.contains("*")) {
int[] compiledPattern = wildcard.compilePattern(pattern);
@@ -113,26 +109,26 @@ public static boolean applyMethod(Set excludeMethods, Set includ
boolean matches = wildcard.match(matchedPatterns, methodCopy, compiledPattern);
if (matches) {
// if found, and wasn't included earlier, don't run it
- return false;
+ return false;
}
}
else {
if (pattern.equals(methodCopy)) {
// if found, and wasn't included earlier, don't run it
- return false;
+ return false;
}
}
}
-
+
// default fall-back from before changes
- return includeMethods.size() == 0 || includeMethods.contains(method) || includeMethods.contains("*");
+ return includeMethods.isEmpty() || includeMethods.contains(method) || includeMethods.contains("*");
}
-
+
/**
* Same as {@link #applyMethod(Set, Set, String)}, except that excludeMethods
* and includeMethods
are supplied as comma separated string.
- *
+ *
* @param excludeMethods comma seperated string of methods to exclude.
* @param includeMethods comma seperated string of methods to include.
* @param method the specified method to check
@@ -141,7 +137,7 @@ public static boolean applyMethod(Set excludeMethods, Set includ
public static boolean applyMethod(String excludeMethods, String includeMethods, String method) {
Set includeMethodsSet = TextParseUtil.commaDelimitedStringToSet(includeMethods == null? "" : includeMethods);
Set excludeMethodsSet = TextParseUtil.commaDelimitedStringToSet(excludeMethods == null? "" : excludeMethods);
-
+
return applyMethod(excludeMethodsSet, includeMethodsSet, method);
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java
index f1919a8c9e..d8c4a31439 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java
@@ -88,8 +88,7 @@ public void setRefreshModelBeforeResult(boolean val) {
public String intercept(ActionInvocation invocation) throws Exception {
Object action = invocation.getAction();
- if (action instanceof ModelDriven) {
- ModelDriven modelDriven = (ModelDriven) action;
+ if (action instanceof ModelDriven modelDriven) {
ValueStack stack = invocation.getStack();
Object model = modelDriven.getModel();
if (model != null) {
@@ -106,7 +105,7 @@ public String intercept(ActionInvocation invocation) throws Exception {
* Refreshes the model instance on the value stack, if it has changed
*/
protected static class RefreshModelBeforeResult implements PreResultListener {
- private Object originalModel;
+ private final Object originalModel;
protected ModelDriven action;
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/PrefixMethodInvocationUtil.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/PrefixMethodInvocationUtil.java
index 040080824e..bd0609370e 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/PrefixMethodInvocationUtil.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/PrefixMethodInvocationUtil.java
@@ -19,8 +19,8 @@
package com.opensymphony.xwork2.interceptor;
import com.opensymphony.xwork2.ActionInvocation;
-import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -28,7 +28,7 @@
/**
*
* A utility class for invoking prefixed methods in action class.
- *
+ *
* Interceptors that made use of this class are:
*
*
* *
*
- *
+ *
* In DefaultWorkflowInterceptor
* applies only when action implements {@link com.opensymphony.xwork2.Validateable}
*
@@ -45,12 +45,12 @@
* else if the action class have validateDo{MethodName}(), it will be invoked
* no matter if 1] or 2] is performed, if alwaysInvokeValidate property of the interceptor is "true" (which is by default "true"), validate() will be invoked.
*
- *
+ *
*
- *
- *
+ *
+ *
*
- *
+ *
* In PrepareInterceptor
* Applies only when action implements Preparable
*
@@ -58,14 +58,14 @@
* else if the action class have prepareDo(MethodName()}(), it will be invoked
* no matter if 1] or 2] is performed, if alwaysinvokePrepare property of the interceptor is "true" (which is by default "true"), prepare() will be invoked.
*
- *
+ *
*
- *
+ *
* @author Philip Luppens
* @author tm_jee
*/
public class PrefixMethodInvocationUtil {
-
+
private static final Logger LOG = LogManager.getLogger(PrefixMethodInvocationUtil.class);
private static final String DEFAULT_INVOCATION_METHODNAME = "execute";
@@ -76,7 +76,7 @@ public class PrefixMethodInvocationUtil {
*
* This method will prefix actionInvocation
's ActionProxy
's
* method
with prefixes
before invoking the prefixed method.
- * Order of the prefixes
is important, as this method will return once
+ * Order of the prefixes
is important, as this method will return once
* a prefixed method is found in the action class.
*
*
@@ -89,7 +89,7 @@ public class PrefixMethodInvocationUtil {
*
*
*
- * Assuming actionInvocation.getProxy(),getMethod()
returns "submit",
+ * Assuming actionInvocation.getProxy(),getMethod()
returns "submit",
* the order of invocation would be as follows:-
*
*
@@ -99,12 +99,12 @@ public class PrefixMethodInvocationUtil {
*
*
*
- * If prepareSubmit()
exists, it will be invoked and this method
- * will return, prepareDoSubmit()
will NOT be invoked.
+ * If prepareSubmit()
exists, it will be invoked and this method
+ * will return, prepareDoSubmit()
will NOT be invoked.
*
*
*
- * On the other hand, if prepareDoSubmit()
does not exists, and
+ * On the other hand, if prepareDoSubmit()
does not exists, and
* prepareDoSubmit()
exists, it will be invoked.
*
*
@@ -119,29 +119,29 @@ public class PrefixMethodInvocationUtil {
*/
public static void invokePrefixMethod(ActionInvocation actionInvocation, String[] prefixes) throws InvocationTargetException, IllegalAccessException {
Object action = actionInvocation.getAction();
-
+
String methodName = actionInvocation.getProxy().getMethod();
-
+
if (methodName == null) {
- // if null returns (possible according to the docs), use the default execute
+ // if null returns (possible according to the docs), use the default execute
methodName = DEFAULT_INVOCATION_METHODNAME;
}
-
+
Method method = getPrefixedMethod(prefixes, methodName, action);
if (method != null) {
- method.invoke(action, new Object[0]);
+ method.invoke(action);
}
}
-
-
+
+
/**
- * This method returns a {@link Method} in action
. The method
+ * This method returns a {@link Method} in action
. The method
* returned is found by searching for method in action
whose method name
* is equals to the result of appending each prefixes
* to methodName
. Only the first method found will be returned, hence
* the order of prefixes
is important. If none is found this method
* will return null.
- *
+ *
* @param prefixes the prefixes to prefix the methodName
* @param methodName the method name to be prefixed with prefixes
* @param action the action class of which the prefixed method is to be search for.
@@ -162,7 +162,7 @@ public static Method getPrefixedMethod(String[] prefixes, String methodName, Obj
}
return null;
}
-
+
/**
*
* This method capitalized the first character of methodName
.
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/PrepareInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/PrepareInterceptor.java
index 4516d760c6..78b3b9c952 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/PrepareInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/PrepareInterceptor.java
@@ -20,9 +20,8 @@
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Preparable;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.LogManager;
+import java.io.Serial;
import java.lang.reflect.InvocationTargetException;
/**
@@ -101,6 +100,7 @@
*/
public class PrepareInterceptor extends MethodFilterInterceptor {
+ @Serial
private static final long serialVersionUID = -5216969014510719786L;
private final static String PREPARE_PREFIX = "prepare";
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptor.java
index 22da179d46..c6daee0281 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptor.java
@@ -35,7 +35,7 @@
*
*
This interceptor only activates on actions that implement the {@link ScopedModelDriven} interface. If
* detected, it will retrieve the model class from the configured scope, then provide it to the Action.
- *
+ *
*
*
* Interceptor parameters:
@@ -45,7 +45,7 @@
*
*
* className - The model class name. Defaults to the class name of the object returned by the getModel() method.
- *
+ *
* name - The key to use when storing or retrieving the instance in a scope. Defaults to the model
* class name.
*
@@ -66,42 +66,42 @@
*
*
*
- *
+ *
* <-- Basic usage -->
* <interceptor name="scopedModelDriven" class="com.opensymphony.interceptor.ScopedModelDrivenInterceptor" />
- *
+ *
* <-- Using all available parameters -->
* <interceptor name="gangsterForm" class="com.opensymphony.interceptor.ScopedModelDrivenInterceptor">
* <param name="scope">session</param>
* <param name="name">gangsterForm</param>
* <param name="className">com.opensymphony.example.GangsterForm</param>
* </interceptor>
- *
+ *
*
*
*/
public class ScopedModelDrivenInterceptor extends AbstractInterceptor {
private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
-
+
private static final String GET_MODEL = "getModel";
private String scope;
private String name;
private String className;
private ObjectFactory objectFactory;
-
+
@Inject
public void setObjectFactory(ObjectFactory factory) {
this.objectFactory = factory;
}
-
+
protected Object resolveModel(ObjectFactory factory, ActionContext actionContext, String modelClassName, String modelScope, String modelName) throws Exception {
Object model;
Map scopeMap = actionContext.getContextMap();
if ("session".equals(modelScope)) {
scopeMap = actionContext.getSession();
}
-
+
model = scopeMap.get(modelName);
if (model == null) {
model = factory.buildBean(modelClassName, null);
@@ -114,12 +114,11 @@ protected Object resolveModel(ObjectFactory factory, ActionContext actionContext
public String intercept(ActionInvocation invocation) throws Exception {
Object action = invocation.getAction();
- if (action instanceof ScopedModelDriven) {
- ScopedModelDriven modelDriven = (ScopedModelDriven) action;
+ if (action instanceof ScopedModelDriven modelDriven) {
if (modelDriven.getModel() == null) {
ActionContext ctx = ActionContext.getContext();
ActionConfig config = invocation.getProxy().getConfig();
-
+
String cName = className;
if (cName == null) {
try {
@@ -127,7 +126,7 @@ public String intercept(ActionInvocation invocation) throws Exception {
Class cls = method.getReturnType();
cName = cls.getName();
} catch (NoSuchMethodException e) {
- throw new StrutsException("The " + GET_MODEL + "() is not defined in action " + action.getClass() + "", config);
+ throw new StrutsException("The " + GET_MODEL + "() is not defined in action " + action.getClass(), config);
}
}
String modelName = name;
@@ -161,5 +160,5 @@ public void setName(String name) {
*/
public void setScope(String scope) {
this.scope = scope;
- }
+ }
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/WithLazyParams.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/WithLazyParams.java
index 3e111d69c8..750d23af1d 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/WithLazyParams.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/WithLazyParams.java
@@ -47,11 +47,8 @@ class LazyParamInjector {
private final TextParseUtil.ParsedValueEvaluator valueEvaluator;
public LazyParamInjector(final ValueStack valueStack) {
- valueEvaluator = new TextParseUtil.ParsedValueEvaluator() {
- public Object evaluate(String parsedValue) {
- return valueStack.findValue(parsedValue); // no asType !!!
- }
- };
+ // no asType !!!
+ valueEvaluator = valueStack::findValue;
}
@Inject
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationWorkflowInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationWorkflowInterceptor.java
index 39b1252362..6f0a936999 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationWorkflowInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationWorkflowInterceptor.java
@@ -26,8 +26,6 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
/**
@@ -117,15 +115,11 @@ public String intercept(ActionInvocation invocation) throws Exception {
invocation.addPreResultListener(this);
List methods = new ArrayList<>(MethodUtils.getMethodsListWithAnnotation(action.getClass(), Before.class,
true, true));
- if (methods.size() > 0) {
+ if (!methods.isEmpty()) {
// methods are only sorted by priority
- Collections.sort(methods, new Comparator() {
- public int compare(Method method1, Method method2) {
- return comparePriorities(MethodUtils.getAnnotation(method1, Before.class, true,
- true).priority(), MethodUtils.getAnnotation(method2, Before.class, true,
- true).priority());
- }
- });
+ methods.sort((method1, method2) -> comparePriorities(
+ MethodUtils.getAnnotation(method1, Before.class, true, true).priority(),
+ MethodUtils.getAnnotation(method2, Before.class, true, true).priority()));
for (Method m : methods) {
final String resultCode = (String) MethodUtils.invokeMethod(action, true, m.getName());
if (resultCode != null) {
@@ -138,18 +132,13 @@ public int compare(Method method1, Method method2) {
String invocationResult = invocation.invoke();
// invoke any @After methods
- methods = new ArrayList(MethodUtils.getMethodsListWithAnnotation(action.getClass(), After.class,
- true, true));
+ methods = new ArrayList<>(MethodUtils.getMethodsListWithAnnotation(action.getClass(), After.class, true, true));
- if (methods.size() > 0) {
+ if (!methods.isEmpty()) {
// methods are only sorted by priority
- Collections.sort(methods, new Comparator() {
- public int compare(Method method1, Method method2) {
- return comparePriorities(MethodUtils.getAnnotation(method1, After.class, true,
- true).priority(), MethodUtils.getAnnotation(method2, After.class, true,
- true).priority());
- }
- });
+ methods.sort((method1, method2) -> comparePriorities(
+ MethodUtils.getAnnotation(method1, After.class, true, true).priority(),
+ MethodUtils.getAnnotation(method2, After.class, true, true).priority()));
for (Method m : methods) {
MethodUtils.invokeMethod(action, true, m.getName());
}
@@ -159,13 +148,7 @@ public int compare(Method method1, Method method2) {
}
protected static int comparePriorities(int val1, int val2) {
- if (val2 < val1) {
- return -1;
- } else if (val2 > val1) {
- return 1;
- } else {
- return 0;
- }
+ return Integer.compare(val2, val1);
}
/**
@@ -175,18 +158,14 @@ protected static int comparePriorities(int val1, int val2) {
*/
public void beforeResult(ActionInvocation invocation, String resultCode) {
Object action = invocation.getAction();
- List methods = new ArrayList(MethodUtils.getMethodsListWithAnnotation(action.getClass(),
+ List methods = new ArrayList<>(MethodUtils.getMethodsListWithAnnotation(action.getClass(),
BeforeResult.class, true, true));
- if (methods.size() > 0) {
+ if (!methods.isEmpty()) {
// methods are only sorted by priority
- Collections.sort(methods, new Comparator() {
- public int compare(Method method1, Method method2) {
- return comparePriorities(MethodUtils.getAnnotation(method1, BeforeResult.class, true,
- true).priority(), MethodUtils.getAnnotation(method2, BeforeResult.class,
- true, true).priority());
- }
- });
+ methods.sort((method1, method2) -> comparePriorities(
+ MethodUtils.getAnnotation(method1, BeforeResult.class, true, true).priority(),
+ MethodUtils.getAnnotation(method2, BeforeResult.class, true, true).priority()));
for (Method m : methods) {
try {
MethodUtils.invokeMethod(action, true, m.getName());
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/BeanInfoCacheFactory.java b/core/src/main/java/com/opensymphony/xwork2/ognl/BeanInfoCacheFactory.java
index 3ea2100017..58d03f5a14 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/BeanInfoCacheFactory.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/BeanInfoCacheFactory.java
@@ -18,6 +18,6 @@
/**
* A proxy interface to be used with Struts DI mechanism
*/
-public interface BeanInfoCacheFactory extends OgnlCacheFactory {
+public interface BeanInfoCacheFactory extends OgnlCacheFactory {
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlLRUCache.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlLRUCache.java
index e324418ceb..9de52f686d 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlLRUCache.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlLRUCache.java
@@ -41,7 +41,7 @@ public class OgnlLRUCache implements OgnlCache {
public OgnlLRUCache(int evictionLimit, int initialCapacity, float loadFactor) {
cacheEvictionLimit = new AtomicInteger(evictionLimit);
// Access-order mode selected (order mode true in LinkedHashMap constructor).
- ognlLRUCache = Collections.synchronizedMap(new LinkedHashMap(initialCapacity, loadFactor, true) {
+ ognlLRUCache = Collections.synchronizedMap(new LinkedHashMap<>(initialCapacity, loadFactor, true) {
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > cacheEvictionLimit.get();
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlNullHandlerWrapper.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlNullHandlerWrapper.java
index 9b24261c82..d05d4636db 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlNullHandlerWrapper.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlNullHandlerWrapper.java
@@ -25,16 +25,18 @@
public class OgnlNullHandlerWrapper implements ognl.NullHandler {
private final NullHandler wrapped;
-
+
public OgnlNullHandlerWrapper(NullHandler target) {
this.wrapped = target;
}
-
+
+ @Override
public Object nullMethodResult(Map context, Object target,
String methodName, Object[] args) {
return wrapped.nullMethodResult(context, target, methodName, args);
}
+ @Override
public Object nullPropertyValue(Map context, Object target, Object property) {
return wrapped.nullPropertyValue(context, target, property);
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionContextFactory.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionContextFactory.java
index ec3db9f9af..b1821ccf5f 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionContextFactory.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionContextFactory.java
@@ -25,6 +25,7 @@
public class OgnlReflectionContextFactory implements ReflectionContextFactory {
+ @Override
public Map createDefaultContext(Object root) {
return Ognl.createDefaultContext(root);
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java
index 1dbc8c67e5..23dec6343e 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java
@@ -40,10 +40,12 @@ public void setOgnlUtil(OgnlUtil ognlUtil) {
this.ognlUtil = ognlUtil;
}
+ @Override
public Field getField(Class inClass, String name) {
return OgnlRuntime.getField(inClass, name);
}
+ @Override
public Method getGetMethod(Class targetClass, String propertyName)
throws IntrospectionException, ReflectionException {
try {
@@ -53,6 +55,7 @@ public Method getGetMethod(Class targetClass, String propertyName)
}
}
+ @Override
public Method getSetMethod(Class targetClass, String propertyName)
throws IntrospectionException, ReflectionException {
try {
@@ -62,18 +65,22 @@ public Method getSetMethod(Class targetClass, String propertyName)
}
}
+ @Override
public void setProperties(Map props, Object o, Map context) {
ognlUtil.setProperties(props, o, context);
}
+ @Override
public void setProperties(Map props, Object o, Map context, boolean throwPropertyExceptions) throws ReflectionException{
ognlUtil.setProperties(props, o, context, throwPropertyExceptions);
}
+ @Override
public void setProperties(Map properties, Object o) {
ognlUtil.setProperties(properties, o);
}
+ @Override
public PropertyDescriptor getPropertyDescriptor(Class targetClass,
String propertyName) throws IntrospectionException,
ReflectionException {
@@ -84,16 +91,19 @@ public PropertyDescriptor getPropertyDescriptor(Class targetClass,
}
}
+ @Override
public void copy(Object from, Object to, Map context,
Collection exclusions, Collection inclusions) {
copy(from, to, context, exclusions, inclusions, null);
}
+ @Override
public void copy(Object from, Object to, Map context,
Collection exclusions, Collection inclusions, Class> editable) {
ognlUtil.copy(from, to, context, exclusions, inclusions, editable);
}
+ @Override
public Object getRealTarget(String property, Map context, Object root)
throws ReflectionException {
try {
@@ -103,14 +113,17 @@ public Object getRealTarget(String property, Map context, Object
}
}
+ @Override
public void setProperty(String name, Object value, Object o, Map context) {
ognlUtil.setProperty(name, value, o, context);
}
+ @Override
public void setProperty(String name, Object value, Object o, Map context, boolean throwPropertyExceptions) {
ognlUtil.setProperty(name, value, o, context, throwPropertyExceptions);
}
+ @Override
public Map getBeanMap(Object source) throws IntrospectionException,
ReflectionException {
try {
@@ -120,6 +133,7 @@ public Map getBeanMap(Object source) throws IntrospectionException,
}
}
+ @Override
public Object getValue(String expression, Map context, Object root)
throws ReflectionException {
try {
@@ -129,6 +143,7 @@ public Object getValue(String expression, Map context, Object ro
}
}
+ @Override
public void setValue(String expression, Map context, Object root,
Object value) throws ReflectionException {
try {
@@ -138,8 +153,8 @@ public void setValue(String expression, Map context, Object root
}
}
- public PropertyDescriptor[] getPropertyDescriptors(Object source)
- throws IntrospectionException {
+ @Override
+ public PropertyDescriptor[] getPropertyDescriptors(Object source) throws IntrospectionException {
return ognlUtil.getPropertyDescriptors(source);
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlTypeConverterWrapper.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlTypeConverterWrapper.java
index c2783b9698..65e614afe8 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlTypeConverterWrapper.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlTypeConverterWrapper.java
@@ -36,12 +36,12 @@ public OgnlTypeConverterWrapper(TypeConverter converter) {
}
this.typeConverter = converter;
}
-
- public Object convertValue(Map context, Object target, Member member,
- String propertyName, Object value, Class toType) {
+
+ @Override
+ public Object convertValue(Map context, Object target, Member member, String propertyName, Object value, Class toType) {
return typeConverter.convertValue(context, target, member, propertyName, value, toType);
}
-
+
public TypeConverter getTarget() {
return typeConverter;
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java
index a052305d08..50de36d48d 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java
@@ -146,6 +146,7 @@ protected void setShouldFallbackToContext(String shouldFallbackToContext) {
/**
* @see com.opensymphony.xwork2.util.ValueStack#getContext()
*/
+ @Override
public Map getContext() {
return context;
}
@@ -158,6 +159,7 @@ public ActionContext getActionContext() {
/**
* @see com.opensymphony.xwork2.util.ValueStack#setDefaultType(java.lang.Class)
*/
+ @Override
public void setDefaultType(Class defaultType) {
this.defaultType = defaultType;
}
@@ -176,6 +178,7 @@ public void setExprOverrides(Map overrides) {
/**
* @see com.opensymphony.xwork2.util.ValueStack#getExprOverrides()
*/
+ @Override
public Map getExprOverrides() {
return this.overrides;
}
@@ -183,6 +186,7 @@ public Map getExprOverrides() {
/**
* @see com.opensymphony.xwork2.util.ValueStack#getRoot()
*/
+ @Override
public CompoundRoot getRoot() {
return root;
}
@@ -190,6 +194,7 @@ public CompoundRoot getRoot() {
/**
* @see com.opensymphony.xwork2.util.ValueStack#setParameter(String, Object)
*/
+ @Override
public void setParameter(String expr, Object value) {
setValue(expr, value, devMode);
}
@@ -197,6 +202,7 @@ public void setParameter(String expr, Object value) {
/**
* @see com.opensymphony.xwork2.util.ValueStack#setValue(java.lang.String, java.lang.Object)
*/
+ @Override
public void setValue(String expr, Object value) {
setValue(expr, value, devMode);
}
@@ -204,6 +210,7 @@ public void setValue(String expr, Object value) {
/**
* @see com.opensymphony.xwork2.util.ValueStack#setValue(java.lang.String, java.lang.Object, boolean)
*/
+ @Override
public void setValue(String expr, Object value, boolean throwExceptionOnFailure) {
Map context = getContext();
try {
@@ -261,10 +268,12 @@ protected void handleOgnlException(String expr, Object value, boolean throwExcep
/**
* @see com.opensymphony.xwork2.util.ValueStack#findString(java.lang.String)
*/
+ @Override
public String findString(String expr) {
return (String) findValue(expr, String.class);
}
+ @Override
public String findString(String expr, boolean throwExceptionOnFailure) {
return (String) findValue(expr, String.class, throwExceptionOnFailure);
}
@@ -272,6 +281,7 @@ public String findString(String expr, boolean throwExceptionOnFailure) {
/**
* @see com.opensymphony.xwork2.util.ValueStack#findValue(java.lang.String)
*/
+ @Override
public Object findValue(String expr, boolean throwExceptionOnFailure) {
try {
setupExceptionOnFailure(throwExceptionOnFailure);
@@ -318,6 +328,7 @@ private String lookupForOverrides(String expr) {
return expr;
}
+ @Override
public Object findValue(String expr) {
return findValue(expr, false);
}
@@ -325,6 +336,7 @@ public Object findValue(String expr) {
/**
* @see com.opensymphony.xwork2.util.ValueStack#findValue(java.lang.String, java.lang.Class)
*/
+ @Override
public Object findValue(String expr, Class asType, boolean throwExceptionOnFailure) {
try {
setupExceptionOnFailure(throwExceptionOnFailure);
@@ -394,6 +406,7 @@ protected Object findInContext(String name) {
return getContext().get(name);
}
+ @Override
public Object findValue(String expr, Class asType) {
return findValue(expr, asType, false);
}
@@ -416,6 +429,7 @@ private void logLookupFailure(String expr, Exception e) {
/**
* @see com.opensymphony.xwork2.util.ValueStack#peek()
*/
+ @Override
public Object peek() {
return root.peek();
}
@@ -423,6 +437,7 @@ public Object peek() {
/**
* @see com.opensymphony.xwork2.util.ValueStack#pop()
*/
+ @Override
public Object pop() {
return root.pop();
}
@@ -430,6 +445,7 @@ public Object pop() {
/**
* @see com.opensymphony.xwork2.util.ValueStack#push(java.lang.Object)
*/
+ @Override
public void push(Object o) {
root.push(o);
}
@@ -437,6 +453,7 @@ public void push(Object o) {
/**
* @see com.opensymphony.xwork2.util.ValueStack#set(java.lang.String, java.lang.Object)
*/
+ @Override
public void set(String key, Object o) {
//set basically is backed by a Map pushed on the stack with a key being put on the map and the Object being the value
Map setMap = retrieveSetMap();
@@ -466,6 +483,7 @@ private boolean shouldUseOldMap(Object topObj) {
/**
* @see com.opensymphony.xwork2.util.ValueStack#size()
*/
+ @Override
public int size() {
return root.size();
}
@@ -487,16 +505,19 @@ private Object readResolve() {
return aStack;
}
+ @Override
public void clearContextValues() {
//this is an OGNL ValueStack so the context will be an OgnlContext
//it would be better to make context of type OgnlContext
((OgnlContext) context).getValues().clear();
}
+ @Override
public void useAcceptProperties(Set acceptedProperties) {
securityMemberAccess.useAcceptProperties(acceptedProperties);
}
+ @Override
public void useExcludeProperties(Set excludeProperties) {
securityMemberAccess.useExcludeProperties(excludeProperties);
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/XWorkTypeConverterWrapper.java b/core/src/main/java/com/opensymphony/xwork2/ognl/XWorkTypeConverterWrapper.java
index 18a2c8e44d..e3abca8013 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/XWorkTypeConverterWrapper.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/XWorkTypeConverterWrapper.java
@@ -29,13 +29,13 @@
public class XWorkTypeConverterWrapper implements TypeConverter {
private final ognl.TypeConverter typeConverter;
-
+
public XWorkTypeConverterWrapper(ognl.TypeConverter conv) {
this.typeConverter = conv;
}
-
- public Object convertValue(Map context, Object target, Member member,
- String propertyName, Object value, Class toType) {
+
+ @Override
+ public Object convertValue(Map context, Object target, Member member, String propertyName, Object value, Class toType) {
return typeConverter.convertValue(context, target, member, propertyName, value, toType);
}
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/CompoundRootAccessor.java b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/CompoundRootAccessor.java
index 1157c1989a..2f9333069c 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/CompoundRootAccessor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/CompoundRootAccessor.java
@@ -147,8 +147,7 @@ public Object getProperty(Map context, Object target, Object name) throws OgnlEx
CompoundRoot root = (CompoundRoot) target;
OgnlContext ognlContext = (OgnlContext) context;
- if (name instanceof Integer) {
- Integer index = (Integer) name;
+ if (name instanceof Integer index) {
return root.cutStack(index);
} else if (name instanceof String) {
if ("top".equals(name)) {
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/ObjectProxyPropertyAccessor.java b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/ObjectProxyPropertyAccessor.java
index 8400bab4f1..5f5ccb7994 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/ObjectProxyPropertyAccessor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/ObjectProxyPropertyAccessor.java
@@ -20,10 +20,10 @@
import com.opensymphony.xwork2.ognl.ObjectProxy;
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
+import ognl.OgnlContext;
import ognl.OgnlException;
import ognl.OgnlRuntime;
import ognl.PropertyAccessor;
-import ognl.OgnlContext;
import java.util.Map;
@@ -40,6 +40,7 @@ public class ObjectProxyPropertyAccessor implements PropertyAccessor {
/**
* Used by OGNl to generate bytecode
*/
+ @Override
public String getSourceAccessor(OgnlContext context, Object target, Object index) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@@ -47,10 +48,12 @@ public String getSourceAccessor(OgnlContext context, Object target, Object index
/**
* Used by OGNl to generate bytecode
*/
+ @Override
public String getSourceSetter(OgnlContext context, Object target, Object index) {
- return null;
+ return null;
}
+ @Override
public Object getProperty(Map context, Object target, Object name) throws OgnlException {
ObjectProxy proxy = (ObjectProxy) target;
setupContext(context, proxy);
@@ -59,6 +62,7 @@ public Object getProperty(Map context, Object target, Object name) throws OgnlEx
}
+ @Override
public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
ObjectProxy proxy = (ObjectProxy) target;
setupContext(context, proxy);
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkCollectionPropertyAccessor.java b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkCollectionPropertyAccessor.java
index 837558f59c..2d3581e143 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkCollectionPropertyAccessor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkCollectionPropertyAccessor.java
@@ -49,27 +49,27 @@ public class XWorkCollectionPropertyAccessor extends SetPropertyAccessor {
//to access properties of the objects in the Set
//so that nothing is put in the context to screw things up
private final ObjectPropertyAccessor _accessor = new ObjectPropertyAccessor();
-
+
private XWorkConverter xworkConverter;
private ObjectFactory objectFactory;
private ObjectTypeDeterminer objectTypeDeterminer;
private OgnlUtil ognlUtil;
-
+
@Inject
public void setXWorkConverter(XWorkConverter conv) {
this.xworkConverter = conv;
}
-
+
@Inject
public void setObjectFactory(ObjectFactory fac) {
this.objectFactory = fac;
}
-
+
@Inject
public void setObjectTypeDeterminer(ObjectTypeDeterminer ot) {
this.objectTypeDeterminer = ot;
}
-
+
@Inject
public void setOgnlUtil(OgnlUtil util) {
this.ognlUtil = util;
@@ -145,26 +145,26 @@ public Object getProperty(Map context, Object target, Object key) throws OgnlExc
&& ReflectionContextState.isCreatingNullObjects(context)
&& objectTypeDeterminer
.shouldCreateIfNew(lastBeanClass,lastPropertyClass,c,keyProperty,false)) {
- //create a new element and
+ //create a new element and
//set the value of keyProperty
//to be the given value
try {
value=objectFactory.buildBean(collClass, context);
-
+
//set the value of the keyProperty
_accessor.setProperty(context,value,keyProperty,realKey);
-
- //add the new object to the collection
+
+ //add the new object to the collection
c.add(value);
-
+
//add to the Map if accessed later
collMap.put(realKey, value);
-
-
+
+
} catch (Exception exc) {
throw new OgnlException("Error adding new element to collection", exc);
}
-
+
}
return value;
} else {
@@ -260,7 +260,7 @@ private Object getRealValue(Map context, Object value, Class convertToClass) {
return value;
}
return xworkConverter.convertValue(context, value, convertToClass);
- }
+ }
}
/**
@@ -268,7 +268,7 @@ private Object getRealValue(Map context, Object value, Class convertToClass) {
*/
class SurrugateList extends ArrayList {
- private Collection surrugate;
+ private final Collection surrugate;
public SurrugateList(Collection surrugate) {
this.surrugate = surrugate;
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java
index 47a6404381..9bc0df14a3 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java
@@ -44,7 +44,7 @@
public class XWorkListPropertyAccessor extends ListPropertyAccessor {
private XWorkCollectionPropertyAccessor _sAcc = new XWorkCollectionPropertyAccessor();
-
+
private XWorkConverter xworkConverter;
private ObjectFactory objectFactory;
private ObjectTypeDeterminer objectTypeDeterminer;
@@ -60,22 +60,22 @@ public void setAutoGrowCollectionLimit(String value) {
public void setXWorkCollectionPropertyAccessor(PropertyAccessor acc) {
this._sAcc = (XWorkCollectionPropertyAccessor) acc;
}
-
+
@Inject
public void setXWorkConverter(XWorkConverter conv) {
this.xworkConverter = conv;
}
-
+
@Inject
public void setObjectFactory(ObjectFactory fac) {
this.objectFactory = fac;
}
-
+
@Inject
public void setObjectTypeDeterminer(ObjectTypeDeterminer ot) {
this.objectTypeDeterminer = ot;
}
-
+
@Inject
public void setOgnlUtil(OgnlUtil util) {
this.ognlUtil = util;
@@ -93,7 +93,7 @@ public Object getProperty(Map context, Object target, Object name) throws OgnlEx
ReflectionContextState.updateCurrentPropertyPath(context, name);
Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
-
+
if (name instanceof Number
&& ReflectionContextState.isCreatingNullObjects(context)
&& objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,true)) {
@@ -168,9 +168,8 @@ public void setProperty(Map context, Object target, Object name, Object value)
Object realValue = getRealValue(context, value, convertToClass);
- if (target instanceof List && name instanceof Number) {
+ if (target instanceof List list && name instanceof Number) {
//make sure there are enough spaces in the List to set
- List list = (List) target;
int listSize = list.size();
int count = ((Number) name).intValue();
if(count > autoGrowCollectionLimit)
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessor.java b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessor.java
index bad7932cee..db8ec65491 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessor.java
@@ -41,21 +41,21 @@ public class XWorkMapPropertyAccessor extends MapPropertyAccessor {
private static final Logger LOG = LogManager.getLogger(XWorkMapPropertyAccessor.class);
private static final String[] INDEX_ACCESS_PROPS = new String[]{"size", "isEmpty", "keys", "values"};
-
+
private XWorkConverter xworkConverter;
private ObjectFactory objectFactory;
private ObjectTypeDeterminer objectTypeDeterminer;
-
+
@Inject
public void setXWorkConverter(XWorkConverter conv) {
this.xworkConverter = conv;
}
-
+
@Inject
public void setObjectFactory(ObjectFactory fac) {
this.objectFactory = fac;
}
-
+
@Inject
public void setObjectTypeDeterminer(ObjectTypeDeterminer ot) {
this.objectTypeDeterminer = ot;
@@ -77,7 +77,7 @@ public Object getProperty(Map context, Object target, Object name) throws OgnlEx
try{
result = super.getProperty(context, target, name);
- } catch (ClassCastException ex) {
+ } catch (ClassCastException ignored) {
}
if (result == null) {
@@ -100,7 +100,7 @@ public Object getProperty(Map context, Object target, Object name) throws OgnlEx
try {
result = objectFactory.buildBean(valueClass, context);
map.put(key, result);
- } catch (Exception exc) {
+ } catch (Exception ignored) {
}
}
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMethodAccessor.java b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMethodAccessor.java
index 180e787f1b..f6e51d4fc1 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMethodAccessor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMethodAccessor.java
@@ -19,7 +19,11 @@
package com.opensymphony.xwork2.ognl.accessor;
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
-import ognl.*;
+import ognl.MethodFailedException;
+import ognl.ObjectMethodAccessor;
+import ognl.OgnlContext;
+import ognl.OgnlRuntime;
+import ognl.PropertyAccessor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -78,13 +82,12 @@ public Object callMethod(Map context, Object object, String string, Object[] obj
//HACK - we pass indexed method access i.e. setXXX(A,B) pattern
if ((objects.length == 2 && string.startsWith("set")) || (objects.length == 1 && string.startsWith("get"))) {
Boolean exec = (Boolean) context.get(ReflectionContextState.DENY_INDEXED_ACCESS_EXECUTION);
- boolean e = ((exec == null) ? false : exec.booleanValue());
+ boolean e = exec != null && exec;
if (!e) {
return callMethodWithDebugInfo(context, object, string, objects);
}
}
- Boolean exec = ReflectionContextState.isDenyMethodExecution(context);
- boolean e = (exec != null && exec);
+ boolean e = ReflectionContextState.isDenyMethodExecution(context);
if (!e) {
return callMethodWithDebugInfo(context, object, string, objects);
@@ -101,7 +104,7 @@ private Object callMethodWithDebugInfo(Map context, Object object, String method
if (LOG.isDebugEnabled()) {
if (!(e.getReason() instanceof NoSuchMethodException)) {
// the method exists on the target object, but something went wrong
- LOG.debug("Error calling method through OGNL: object: [{}] method: [{}] args: [{}]", e.getReason(), object.toString(), methodName, Arrays.toString(objects));
+ LOG.debug("Error calling method through OGNL: object: [{}] method: [{}] args: [{}] - {}", object.toString(), methodName, Arrays.toString(objects), e.getReason());
}
}
throw e;
@@ -110,8 +113,7 @@ private Object callMethodWithDebugInfo(Map context, Object object, String method
@Override
public Object callStaticMethod(Map context, Class aClass, String string, Object[] objects) throws MethodFailedException {
- Boolean exec = ReflectionContextState.isDenyMethodExecution(context);
- boolean e = ((exec == null) ? false : exec.booleanValue());
+ boolean e = ReflectionContextState.isDenyMethodExecution(context);
if (!e) {
return callStaticMethodWithDebugInfo(context, aClass, string, objects);
@@ -129,7 +131,7 @@ private Object callStaticMethodWithDebugInfo(Map context, Class aClass, String m
if (LOG.isDebugEnabled()) {
if (!(e.getReason() instanceof NoSuchMethodException)) {
// the method exists on the target class, but something went wrong
- LOG.debug("Error calling method through OGNL, class: [{}] method: [{}] args: [{}]", e.getReason(), aClass.getName(), methodName, Arrays.toString(objects));
+ LOG.debug("Error calling method through OGNL, class: [{}] method: [{}] args: [{}] - {}", aClass.getName(), methodName, Arrays.toString(objects), e.getReason());
}
}
throw e;
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkObjectPropertyAccessor.java b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkObjectPropertyAccessor.java
index 2fb7e61655..e719b1e4e6 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkObjectPropertyAccessor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkObjectPropertyAccessor.java
@@ -30,8 +30,7 @@
*/
public class XWorkObjectPropertyAccessor extends ObjectPropertyAccessor {
@Override
- public Object getProperty(Map context, Object target, Object oname)
- throws OgnlException {
+ public Object getProperty(Map context, Object target, Object oname) throws OgnlException {
//set the last set objects in the context
//so if the next objects accessed are
//Maps or Collections they can use the information
diff --git a/core/src/main/java/com/opensymphony/xwork2/security/DefaultAcceptedPatternsChecker.java b/core/src/main/java/com/opensymphony/xwork2/security/DefaultAcceptedPatternsChecker.java
index be803b7e84..82cc4af877 100644
--- a/core/src/main/java/com/opensymphony/xwork2/security/DefaultAcceptedPatternsChecker.java
+++ b/core/src/main/java/com/opensymphony/xwork2/security/DefaultAcceptedPatternsChecker.java
@@ -44,7 +44,7 @@ public class DefaultAcceptedPatternsChecker implements AcceptedPatternsChecker {
/**
* Must match {@link #ACCEPTED_PATTERNS} RegEx. Signifies characters which result in a nested lookup via OGNL.
*/
- public static final Set NESTING_CHARS = unmodifiableSet(new HashSet<>(asList('.', '[', '(')));
+ public static final Set NESTING_CHARS = Set.of('.', '[', '(');
public static final String NESTING_CHARS_STR = NESTING_CHARS.stream().map(String::valueOf).collect(joining());
public static final String[] DMI_AWARE_ACCEPTED_PATTERNS = {
diff --git a/core/src/main/java/com/opensymphony/xwork2/test/StubConfigurationProvider.java b/core/src/main/java/com/opensymphony/xwork2/test/StubConfigurationProvider.java
index f05bd1e6b9..73ef890dbe 100644
--- a/core/src/main/java/com/opensymphony/xwork2/test/StubConfigurationProvider.java
+++ b/core/src/main/java/com/opensymphony/xwork2/test/StubConfigurationProvider.java
@@ -26,25 +26,30 @@
public class StubConfigurationProvider implements ConfigurationProvider {
+ @Override
public void destroy() {
// TODO Auto-generated method stub
}
+ @Override
public void init(Configuration configuration) throws ConfigurationException {
// TODO Auto-generated method stub
}
+ @Override
public void loadPackages() throws ConfigurationException {
// TODO Auto-generated method stub
}
+ @Override
public boolean needsReload() {
// TODO Auto-generated method stub
return false;
}
+ @Override
public void register(ContainerBuilder builder, LocatableProperties props)
throws ConfigurationException {
// TODO Auto-generated method stub
diff --git a/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java b/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java
index 87f65b216d..9eb978a049 100644
--- a/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java
+++ b/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java
@@ -24,7 +24,6 @@
import org.apache.commons.lang3.ObjectUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.struts2.StrutsConstants;
import java.lang.reflect.Field;
@@ -35,6 +34,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
+import java.util.Objects;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.StringTokenizer;
@@ -77,11 +77,7 @@ public void addDefaultResourceBundle(String resourceBundleName) {
//make sure this doesn't get added more than once
final ClassLoader ccl = getCurrentThreadContextClassLoader();
synchronized (XWORK_MESSAGES_BUNDLE) {
- List bundles = classLoaderMap.get(ccl.hashCode());
- if (bundles == null) {
- bundles = new CopyOnWriteArrayList<>();
- classLoaderMap.put(ccl.hashCode(), bundles);
- }
+ List bundles = classLoaderMap.computeIfAbsent(ccl.hashCode(), k -> new CopyOnWriteArrayList<>());
bundles.remove(resourceBundleName);
bundles.add(0, resourceBundleName);
}
@@ -101,17 +97,17 @@ protected ClassLoader getCurrentThreadContextClassLoader() {
@Inject(value = StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES, required = false)
public void setCustomI18NResources(String bundles) {
- if (bundles != null && bundles.length() > 0) {
- StringTokenizer customBundles = new StringTokenizer(bundles, ", ");
-
- while (customBundles.hasMoreTokens()) {
- String name = customBundles.nextToken();
- try {
- LOG.trace("Loading global messages from [{}]", name);
- addDefaultResourceBundle(name);
- } catch (Exception e) {
- LOG.error(new ParameterizedMessage("Could not find messages file {}.properties. Skipping", name), e);
- }
+ if (bundles == null || bundles.isEmpty()) {
+ return;
+ }
+ StringTokenizer customBundles = new StringTokenizer(bundles, ", ");
+ while (customBundles.hasMoreTokens()) {
+ String name = customBundles.nextToken();
+ try {
+ LOG.trace("Loading global messages from [{}]", name);
+ addDefaultResourceBundle(name);
+ } catch (Exception e) {
+ LOG.error("Could not find messages file {}.properties. Skipping", name, e);
}
}
}
@@ -238,7 +234,7 @@ public void setDelegatedClassLoader(final ClassLoader classLoader) {
protected void clearBundle(final String bundleName, Locale locale) {
final String key = createMissesKey(String.valueOf(getCurrentThreadContextClassLoader().hashCode()), bundleName, locale);
final ResourceBundle removedBundle = bundlesMap.remove(key);
- LOG.debug("Clearing resource bundle [{}], locale [{}], result: [{}].", bundleName, locale, Boolean.valueOf(removedBundle != null));
+ LOG.debug("Clearing resource bundle [{}], locale [{}], result: [{}].", bundleName, locale, removedBundle != null);
}
/**
@@ -676,8 +672,8 @@ public boolean equals(Object o) {
MessageFormatKey that = (MessageFormatKey) o;
- if (pattern != null ? !pattern.equals(that.pattern) : that.pattern != null) return false;
- return locale != null ? locale.equals(that.locale) : that.locale == null;
+ if (!Objects.equals(pattern, that.pattern)) return false;
+ return Objects.equals(locale, that.locale);
}
@Override
diff --git a/core/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java b/core/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java
index acac0b1447..b1d132fa68 100644
--- a/core/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java
+++ b/core/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java
@@ -21,7 +21,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.*;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.NoSuchElementException;
+import java.util.Set;
/**
@@ -39,7 +44,7 @@ public class ClassLoaderUtil {
/**
*
- * Load all resources with a given name, potentially aggregating all results
+ * Load all resources with a given name, potentially aggregating all results
* from the searched classloaders. If no results are found, the resource name
* is prepended by '/' and tried again.
*
@@ -80,7 +85,7 @@ public static Iterator getResources(String resourceName, Class callingClass
}
}
- if (!iterator.hasNext() && (resourceName != null) && ((resourceName.length() == 0) || (resourceName.charAt(0) != '/'))) {
+ if (!iterator.hasNext() && (resourceName != null) && ((resourceName.isEmpty()) || (resourceName.charAt(0) != '/'))) {
return getResources('/' + resourceName, callingClass, aggregate);
}
@@ -119,7 +124,7 @@ public static URL getResource(String resourceName, Class callingClass) {
}
}
- if ((url == null) && (resourceName != null) && ((resourceName.length() == 0) || (resourceName.charAt(0) != '/'))) {
+ if ((url == null) && (resourceName != null) && ((resourceName.isEmpty()) || (resourceName.charAt(0) != '/'))) {
return getResource('/' + resourceName, callingClass);
}
@@ -214,7 +219,7 @@ static class AggregateIterator implements Iterator {
LinkedList> enums = new LinkedList<>();
Enumeration cur = null;
E next = null;
- Set loaded = new HashSet();
+ Set