You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by di...@apache.org on 2020/04/29 03:05:05 UTC
[rocketmq] branch develop updated: [ISSUE #1906] The
BooleanConstantExpression might lead to class loading deadlock
This is an automated email from the ASF dual-hosted git repository.
dinglei pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new bc692b4 [ISSUE #1906] The BooleanConstantExpression might lead to class loading deadlock
bc692b4 is described below
commit bc692b408d9725bf81dbe59c9aae4b4f2b304572
Author: bruce <84...@qq.com>
AuthorDate: Wed Apr 29 11:04:56 2020 +0800
[ISSUE #1906] The BooleanConstantExpression might lead to class loading deadlock
[ISSUE #1906] The BooleanConstantExpression might lead to class loading deadlock
---
.../expression/BooleanConstantExpression.java | 37 ++++++++++++++++++++
.../filter/expression/ComparisonExpression.java | 4 +--
.../filter/expression/ConstantExpression.java | 39 ++++++----------------
.../rocketmq/filter/parser/SelectorParser.java | 7 ++--
4 files changed, 53 insertions(+), 34 deletions(-)
diff --git a/filter/src/main/java/org/apache/rocketmq/filter/expression/BooleanConstantExpression.java b/filter/src/main/java/org/apache/rocketmq/filter/expression/BooleanConstantExpression.java
new file mode 100644
index 0000000..958e622
--- /dev/null
+++ b/filter/src/main/java/org/apache/rocketmq/filter/expression/BooleanConstantExpression.java
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+package org.apache.rocketmq.filter.expression;
+
+/**
+ * BooleanConstantExpression
+ */
+public class BooleanConstantExpression extends ConstantExpression implements BooleanExpression {
+
+ public static final BooleanConstantExpression NULL = new BooleanConstantExpression(null);
+ public static final BooleanConstantExpression TRUE = new BooleanConstantExpression(Boolean.TRUE);
+ public static final BooleanConstantExpression FALSE = new BooleanConstantExpression(Boolean.FALSE);
+
+ public BooleanConstantExpression(Object value) {
+ super(value);
+ }
+
+ public boolean matches(EvaluationContext context) throws Exception {
+ Object object = evaluate(context);
+ return object != null && object == Boolean.TRUE;
+ }
+}
diff --git a/filter/src/main/java/org/apache/rocketmq/filter/expression/ComparisonExpression.java b/filter/src/main/java/org/apache/rocketmq/filter/expression/ComparisonExpression.java
index fe898e7..9a919c4 100644
--- a/filter/src/main/java/org/apache/rocketmq/filter/expression/ComparisonExpression.java
+++ b/filter/src/main/java/org/apache/rocketmq/filter/expression/ComparisonExpression.java
@@ -90,11 +90,11 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
}
public static BooleanExpression createIsNull(Expression left) {
- return doCreateEqual(left, ConstantExpression.NULL);
+ return doCreateEqual(left, BooleanConstantExpression.NULL);
}
public static BooleanExpression createIsNotNull(Expression left) {
- return UnaryExpression.createNOT(doCreateEqual(left, ConstantExpression.NULL));
+ return UnaryExpression.createNOT(doCreateEqual(left, BooleanConstantExpression.NULL));
}
public static BooleanExpression createNotEqual(Expression left, Expression right) {
diff --git a/filter/src/main/java/org/apache/rocketmq/filter/expression/ConstantExpression.java b/filter/src/main/java/org/apache/rocketmq/filter/expression/ConstantExpression.java
index e649f5a..127bd8b 100644
--- a/filter/src/main/java/org/apache/rocketmq/filter/expression/ConstantExpression.java
+++ b/filter/src/main/java/org/apache/rocketmq/filter/expression/ConstantExpression.java
@@ -30,21 +30,6 @@ package org.apache.rocketmq.filter.expression;
*/
public class ConstantExpression implements Expression {
- static class BooleanConstantExpression extends ConstantExpression implements BooleanExpression {
- public BooleanConstantExpression(Object value) {
- super(value);
- }
-
- public boolean matches(EvaluationContext context) throws Exception {
- Object object = evaluate(context);
- return object != null && object == Boolean.TRUE;
- }
- }
-
- public static final BooleanConstantExpression NULL = new BooleanConstantExpression(null);
- public static final BooleanConstantExpression TRUE = new BooleanConstantExpression(Boolean.TRUE);
- public static final BooleanConstantExpression FALSE = new BooleanConstantExpression(Boolean.FALSE);
-
private Object value;
public ConstantExpression(Object value) {
@@ -60,16 +45,10 @@ public class ConstantExpression implements Expression {
// only support Long.MIN_VALUE ~ Long.MAX_VALUE
Number value = new Long(text);
-// try {
-// value = new Long(text);
-// } catch (NumberFormatException e) {
-// // The number may be too big to fit in a long.
-// value = new BigDecimal(text);
-// }
long l = value.longValue();
if (Integer.MIN_VALUE <= l && l <= Integer.MAX_VALUE) {
- value = Integer.valueOf(value.intValue());
+ value = value.intValue();
}
return new ConstantExpression(value);
}
@@ -106,7 +85,7 @@ public class ConstantExpression implements Expression {
return "NULL";
}
if (value instanceof Boolean) {
- return ((Boolean) value).booleanValue() ? "TRUE" : "FALSE";
+ return (Boolean) value ? "TRUE" : "FALSE";
}
if (value instanceof String) {
return encodeString((String) value);
@@ -138,17 +117,19 @@ public class ConstantExpression implements Expression {
* it was provided in a selector.
*/
public static String encodeString(String s) {
- StringBuffer b = new StringBuffer();
- b.append('\'');
+
+ StringBuilder builder = new StringBuilder();
+
+ builder.append('\'');
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '\'') {
- b.append(c);
+ builder.append(c);
}
- b.append(c);
+ builder.append(c);
}
- b.append('\'');
- return b.toString();
+ builder.append('\'');
+ return builder.toString();
}
}
diff --git a/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParser.java b/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParser.java
index 198aacf..4ea7dcf 100644
--- a/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParser.java
+++ b/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParser.java
@@ -20,6 +20,7 @@ package org.apache.rocketmq.filter.parser;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
+import org.apache.rocketmq.filter.expression.BooleanConstantExpression;
import org.apache.rocketmq.filter.expression.BooleanExpression;
import org.apache.rocketmq.filter.expression.ComparisonExpression;
import org.apache.rocketmq.filter.expression.ConstantExpression;
@@ -437,15 +438,15 @@ public class SelectorParser implements SelectorParserConstants {
break;
case TRUE:
jj_consume_token(TRUE);
- left = ConstantExpression.TRUE;
+ left = BooleanConstantExpression.TRUE;
break;
case FALSE:
jj_consume_token(FALSE);
- left = ConstantExpression.FALSE;
+ left = BooleanConstantExpression.FALSE;
break;
case NULL:
jj_consume_token(NULL);
- left = ConstantExpression.NULL;
+ left = BooleanConstantExpression.NULL;
break;
default:
jjLa1[12] = jjGen;