You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2024/09/26 15:33:46 UTC
(tomcat) 03/04: Complete fix for BZ 69338. Optimise "not empty"
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit d7615a5c1041c738afc91af6feab46a98fa3f929
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Sep 26 16:33:02 2024 +0100
Complete fix for BZ 69338. Optimise "not empty"
---
.../{AstEmpty.java => AstAbstractEmpty.java} | 35 ++++++++++----------
java/org/apache/el/parser/AstEmpty.java | 37 ++--------------------
java/org/apache/el/parser/AstNotEmpty.java | 24 ++++++++++++++
java/org/apache/el/parser/ELParser.jjt | 3 ++
4 files changed, 48 insertions(+), 51 deletions(-)
diff --git a/java/org/apache/el/parser/AstEmpty.java b/java/org/apache/el/parser/AstAbstractEmpty.java
similarity index 62%
copy from java/org/apache/el/parser/AstEmpty.java
copy to java/org/apache/el/parser/AstAbstractEmpty.java
index 0fc73218ed..58577fe267 100644
--- a/java/org/apache/el/parser/AstEmpty.java
+++ b/java/org/apache/el/parser/AstAbstractEmpty.java
@@ -24,13 +24,21 @@ import jakarta.el.ELException;
import org.apache.el.lang.EvaluationContext;
+public abstract class AstAbstractEmpty extends SimpleNode {
-/**
- * @author Jacob Hookom [jacob@hookom.net]
- */
-public final class AstEmpty extends SimpleNode {
- public AstEmpty(int id) {
+ private final Boolean RETURN_EMPTY;
+ private final Boolean RETURN_NOT_EMPTY;
+
+
+ public AstAbstractEmpty(int id, boolean invert) {
super(id);
+ if (invert) {
+ RETURN_EMPTY = Boolean.FALSE;
+ RETURN_NOT_EMPTY = Boolean.TRUE;
+ } else {
+ RETURN_EMPTY = Boolean.TRUE;
+ RETURN_NOT_EMPTY = Boolean.FALSE;
+ }
}
@Override
@@ -41,17 +49,12 @@ public final class AstEmpty extends SimpleNode {
@Override
public Object getValue(EvaluationContext ctx) throws ELException {
Object obj = this.children[0].getValue(ctx);
- if (obj == null) {
- return Boolean.TRUE;
- } else if (obj instanceof String) {
- return Boolean.valueOf(((String) obj).length() == 0);
- } else if (obj instanceof Object[]) {
- return Boolean.valueOf(((Object[]) obj).length == 0);
- } else if (obj instanceof Collection<?>) {
- return Boolean.valueOf(((Collection<?>) obj).isEmpty());
- } else if (obj instanceof Map<?,?>) {
- return Boolean.valueOf(((Map<?,?>) obj).isEmpty());
+ if (obj == null || obj instanceof String && ((String) obj).length() == 0 ||
+ obj instanceof Object[] && ((Object[]) obj).length == 0 ||
+ obj instanceof Collection<?> && ((Collection<?>) obj).isEmpty() ||
+ obj instanceof Map<?,?> && ((Map<?,?>) obj).isEmpty()) {
+ return RETURN_EMPTY;
}
- return Boolean.FALSE;
+ return RETURN_NOT_EMPTY;
}
}
diff --git a/java/org/apache/el/parser/AstEmpty.java b/java/org/apache/el/parser/AstEmpty.java
index 0fc73218ed..0517091b9c 100644
--- a/java/org/apache/el/parser/AstEmpty.java
+++ b/java/org/apache/el/parser/AstEmpty.java
@@ -17,41 +17,8 @@
/* Generated By:JJTree: Do not edit this line. AstEmpty.java */
package org.apache.el.parser;
-import java.util.Collection;
-import java.util.Map;
-
-import jakarta.el.ELException;
-
-import org.apache.el.lang.EvaluationContext;
-
-
-/**
- * @author Jacob Hookom [jacob@hookom.net]
- */
-public final class AstEmpty extends SimpleNode {
+public final class AstEmpty extends AstAbstractEmpty {
public AstEmpty(int id) {
- super(id);
- }
-
- @Override
- public Class<?> getType(EvaluationContext ctx) throws ELException {
- return Boolean.class;
- }
-
- @Override
- public Object getValue(EvaluationContext ctx) throws ELException {
- Object obj = this.children[0].getValue(ctx);
- if (obj == null) {
- return Boolean.TRUE;
- } else if (obj instanceof String) {
- return Boolean.valueOf(((String) obj).length() == 0);
- } else if (obj instanceof Object[]) {
- return Boolean.valueOf(((Object[]) obj).length == 0);
- } else if (obj instanceof Collection<?>) {
- return Boolean.valueOf(((Collection<?>) obj).isEmpty());
- } else if (obj instanceof Map<?,?>) {
- return Boolean.valueOf(((Map<?,?>) obj).isEmpty());
- }
- return Boolean.FALSE;
+ super(id, false);
}
}
diff --git a/java/org/apache/el/parser/AstNotEmpty.java b/java/org/apache/el/parser/AstNotEmpty.java
new file mode 100644
index 0000000000..0066c07afb
--- /dev/null
+++ b/java/org/apache/el/parser/AstNotEmpty.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/* Generated By:JJTree: Do not edit this line. AstEmpty.java */
+package org.apache.el.parser;
+
+public final class AstNotEmpty extends AstAbstractEmpty {
+ public AstNotEmpty(int id) {
+ super(id, true);
+ }
+}
diff --git a/java/org/apache/el/parser/ELParser.jjt b/java/org/apache/el/parser/ELParser.jjt
index 379de3058b..1a9cc31dd6 100644
--- a/java/org/apache/el/parser/ELParser.jjt
+++ b/java/org/apache/el/parser/ELParser.jjt
@@ -261,6 +261,9 @@ void Multiplication() : {}
void Unary() : {}
{
<MINUS> Unary() #Negative
+ |
+ LOOKAHEAD(2)
+ (<NOT0>|<NOT1>) <EMPTY> Unary() #NotEmpty
|
(<NOT0>|<NOT1>) Unary() #Not
|
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org