You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by ku...@apache.org on 2024/08/13 08:30:54 UTC
(struts) 01/01: WW-4062 Further optimisation of OgnlException caching
This is an automated email from the ASF dual-hosted git repository.
kusal pushed a commit to branch WW-4062-ognl-exc-cache
in repository https://gitbox.apache.org/repos/asf/struts.git
commit 04905ce8a22c54e5c1e830a374e0e0435e1d7be0
Author: Kusal Kithul-Godage <gi...@kusal.io>
AuthorDate: Tue Aug 13 18:29:04 2024 +1000
WW-4062 Further optimisation of OgnlException caching
---
core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java | 7 +++----
core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java | 7 ++++---
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java
index 05d0be6c5..b94253478 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java
@@ -602,10 +602,9 @@ public class OgnlUtil {
tree = expressionCache.get(expr);
}
if (tree instanceof OgnlException) {
- // OgnlException was cached, rethrow it with updated stack trace
- OgnlException e = (OgnlException) tree;
- e.getCause().fillInStackTrace();
- throw e;
+ // OgnlException was cached, rethrow it with empty stack trace (refilling the stack trace is expensive)
+ ((OgnlException) tree).getCause().setStackTrace(new StackTraceElement[0]);
+ throw (OgnlException) tree;
}
if (tree == null) {
try {
diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java
index b7ba175f7..40c2dbddf 100644
--- a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java
@@ -1650,14 +1650,15 @@ public class OgnlUtilTest extends XWorkTestCase {
StackTraceElement[] stackTrace = e.getStackTrace();
assertThat(stackTrace).isEmpty();
StackTraceElement[] causeStackTrace = e.getCause().getStackTrace();
+ assertThat(causeStackTrace).isNotEmpty();
OgnlException e2 = assertThrows(OgnlException.class, () -> ognlUtil.compile(".literal.$something"));
- StackTraceElement[] stackTrace2 = e.getStackTrace();
+ StackTraceElement[] stackTrace2 = e2.getStackTrace();
assertThat(stackTrace2).isEmpty();
- StackTraceElement[] causeStackTrace2 = e.getCause().getStackTrace();
+ StackTraceElement[] causeStackTrace2 = e2.getCause().getStackTrace();
+ assertThat(causeStackTrace2).isEmpty(); // Stack trace cleared before rethrow
assertSame(e, e2); // Exception is cached
- assertThat(causeStackTrace).isNotEqualTo(causeStackTrace2); // Stack trace refreshed
}
/**