diff --git a/README.md b/README.md
index a2615b245..ff5f53f40 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ QLExpress脚本引擎被广泛应用在阿里的电商业务场景,具有以
com.alibaba
QLExpress
- 3.3.0
+ 3.3.1
```
@@ -371,7 +371,7 @@ private boolean isTrace = false;
* @return
* @throws Exception
*/
-Object execute(String expressString, IExpressContext context, List errorList, boolean isCache, boolean isTrace, Log aLog);
+Object execute(String expressString, IExpressContext context, List errorList, boolean isCache, boolean isTrace);
```
## 3、功能扩展API列表
@@ -809,11 +809,31 @@ assertEquals("t", expressRunner.execute("test.a", context,
null, false, true));
```
+在沙箱模式下,为了进一步保障内存的安全,建议同时限制脚本能够申请的最大数组长度以及超时时间,设置方法如下:
+
+`com.ql.util.express.test.ArrayLenCheckTest`
+
+```java
+// 限制最大申请数组长度为10, 默认没有限制
+QLExpressRunStrategy.setMaxArrLength(10);
+ExpressRunner runner = new ExpressRunner();
+String code = "byte[] a = new byte[11];";
+try {
+ // 20ms 超时时间
+ runner.execute(code, new DefaultContext<>(), null, false, false, 20);
+ Assert.fail();
+} catch (QLException e) {
+}
+
+QLExpressRunStrategy.setMaxArrLength(-1);
+// 20ms 超时时间
+runner.execute(code, new DefaultContext<>(), null, false, false, 20);
+```
+
附录:
[版本更新列表](VERSIONS.md)
## links for us
- Gitter channel - Online chat room with QLExpress developers. [Gitter channel ](https://gitter.im/QLExpress/Lobby)
- email:tianqiao@alibaba-inc.com,baoxingjie@126.com
-- wechart:371754252
-- QLExpress blogs: https://yq.aliyun.com/album/130
\ No newline at end of file
+- wechart:371754252
\ No newline at end of file
diff --git a/VERSIONS.md b/VERSIONS.md
index 09f18804b..5cc5096aa 100644
--- a/VERSIONS.md
+++ b/VERSIONS.md
@@ -143,4 +143,13 @@ public Object execute(InstructionSet[] instructionSets,IExpressContextcom.alibaba
QLExpress
jar
- 3.3.1-SNAPSHOT
+ 3.3.1
QLExpress
QLExpress is a powerful, lightweight, dynamic language for the Java platform aimed at improving developers’ productivity in different business scenes.
@@ -66,17 +66,6 @@
commons-beanutils
1.8.2
-
- log4j
- log4j
- 1.2.16
- provided
-
-
- commons-logging
- commons-logging
- 1.1.1
-
commons-lang
commons-lang
diff --git a/src/main/java/com/ql/util/express/ExpressRemoteCacheRunner.java b/src/main/java/com/ql/util/express/ExpressRemoteCacheRunner.java
index 0ffeeea1b..4212569f2 100644
--- a/src/main/java/com/ql/util/express/ExpressRemoteCacheRunner.java
+++ b/src/main/java/com/ql/util/express/ExpressRemoteCacheRunner.java
@@ -2,8 +2,6 @@
import java.util.List;
-import org.apache.commons.logging.Log;
-
/**
* 远程缓存对象
*
@@ -25,14 +23,14 @@ public void loadCache(String expressName, String text) {
}
public Object execute(String name, IExpressContext context, List errorList, boolean isTrace,
- boolean isCatchException, Log log) {
+ boolean isCatchException) {
try {
CacheObject cache = (CacheObject)this.getCache(name);
if (cache == null) {
throw new RuntimeException("未获取到缓存对象.");
}
ExpressRunner expressRunner = getExpressRunner();
- return expressRunner.execute(cache.getInstructionSet(), context, errorList, isTrace, isCatchException, log);
+ return expressRunner.execute(cache.getInstructionSet(), context, errorList, isTrace, isCatchException);
} catch (Exception e) {
throw new RuntimeException("获取缓存信息,并且执行指令集出现错误.", e);
}
@@ -61,5 +59,3 @@ public Object execute(String name, IExpressContext context, List
*/
public abstract void putCache(String key, Object object);
}
-
-
diff --git a/src/main/java/com/ql/util/express/ExpressRunner.java b/src/main/java/com/ql/util/express/ExpressRunner.java
index c0f456a7b..2cf292fb8 100644
--- a/src/main/java/com/ql/util/express/ExpressRunner.java
+++ b/src/main/java/com/ql/util/express/ExpressRunner.java
@@ -32,8 +32,6 @@
import com.ql.util.express.parse.NodeType;
import com.ql.util.express.parse.NodeTypeManager;
import com.ql.util.express.parse.Word;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
* 语法分析和计算的入口类
@@ -41,7 +39,6 @@
* @author xuannan
*/
public class ExpressRunner {
- private static final Log log = LogFactory.getLog(ExpressRunner.class);
private static final String GLOBAL_DEFINE_NAME = "全局定义";
@@ -127,17 +124,15 @@ public ExpressRunner(boolean isPrecise, boolean isTrace) {
}
/**
- *
* @param isPrecise
* @param isTrace
- * @param cacheMap user can define safe and efficient cache or use default concurrentMap
+ * @param cacheMap user can define safe and efficient cache or use default concurrentMap
*/
public ExpressRunner(boolean isPrecise, boolean isTrace,
Map cacheMap) {
this(isPrecise, isTrace, new DefaultExpressResourceLoader(), null, cacheMap);
}
-
public ExpressRunner(boolean isPrecise, boolean isStrace, NodeTypeManager nodeTypeManager) {
this(isPrecise, isStrace, new DefaultExpressResourceLoader(), nodeTypeManager);
}
@@ -157,7 +152,7 @@ public ExpressRunner(boolean isPrecise, boolean isTrace, IExpressResourceLoader
* @param isPrecise 是否需要高精度计算支持
* @param isTrace 是否跟踪执行指令的过程
* @param iExpressResourceLoader 表达式的资源装载器
- * @param cacheMap 指令集缓存
+ * @param cacheMap 指令集缓存, 必须是线程安全的集合
*/
public ExpressRunner(boolean isPrecise, boolean isTrace, IExpressResourceLoader iExpressResourceLoader,
NodeTypeManager nodeTypeManager, Map cacheMap) {
@@ -225,7 +220,6 @@ public IExpressResourceLoader getExpressResourceLoader() {
return this.expressResourceLoader;
}
-
/**
* 添加宏定义
* 例如: macro 宏名称 { abc(userInfo.userId);}
@@ -537,7 +531,8 @@ public void addOperatorWithAlias(String keyWordName, String realKeyWordName, Str
}
boolean isExist = this.operatorManager.isExistOperator(realNodeType.getName());
if (!isExist && errorInfo != null) {
- throw new QLException("关键字:" + realKeyWordName + "是通过指令来实现的,不能设置错误的提示信息,errorInfo 必须是 null");
+ throw new QLException(
+ "关键字:" + realKeyWordName + "是通过指令来实现的,不能设置错误的提示信息,errorInfo 必须是 null");
}
if (!isExist || errorInfo == null) {
//不需要新增操作符号,只需要建立一个关键子即可
@@ -576,36 +571,14 @@ public void clearExpressCache() {
* @param errorList
* @param isTrace
* @param isCatchException
- * @param log
* @return
* @throws Exception
*/
public Object executeByExpressName(String name, IExpressContext context, List errorList,
- boolean isTrace, boolean isCatchException, Log log) throws Exception {
+ boolean isTrace, boolean isCatchException) throws Exception {
return InstructionSetRunner.executeOuter(this, this.loader.getInstructionSet(name), this.loader, context,
- errorList, isTrace, isCatchException, log, false);
- }
-
- ///**
- // * 执行指令集(兼容老接口,请不要自己管理指令缓存,直接使用execute(InstructionSet instructionSet,....... )
- // * 清理缓存可以使用clearExpressCache()函数
- // *
- // * @param instructionSets
- // * @param context
- // * @param errorList
- // * @param isTrace
- // * @param isCatchException
- // * @param log
- // * @return
- // * @throws Exception
- // * @deprecated
- // */
- //@Deprecated
- //public Object execute(InstructionSet[] instructionSets, IExpressContext context,
- // List errorList, boolean isTrace, boolean isCatchException, Log log) throws Exception {
- // return InstructionSetRunner.executeOuter(this, instructionSets[0], this.loader, context, errorList,
- // isTrace, isCatchException, log, false);
- //}
+ errorList, isTrace, isCatchException, false);
+ }
/**
* 执行指令集
@@ -615,14 +588,12 @@ public Object executeByExpressName(String name, IExpressContext
* @param errorList
* @param isTrace
* @param isCatchException
- * @param log
* @return
* @throws Exception
*/
public Object execute(InstructionSet instructionSet, IExpressContext context,
- List errorList, boolean isTrace, boolean isCatchException, Log log) throws Exception {
- return InstructionSetRunner.executeOuter(this, instructionSet, this.loader, context, errorList,
- isTrace, isCatchException, log, false);
+ List errorList, boolean isTrace, boolean isCatchException) throws Exception {
+ return executeReentrant(instructionSet, context, errorList, isTrace, isCatchException);
}
/**
@@ -642,7 +613,7 @@ public Object execute(String expressString, IExpressContext cont
//设置超时毫秒时间
QLExpressTimer.setTimer(timeoutMillis);
try {
- return this.execute(expressString, context, errorList, isCache, isTrace, null);
+ return this.execute(expressString, context, errorList, isCache, isTrace);
} finally {
QLExpressTimer.reset();
}
@@ -661,48 +632,38 @@ public Object execute(String expressString, IExpressContext cont
*/
public Object execute(String expressString, IExpressContext context, List errorList,
boolean isCache, boolean isTrace) throws Exception {
- return this.execute(expressString, context, errorList, isCache, isTrace, null);
- }
-
- /**
- * 执行一段文本
- *
- * @param expressString 程序文本
- * @param context 执行上下文
- * @param errorList 输出的错误信息List
- * @param isCache 是否使用Cache中的指令集
- * @param isTrace 是否输出详细的执行指令信息
- * @param log 输出的log
- * @return
- * @throws Exception
- */
- public Object execute(String expressString, IExpressContext context, List errorList,
- boolean isCache, boolean isTrace, Log log) throws Exception {
InstructionSet parseResult;
if (isCache) {
parseResult = expressInstructionSetCache.get(expressString);
if (parseResult == null) {
- expressInstructionSetCache.putIfAbsent(expressString,
- parseResult = this.parseInstructionSet(expressString));
+ synchronized (expressInstructionSetCache) {
+ // 防止在第一次执行时多次计算 parseInstructionSet, 所以需要加锁
+ // 可以优化成分段锁, 而不是锁整个 cache, 进一步优化可以使用定制的 concurrentMap
+ parseResult = expressInstructionSetCache.get(expressString);
+ if (parseResult == null) {
+ expressInstructionSetCache.put(expressString,
+ parseResult = this.parseInstructionSet(expressString));
+ }
+ }
}
} else {
parseResult = this.parseInstructionSet(expressString);
}
- return executeReentrant(parseResult, context, errorList, isTrace, log);
+ return executeReentrant(parseResult, context, errorList, isTrace, false);
}
private Object executeReentrant(InstructionSet sets, IExpressContext iExpressContext,
- List errorList, boolean isTrace, Log log) throws Exception {
+ List errorList, boolean isTrace, boolean isCatchException) throws Exception {
try {
int reentrantCount = threadReentrantCount.get() + 1;
threadReentrantCount.set(reentrantCount);
return reentrantCount > 1 ?
// 线程重入
- InstructionSetRunner.execute(this, sets, this.loader, iExpressContext, errorList, isTrace, false, true,
- log, false) :
- InstructionSetRunner.executeOuter(this, sets, this.loader, iExpressContext, errorList, isTrace, false,
- log, false);
+ InstructionSetRunner.execute(this, sets, this.loader, iExpressContext, errorList, isTrace,
+ isCatchException, true, false) :
+ InstructionSetRunner.executeOuter(this, sets, this.loader, iExpressContext, errorList, isTrace,
+ isCatchException, false);
} finally {
threadReentrantCount.set(threadReentrantCount.get() - 1);
}
@@ -726,8 +687,8 @@ public InstructionSet parseInstructionSet(String text) throws Exception {
ExpressNode root = this.parse.parse(this.rootExpressPackage, text, isTrace, selfDefineClass);
InstructionSet result = createInstructionSet(root, "main");
- if (this.isTrace && log.isDebugEnabled()) {
- log.debug(result);
+ if (this.isTrace) {
+ System.out.println(result);
}
return result;
} catch (QLCompileException e) {
@@ -756,7 +717,8 @@ public ExportItem[] getExportInfo() {
public InstructionSet getInstructionSetFromLocalCache(String expressString) throws Exception {
InstructionSet parseResult = expressInstructionSetCache.get(expressString);
if (parseResult == null) {
- expressInstructionSetCache.putIfAbsent(expressString, parseResult = this.parseInstructionSet(expressString));
+ expressInstructionSetCache.putIfAbsent(expressString,
+ parseResult = this.parseInstructionSet(expressString));
}
return parseResult;
}
@@ -846,15 +808,14 @@ public boolean checkSyntax(String text, boolean mockRemoteJavaClass, List errorList,
- boolean isReturnLastData, Log log) throws Exception {
+ boolean isReturnLastData) throws Exception {
//将函数export到上下文中,这儿就是重入也没有关系,不需要考虑并发
if (cacheFunctionSet == null) {
Map tempMap = new HashMap<>();
@@ -166,7 +160,7 @@ public CallResult execute(RunEnvironment environment, InstructionSetContext cont
context.addSymbol(cacheFunctionSet);
- this.executeInnerOriginalInstruction(environment, errorList, log);
+ this.executeInnerOriginalInstruction(environment, errorList);
// 是在执行完所有的指令后结束的代码
if (!environment.isExit()) {
if (environment.getDataStackSize() > 0) {
@@ -192,23 +186,16 @@ public CallResult execute(RunEnvironment environment, InstructionSetContext cont
return OperateDataCacheManager.fetchCallResult(environment.getReturnValue(), environment.isExit());
}
- public void executeInnerOriginalInstruction(RunEnvironment environment, List errorList, Log log)
+ public void executeInnerOriginalInstruction(RunEnvironment environment, List errorList)
throws Exception {
Instruction instruction = null;
try {
while (environment.programPoint < this.instructionList.length) {
QLExpressTimer.assertTimeOut();
instruction = this.instructionList[environment.programPoint];
- // 设置log
- instruction.setLog(log);
instruction.execute(environment, errorList);
}
} catch (Exception e) {
- if (PRINT_INSTRUCTION_ERROR) {
- InstructionSet.log.error("当前ProgramPoint = " + environment.programPoint);
- InstructionSet.log.error("当前指令" + instruction);
- InstructionSet.log.error(e);
- }
throw e;
}
}
@@ -325,4 +312,4 @@ public String toString(int level) {
throw new RuntimeException(e);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/ql/util/express/InstructionSetRunner.java b/src/main/java/com/ql/util/express/InstructionSetRunner.java
index 2cf474b22..011c14fc4 100644
--- a/src/main/java/com/ql/util/express/InstructionSetRunner.java
+++ b/src/main/java/com/ql/util/express/InstructionSetRunner.java
@@ -4,11 +4,8 @@
import com.ql.util.express.config.QLExpressTimer;
import com.ql.util.express.instruction.OperateDataCacheManager;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
public class InstructionSetRunner {
- private static final Log log = LogFactory.getLog(InstructionSetRunner.class);
private InstructionSetRunner() {
throw new IllegalStateException("Utility class");
@@ -16,14 +13,14 @@ private InstructionSetRunner() {
public static Object executeOuter(ExpressRunner runner, InstructionSet instructionSet, ExpressLoader loader,
IExpressContext iExpressContext, List errorList, boolean isTrace,
- boolean isCatchException, Log log, boolean isSupportDynamicFieldName) throws Exception {
+ boolean isCatchException, boolean isSupportDynamicFieldName) throws Exception {
try {
//开始计时
QLExpressTimer.startTimer();
OperateDataCacheManager.push(runner);
return execute(runner, instructionSet, loader, iExpressContext, errorList, isTrace, isCatchException, true,
- log, isSupportDynamicFieldName);
+ isSupportDynamicFieldName);
} finally {
OperateDataCacheManager.resetCache();
}
@@ -40,38 +37,31 @@ public static Object executeOuter(ExpressRunner runner, InstructionSet instructi
* @param isTrace
* @param isCatchException
* @param isReturnLastData
- * @param log
* @param isSupportDynamicFieldName
* @return
* @throws Exception
*/
public static Object execute(ExpressRunner runner, InstructionSet instructionSet, ExpressLoader loader,
IExpressContext iExpressContext, List errorList, boolean isTrace,
- boolean isCatchException, boolean isReturnLastData, Log log, boolean isSupportDynamicFieldName)
+ boolean isCatchException, boolean isReturnLastData, boolean isSupportDynamicFieldName)
throws Exception {
InstructionSetContext context = OperateDataCacheManager.fetchInstructionSetContext(true, runner,
iExpressContext, loader, isSupportDynamicFieldName);
- return execute(instructionSet, context, errorList, isTrace, isCatchException, isReturnLastData, log);
+ return execute(instructionSet, context, errorList, isTrace, isCatchException, isReturnLastData);
}
public static Object execute(InstructionSet set, InstructionSetContext context, List errorList,
- boolean isTrace, boolean isCatchException, boolean isReturnLastData, Log log) throws Exception {
+ boolean isTrace, boolean isCatchException, boolean isReturnLastData) throws Exception {
RunEnvironment environment;
Object result = null;
environment = OperateDataCacheManager.fetRunEnvironment(set, context, isTrace);
try {
- CallResult tempResult = set.execute(environment, context, errorList, isReturnLastData, log);
+ CallResult tempResult = set.execute(environment, context, errorList, isReturnLastData);
if (tempResult.isExit()) {
result = tempResult.getReturnValue();
}
} catch (Exception e) {
- if (isCatchException) {
- if (log != null) {
- log.error(e.getMessage(), e);
- } else {
- InstructionSetRunner.log.error(e.getMessage(), e);
- }
- } else {
+ if (!isCatchException) {
throw e;
}
}
diff --git a/src/main/java/com/ql/util/express/QLambda.java b/src/main/java/com/ql/util/express/QLambda.java
index c4ea14402..49b6153f7 100644
--- a/src/main/java/com/ql/util/express/QLambda.java
+++ b/src/main/java/com/ql/util/express/QLambda.java
@@ -4,7 +4,6 @@
import com.ql.util.express.instruction.OperateDataCacheManager;
import com.ql.util.express.instruction.opdata.OperateDataLocalVar;
-import org.apache.commons.logging.Log;
/**
* 代表一个 lambda 表达式
@@ -17,13 +16,10 @@ public class QLambda {
private final List errorList;
- private final Log log;
-
- public QLambda(InstructionSet functionSet, RunEnvironment environment, List errorList, Log log) {
+ public QLambda(InstructionSet functionSet, RunEnvironment environment, List errorList) {
this.functionSet = functionSet;
this.environment = environment;
this.errorList = errorList;
- this.log = log;
}
public Object call(Object... params) throws Exception {
@@ -39,7 +35,7 @@ public Object call(Object... params) throws Exception {
operateDataLocalVar.setObject(context, params.length > i ? params[i] : null);
}
- return InstructionSetRunner.execute(functionSet, context, errorList, environment.isTrace(), false, true, log);
+ return InstructionSetRunner.execute(functionSet, context, errorList, environment.isTrace(), false, true);
}
/**
diff --git a/src/main/java/com/ql/util/express/config/QLExpressRunStrategy.java b/src/main/java/com/ql/util/express/config/QLExpressRunStrategy.java
index 0ad111912..4db6742e6 100644
--- a/src/main/java/com/ql/util/express/config/QLExpressRunStrategy.java
+++ b/src/main/java/com/ql/util/express/config/QLExpressRunStrategy.java
@@ -48,6 +48,13 @@ public class QLExpressRunStrategy {
*/
private static Set SECURE_METHOD_LIST = new HashSet<>();
+ /**
+ * 最大申请的数组大小, 默认没有限制
+ * 防止用户一次性申请过多的内存
+ * -1 表示没有限制
+ */
+ private static int maxArrLength = -1;
+
static {
// 系统退出
SECURITY_RISK_METHOD_LIST.add(System.class.getName() + "." + "exit");
@@ -68,6 +75,12 @@ public class QLExpressRunStrategy {
SECURITY_RISK_METHOD_LIST.add("javax.naming.InitialContext.lookup");
SECURITY_RISK_METHOD_LIST.add("com.sun.rowset.JdbcRowSetImpl.setDataSourceName");
SECURITY_RISK_METHOD_LIST.add("com.sun.rowset.JdbcRowSetImpl.setAutoCommit");
+
+ // QLE 自身开关
+ SECURITY_RISK_METHOD_LIST.add(QLExpressRunStrategy.class.getName() + ".setForbidInvokeSecurityRiskMethods");
+ SECURITY_RISK_METHOD_LIST.add("jdk.jshell.JShell.create");
+ SECURITY_RISK_METHOD_LIST.add("javax.script.ScriptEngineManager.getEngineByName");
+ SECURITY_RISK_METHOD_LIST.add("org.springframework.jndi.JndiLocatorDelegate.lookup");
}
private QLExpressRunStrategy() {
@@ -162,4 +175,12 @@ public static boolean checkWhiteClassList(Class> clazz) {
public static void setCompileWhiteCheckerList(List compileWhiteCheckerList) {
QLExpressRunStrategy.compileWhiteCheckerList = compileWhiteCheckerList;
}
+
+ public static void setMaxArrLength(int maxArrLength) {
+ QLExpressRunStrategy.maxArrLength = maxArrLength;
+ }
+
+ public static boolean checkArrLength(int arrLen) {
+ return QLExpressRunStrategy.maxArrLength == -1 || arrLen <= QLExpressRunStrategy.maxArrLength;
+ }
}
diff --git a/src/main/java/com/ql/util/express/instruction/detail/Instruction.java b/src/main/java/com/ql/util/express/instruction/detail/Instruction.java
index d4fda00e8..caab7a848 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/Instruction.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/Instruction.java
@@ -3,12 +3,8 @@
import java.util.List;
import com.ql.util.express.RunEnvironment;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
public abstract class Instruction {
- protected static final transient Log staticLog = LogFactory.getLog(Instruction.class);
- protected static transient Log log = staticLog;
private Integer line = 0;
public Instruction setLine(Integer line) {
@@ -20,12 +16,6 @@ public Integer getLine() {
return line;
}
- public void setLog(Log log) {
- if (log != null) {
- Instruction.log = log;
- }
- }
-
public String getExceptionPrefix() {
return "run QlExpress Exception at line " + line + " :";
}
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionCallMacro.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionCallMacro.java
index f7032d6ad..018fc87be 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionCallMacro.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionCallMacro.java
@@ -18,15 +18,11 @@ public InstructionCallMacro(String name) {
@Override
public void execute(RunEnvironment environment, List errorList) throws Exception {
- if (environment.isTrace() && log.isDebugEnabled()) {
- log.debug(this);
- }
-
InstructionSetContext context = environment.getContext();
Object functionSet = context.getSymbol(this.name);
Object result = InstructionSetRunner.execute(context.getExpressRunner(), (InstructionSet)functionSet,
- context.getExpressLoader(), context, errorList, environment.isTrace(), false, false, log,
+ context.getExpressLoader(), context, errorList, environment.isTrace(), false, false,
environment.getContext().isSupportDynamicFieldName());
if (result instanceof OperateData) {
environment.push((OperateData)result);
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionCallSelfDefineFunction.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionCallSelfDefineFunction.java
index 8c73a06a3..0c3b86f38 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionCallSelfDefineFunction.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionCallSelfDefineFunction.java
@@ -10,9 +10,7 @@
import com.ql.util.express.RunEnvironment;
import com.ql.util.express.exception.QLException;
import com.ql.util.express.instruction.OperateDataCacheManager;
-import com.ql.util.express.instruction.opdata.OperateDataAttr;
import com.ql.util.express.instruction.opdata.OperateDataLocalVar;
-import org.apache.commons.logging.Log;
public class InstructionCallSelfDefineFunction extends Instruction {
private final String functionName;
@@ -34,37 +32,21 @@ public int getOpDataNumber() {
@Override
public void execute(RunEnvironment environment, List errorList) throws Exception {
ArraySwap parameters = environment.popArray(this.opDataNumber);
- if (environment.isTrace() && log.isDebugEnabled()) {
- StringBuilder str = new StringBuilder(this.functionName + "(");
- OperateData operateData;
- for (int i = 0; i < parameters.length; i++) {
- operateData = parameters.get(i);
- if (i > 0) {
- str.append(",");
- }
- if (operateData instanceof OperateDataAttr) {
- str.append(operateData).append(":").append(operateData.getObject(environment.getContext()));
- } else {
- str.append(operateData);
- }
- }
- str.append(")");
- log.debug(str.toString());
- }
Object function = environment.getContext().getSymbol(functionName);
if (!(function instanceof InstructionSet)) {
- throw new QLException(getExceptionPrefix() + "在Runner的操作符定义和自定义函数中都没有找到" + this.functionName + "的定义");
+ throw new QLException(
+ getExceptionPrefix() + "在Runner的操作符定义和自定义函数中都没有找到" + this.functionName + "的定义");
}
InstructionSet functionSet = (InstructionSet)function;
OperateData result = InstructionCallSelfDefineFunction.executeSelfFunction(environment, functionSet, parameters,
- errorList, log);
+ errorList);
environment.push(result);
environment.programPointAddOne();
}
public static OperateData executeSelfFunction(RunEnvironment environment, InstructionSet functionSet,
- ArraySwap parameters, List errorList, Log log) throws Exception {
+ ArraySwap parameters, List errorList) throws Exception {
InstructionSetContext context = OperateDataCacheManager.fetchInstructionSetContext(
true, environment.getContext().getExpressRunner(), environment.getContext(),
environment.getContext().getExpressLoader(), environment.getContext().isSupportDynamicFieldName());
@@ -76,8 +58,8 @@ public static OperateData executeSelfFunction(RunEnvironment environment, Instru
context.addSymbol(operateDataLocalVar.getName(), operateDataLocalVar);
operateDataLocalVar.setObject(context, parameters.get(i).getObject(environment.getContext()));
}
- Object result = InstructionSetRunner.execute(functionSet,
- context, errorList, environment.isTrace(), false, true, log);
+ Object result = InstructionSetRunner.execute(functionSet, context, errorList, environment.isTrace(), false,
+ true);
return OperateDataCacheManager.fetchOperateData(result, null);
}
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionClearDataStack.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionClearDataStack.java
index 08393c225..2020aca08 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionClearDataStack.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionClearDataStack.java
@@ -8,9 +8,6 @@ public class InstructionClearDataStack extends Instruction {
@Override
public void execute(RunEnvironment environment, List errorList) {
// 目前的模式,不需要执行任何操作
- if (environment.isTrace() && log.isDebugEnabled()) {
- log.debug(this);
- }
environment.clearDataStack();
environment.programPointAddOne();
}
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionCloseNewArea.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionCloseNewArea.java
index 2ebb19b12..e5979be95 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionCloseNewArea.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionCloseNewArea.java
@@ -9,9 +9,6 @@ public class InstructionCloseNewArea extends Instruction {
@Override
public void execute(RunEnvironment environment, List errorList) {
//目前的模式,不需要执行任何操作
- if (environment.isTrace() && log.isDebugEnabled()) {
- log.debug(this);
- }
environment.setContext((InstructionSetContext)environment.getContext().getParent());
environment.programPointAddOne();
}
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionConstData.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionConstData.java
index 49e83b79a..3080a349b 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionConstData.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionConstData.java
@@ -19,13 +19,6 @@ public OperateData getOperateData() {
@Override
public void execute(RunEnvironment environment, List errorList) throws Exception {
- if (environment.isTrace() && log.isDebugEnabled()) {
- if (this.operateData instanceof OperateDataAttr) {
- log.debug(this + ":" + this.operateData.getObject(environment.getContext()));
- } else {
- log.debug(this);
- }
- }
environment.push(this.operateData);
environment.programPointAddOne();
}
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionGoTo.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionGoTo.java
index f35ccff39..e221bff36 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionGoTo.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionGoTo.java
@@ -17,9 +17,6 @@ public InstructionGoTo(int offset) {
@Override
public void execute(RunEnvironment environment, List errorList) {
- if (environment.isTrace() && log.isDebugEnabled()) {
- log.debug(this);
- }
environment.gotoWithOffset(this.offset);
}
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionGoToWithCondition.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionGoToWithCondition.java
index 5cb612962..61fc4883e 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionGoToWithCondition.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionGoToWithCondition.java
@@ -41,14 +41,8 @@ public void execute(RunEnvironment environment, List errorList) throws E
throw new QLException(getExceptionPrefix() + "指令错误:" + o + " 不是Boolean");
}
if (r == this.condition) {
- if (environment.isTrace() && log.isDebugEnabled()) {
- log.debug("goto +" + this.offset);
- }
environment.gotoWithOffset(this.offset);
} else {
- if (environment.isTrace() && log.isDebugEnabled()) {
- log.debug("programPoint ++ ");
- }
environment.programPointAddOne();
}
}
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionGoToWithNotNull.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionGoToWithNotNull.java
index d0b0d6161..64fc546ef 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionGoToWithNotNull.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionGoToWithNotNull.java
@@ -25,14 +25,8 @@ public void execute(RunEnvironment environment, List errorList) throws E
o = environment.pop().getObject(environment.getContext());
}
if (o != null) {
- if (environment.isTrace() && log.isDebugEnabled()) {
- log.debug("goto +" + this.offset);
- }
environment.gotoWithOffset(this.offset);
} else {
- if (environment.isTrace() && log.isDebugEnabled()) {
- log.debug("programPoint ++ ");
- }
environment.programPointAddOne();
}
}
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionLoadAttr.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionLoadAttr.java
index ba4956b6b..6c61ba782 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionLoadAttr.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionLoadAttr.java
@@ -22,17 +22,10 @@ public void execute(RunEnvironment environment, List errorList) throws E
Object o = environment.getContext().getSymbol(this.attrName);
//是函数,则执行
if (o instanceof InstructionSet) {
- if (environment.isTrace() && log.isDebugEnabled()) {
- log.debug("指令转换: LoadAttr -- >CallMacro ");
- }
InstructionCallMacro macro = new InstructionCallMacro(this.attrName);
- macro.setLog(log);
macro.execute(environment, errorList);
//注意,此处不能在增加指令,因为在InstructionCallMacro已经调用 environment.programPointAddOne();
} else {
- if (environment.isTrace() && log.isDebugEnabled()) {
- log.debug(this + ":" + ((OperateDataAttr)o).getObject(environment.getContext()));
- }
environment.push((OperateDataAttr)o);
environment.programPointAddOne();
}
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionLoadLambda.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionLoadLambda.java
index b7a68100a..865cabda0 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionLoadLambda.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionLoadLambda.java
@@ -20,7 +20,7 @@ public InstructionLoadLambda(InstructionSet lambdaSet) {
@Override
public void execute(RunEnvironment environment, List errorList) {
environment.push(
- OperateDataCacheManager.fetchOperateData(new QLambda(lambdaSet, environment, errorList, log), null)
+ OperateDataCacheManager.fetchOperateData(new QLambda(lambdaSet, environment, errorList), null)
);
environment.programPointAddOne();
}
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionNewVirClass.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionNewVirClass.java
index 7ebbd45b2..d9346cc44 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionNewVirClass.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionNewVirClass.java
@@ -24,23 +24,6 @@ public String getClassName() {
@Override
public void execute(RunEnvironment environment, List errorList) throws Exception {
ArraySwap parameters = environment.popArray(this.opDataNumber);
- if (environment.isTrace() && log.isDebugEnabled()) {
- StringBuilder str = new StringBuilder("new VClass(");
- OperateData p;
- for (int i = 0; i < parameters.length; i++) {
- p = parameters.get(i);
- if (i > 0) {
- str.append(",");
- }
- if (p instanceof OperateDataAttr) {
- str.append(p).append(":").append(p.getObject(environment.getContext()));
- } else {
- str.append(p);
- }
- }
- str.append(")");
- log.debug(str.toString());
- }
//因为会影响堆栈,要先把对象拷贝出来
OperateData[] list = new OperateData[parameters.length];
@@ -51,7 +34,7 @@ public void execute(RunEnvironment environment, List errorList) throws E
OperateDataVirClass result = new OperateDataVirClass(className);
environment.push(result);
environment.programPointAddOne();
- result.initialInstance(environment.getContext(), list, errorList, environment.isTrace(), log);
+ result.initialInstance(environment.getContext(), list, errorList, environment.isTrace());
}
@Override
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionOpenNewArea.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionOpenNewArea.java
index 8c8514f21..a996e70d6 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionOpenNewArea.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionOpenNewArea.java
@@ -10,9 +10,6 @@ public class InstructionOpenNewArea extends Instruction {
@Override
public void execute(RunEnvironment environment, List errorList) {
//目前的模式,不需要执行任何操作
- if (environment.isTrace() && log.isDebugEnabled()) {
- log.debug(this);
- }
InstructionSetContext parentContext = environment.getContext();
environment.setContext(OperateDataCacheManager.fetchInstructionSetContext(
true,
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionOperator.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionOperator.java
index f1a696d91..8d55b822e 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionOperator.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionOperator.java
@@ -28,23 +28,6 @@ public OperatorBase getOperator() {
public void execute(RunEnvironment environment, List errorList) throws Exception {
InstructionSetContext instructionSetContext = environment.getContext();
ArraySwap parameters = environment.popArray(this.opDataNumber);
- if (environment.isTrace() && log.isDebugEnabled()) {
- StringBuilder stringBuilder = new StringBuilder(this.operator.toString() + "(");
- OperateData operateData;
- for (int i = 0; i < parameters.length; i++) {
- operateData = parameters.get(i);
- if (i > 0) {
- stringBuilder.append(",");
- }
- if (operateData instanceof OperateDataAttr) {
- stringBuilder.append(operateData).append(":").append(operateData.getObject(instructionSetContext));
- } else {
- stringBuilder.append(operateData);
- }
- }
- stringBuilder.append(")");
- log.debug(stringBuilder.toString());
- }
try {
OperateData result = this.operator.execute(instructionSetContext, parameters, errorList);
environment.push(result);
diff --git a/src/main/java/com/ql/util/express/instruction/detail/InstructionReturn.java b/src/main/java/com/ql/util/express/instruction/detail/InstructionReturn.java
index 0cd157bc4..fa8e5658e 100644
--- a/src/main/java/com/ql/util/express/instruction/detail/InstructionReturn.java
+++ b/src/main/java/com/ql/util/express/instruction/detail/InstructionReturn.java
@@ -14,9 +14,6 @@ public InstructionReturn(boolean haveReturnValue) {
@Override
public void execute(RunEnvironment environment, List errorList) throws Exception {
//目前的模式,不需要执行任何操作
- if (environment.isTrace() && log.isDebugEnabled()) {
- log.debug(this);
- }
if (this.haveReturnValue) {
environment.quitExpress(environment.pop().getObject(environment.getContext()));
} else {
diff --git a/src/main/java/com/ql/util/express/instruction/op/OperatorNew.java b/src/main/java/com/ql/util/express/instruction/op/OperatorNew.java
index 8c73504df..5427162c0 100644
--- a/src/main/java/com/ql/util/express/instruction/op/OperatorNew.java
+++ b/src/main/java/com/ql/util/express/instruction/op/OperatorNew.java
@@ -7,6 +7,7 @@
import com.ql.util.express.ExpressUtil;
import com.ql.util.express.InstructionSetContext;
import com.ql.util.express.OperateData;
+import com.ql.util.express.config.QLExpressRunStrategy;
import com.ql.util.express.exception.QLException;
import com.ql.util.express.instruction.OperateDataCacheManager;
@@ -30,6 +31,11 @@ public OperateData executeInner(InstructionSetContext parent, ArraySwap list) th
dimLength[index] = ((Number)(list.get(index + 1).getObject(parent)))
.intValue();
}
+ if (dimLength.length > 0) {
+ if (!QLExpressRunStrategy.checkArrLength(dimLength[0])) {
+ throw new QLException("超过了最大的数组申请限制");
+ }
+ }
return OperateDataCacheManager.fetchOperateData(Array.newInstance(tmpClass, dimLength), obj);
}
Class>[] types = new Class[list.length - 1];
diff --git a/src/main/java/com/ql/util/express/instruction/opdata/OperateDataVirClass.java b/src/main/java/com/ql/util/express/instruction/opdata/OperateDataVirClass.java
index 6c6425b3d..fe6becda5 100644
--- a/src/main/java/com/ql/util/express/instruction/opdata/OperateDataVirClass.java
+++ b/src/main/java/com/ql/util/express/instruction/opdata/OperateDataVirClass.java
@@ -8,7 +8,6 @@
import com.ql.util.express.OperateData;
import com.ql.util.express.exception.QLException;
import com.ql.util.express.instruction.OperateDataCacheManager;
-import org.apache.commons.logging.Log;
/**
* 虚拟Class的内存对象
@@ -28,16 +27,13 @@ public class OperateDataVirClass extends OperateDataAttr {
private boolean isTrace;
- private Log log;
-
public OperateDataVirClass(String name) {
super(name, null);
}
public void initialInstance(InstructionSetContext parent, OperateData[] parameters, List errorList,
- boolean isTrace, Log log) throws Exception {
+ boolean isTrace) throws Exception {
this.isTrace = isTrace;
- this.log = log;
this.context = OperateDataCacheManager.fetchInstructionSetContext(false, parent.getExpressRunner(), parent,
parent.getExpressLoader(), parent.isSupportDynamicFieldName());
Object functionSet = parent.getSymbol(this.name);
@@ -54,7 +50,7 @@ public void initialInstance(InstructionSetContext parent, OperateData[] paramete
this.context.addSymbol(operateDataLocalVar.getName(), operateDataLocalVar);
operateDataLocalVar.setObject(context, parameters[i].getObject(parent));
}
- InstructionSetRunner.execute(virClassInstructionSet, context, errorList, isTrace, false, false, this.log);
+ InstructionSetRunner.execute(virClassInstructionSet, context, errorList, isTrace, false, false);
}
public OperateData callSelfFunction(String functionName, OperateData[] parameters) throws Exception {
@@ -75,8 +71,7 @@ public OperateData callSelfFunction(String functionName, OperateData[] parameter
tempContext.addSymbol(operateDataLocalVar.getName(), operateDataLocalVar);
operateDataLocalVar.setObject(tempContext, parameters[i].getObject(this.context));
}
- Object result = InstructionSetRunner.execute(functionSet, tempContext, null, this.isTrace, false, true,
- this.log);
+ Object result = InstructionSetRunner.execute(functionSet, tempContext, null, this.isTrace, false, true);
return OperateDataCacheManager.fetchOperateData(result, null);
}
@@ -93,7 +88,7 @@ public Object getValue(Object name) throws Exception {
this.context.getExpressRunner(), this.context, this.context.getExpressLoader(),
this.context.isSupportDynamicFieldName());
Object result = InstructionSetRunner.execute(this.context.getExpressRunner(), (InstructionSet)o,
- this.context.getExpressLoader(), tempContext, null, this.isTrace, false, false, this.log,
+ this.context.getExpressLoader(), tempContext, null, this.isTrace, false, false,
this.context.isSupportDynamicFieldName());
if (result instanceof OperateData) {
return ((OperateData)result).getObject(this.context);
diff --git a/src/main/java/com/ql/util/express/match/QLPattern.java b/src/main/java/com/ql/util/express/match/QLPattern.java
index d75c9caf0..45406447f 100644
--- a/src/main/java/com/ql/util/express/match/QLPattern.java
+++ b/src/main/java/com/ql/util/express/match/QLPattern.java
@@ -5,23 +5,8 @@
import java.util.concurrent.atomic.AtomicLong;
import com.ql.util.express.exception.QLCompileException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
public class QLPattern {
- private static final Log log = LogFactory.getLog(QLPattern.class);
-
- /**
- * 优化栈的递归深度
- * TODO public field
- */
- public static boolean optimizeStackDepth = true;
-
- /**
- * 打印栈的最大深度
- * TODO public field
- */
- public static boolean printStackDepth = false;
private QLPattern() {
throw new IllegalStateException("Utility class");
@@ -41,10 +26,6 @@ public static QLMatchResult findMatchStatement(INodeTypeManager iNodeTypeManager
MatchParamsPack staticParams = new MatchParamsPack(iNodeTypeManager, nodes, maxDeep, maxMatchPoint, resultCache,
arrayListCache);
QLMatchResult result = findMatchStatementWithAddRootOptimizeStack(staticParams, pattern, point, 1);
- if (printStackDepth) {
- log.warn("递归堆栈深度:" + maxDeep.longValue() + " 重用QLMatchResult次数:" + resultCache.fetchCount
- + " 新建QLMatchResult次数:" + resultCache.newCount + " 新建ArrayList数量:" + arrayListCache.newCount);
- }
if (result == null || result.getMatchSize() == 0) {
throw new QLCompileException("程序错误,不满足语法规范,没有匹配到合适的语法,最大匹配致[0:" + (maxMatchPoint.longValue() - 1) + "]");
} else if (result.getMatchSize() != 1) {
@@ -101,8 +82,6 @@ private static QLMatchResult findMatchStatementWithAddRootOptimizeStack(MatchPar
new QLMatchResultTree(tempNodeType, nodes.get(pointDetail), pattern.targetNodeType));
pointDetail = pointDetail + 1;
resultDetail.setMatchLastIndex(pointDetail);
-
- traceLog(pattern, resultDetail, pointDetail - 1, 1);
} else if (pattern.nodeType.getPatternNode() != null) {
resultDetail = findMatchStatementWithAddRootOptimizeStack(staticParams,
pattern.nodeType.getPatternNode(), pointDetail, deep);
@@ -194,7 +173,6 @@ private static QLMatchResult findMatchStatementWithAddRootOptimizeStack(MatchPar
if (!isBreak) {
tempResult = staticParams.resultCache.fetch().addQLMatchResultTreeList(tempListAnd);
tempResult.setMatchLastIndex(pointAnd);
- traceLog(pattern, tempResult, lastPoint, matchCount);
} else {
tempResult = null;
}
@@ -282,13 +260,6 @@ private static QLMatchResult findMatchStatementWithAddRootOptimizeStack(MatchPar
return result;
}
- public static void traceLog(QLPatternNode pattern, QLMatchResult result, int point, int matchCount) {
- if (log.isTraceEnabled() && (pattern.matchMode == MatchMode.DETAIL
- || pattern.matchMode == MatchMode.AND && matchCount > 1 && !"ANONY_PATTERN".equals(pattern.name))) {
- log.trace("匹配--" + pattern.name + "[" + point + ":" + (result.getMatchLastIndex() - 1) + "]:" + pattern);
- }
- }
-
public static class MatchParamsPack {
final INodeTypeManager iNodeTypeManager;
final List extends IDataNode> nodes;
diff --git a/src/main/java/com/ql/util/express/match/QLPatternNode.java b/src/main/java/com/ql/util/express/match/QLPatternNode.java
index ec9690628..f1c689881 100644
--- a/src/main/java/com/ql/util/express/match/QLPatternNode.java
+++ b/src/main/java/com/ql/util/express/match/QLPatternNode.java
@@ -4,8 +4,6 @@
import java.util.List;
import com.ql.util.express.exception.QLCompileException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
enum MatchMode {
AND,
@@ -15,7 +13,6 @@ enum MatchMode {
}
public class QLPatternNode {
- private static final Log log = LogFactory.getLog(QLPatternNode.class);
private final INodeTypeManager nodeTypeManager;
@@ -88,7 +85,7 @@ public class QLPatternNode {
private final List children = new ArrayList<>();
public boolean canMergeDetail() {
- return QLPattern.optimizeStackDepth && this.matchMode == MatchMode.DETAIL && "ANONY_PATTERN".equals(this.name)
+ return this.matchMode == MatchMode.DETAIL && "ANONY_PATTERN".equals(this.name)
&& this.nodeType.getPatternNode() != null
&& !this.isSkip
&& !this.blame
@@ -126,13 +123,6 @@ protected QLPatternNode(INodeTypeManager iNodeTypeManager, String name, String o
}
public void splitChild() throws Exception {
- if (log.isTraceEnabled()) {
- StringBuilder str = new StringBuilder();
- for (int i = 0; i < this.level; i++) {
- str.append(" ");
- }
- //log.trace("分解匹配模式[LEVEL="+ this.level +"]START:" + str + this.originalContent);
- }
String originalStr = this.originalContent;
if ("(".equals(originalStr) || ")".equals(originalStr) || "|".equals(originalStr) || "||".equals(originalStr)
|| "/**".equals(originalStr) || "**/".equals(originalStr) || "*".equals(originalStr)
@@ -311,4 +301,4 @@ public String joinStringList(List list, String splitChar) {
}
return buffer.toString();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/ql/util/express/parse/ExpressParse.java b/src/main/java/com/ql/util/express/parse/ExpressParse.java
index 22bc8d724..409733688 100644
--- a/src/main/java/com/ql/util/express/parse/ExpressParse.java
+++ b/src/main/java/com/ql/util/express/parse/ExpressParse.java
@@ -14,12 +14,9 @@
import com.ql.util.express.exception.QLSecurityRiskException;
import com.ql.util.express.match.QLMatchResult;
import com.ql.util.express.match.QLPattern;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
public class ExpressParse {
- private static final Log log = LogFactory.getLog(ExpressParse.class);
final NodeTypeManager nodeTypeManager;
final IExpressResourceLoader expressResourceLoader;
@@ -336,13 +333,13 @@ public ExpressNode parse(ExpressPackage rootExpressPackage, String express, bool
public Word[] splitWords(String express, boolean isTrace, Map selfDefineClass) throws Exception {
Word[] words = WordSplit.parse(this.nodeTypeManager.splitWord, express);
- if (isTrace && log.isDebugEnabled()) {
- log.debug("执行的表达式:" + express);
- log.debug("单词分解结果:" + WordSplit.getPrintInfo(words, ","));
+ if (isTrace) {
+ System.out.println("执行的表达式:" + express);
+ System.out.println("单词分解结果:" + WordSplit.getPrintInfo(words, ","));
}
words = this.dealInclude(words);
- if (isTrace && log.isDebugEnabled()) {
- log.debug("预处理后结果:" + WordSplit.getPrintInfo(words, ","));
+ if (isTrace) {
+ System.out.println("预处理后结果:" + WordSplit.getPrintInfo(words, ","));
}
//提取自定义Class
@@ -366,8 +363,8 @@ public ExpressNode parse(ExpressPackage rootExpressPackage, Word[] words, String
List tempList = this.transferWord2ExpressNode(rootExpressPackage, words, selfDefineClass,
!QLExpressRunStrategy.isSandboxMode());
- if (isTrace && log.isDebugEnabled()) {
- log.debug("单词分析结果:" + printInfo(tempList, ","));
+ if (isTrace) {
+ System.out.println("单词分析结果:" + printInfo(tempList, ","));
}
//比如用在远程配置脚本,本地jvm并不包含这个java类,可以
if (mockRemoteJavaClass) {
@@ -395,8 +392,8 @@ public ExpressNode parse(ExpressPackage rootExpressPackage, Word[] words, String
}
}
tempList = tempList2;
- if (isTrace && log.isDebugEnabled()) {
- log.debug("修正后单词分析结果:" + printInfo(tempList, ","));
+ if (isTrace) {
+ System.out.println("修正后单词分析结果:" + printInfo(tempList, ","));
}
}
@@ -418,8 +415,8 @@ public ExpressNode parse(ExpressPackage rootExpressPackage, Word[] words, String
//为了生成代码时候进行判断,需要设置每个节点的父亲
resetParent(root, null);
- if (isTrace && log.isDebugEnabled()) {
- log.debug("最后的语法树:");
+ if (isTrace) {
+ System.out.println("最后的语法树:");
printTreeNode(root, 1);
}
return root;
@@ -436,4 +433,3 @@ public static String printInfo(List list, String splitOp) {
return stringBuilder.toString();
}
}
-
diff --git a/src/main/java/com/ql/util/express/parse/NodeTypeManager.java b/src/main/java/com/ql/util/express/parse/NodeTypeManager.java
index 765916b30..fcdc353bd 100644
--- a/src/main/java/com/ql/util/express/parse/NodeTypeManager.java
+++ b/src/main/java/com/ql/util/express/parse/NodeTypeManager.java
@@ -6,11 +6,8 @@
import java.util.Map;
import com.ql.util.express.match.INodeTypeManager;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
public class NodeTypeManager implements INodeTypeManager {
- private static final Log log = LogFactory.getLog(NodeTypeManager.class);
public final String[] splitWord;
private final String[] keyWords;
@@ -84,7 +81,6 @@ public NodeType createNodeType(String defineStr) {
String name = defineStr.substring(0, index).trim();
NodeType define = nodeTypes.get(name);
if (define != null) {
- log.warn("节点类型定义重复:" + name + " 定义1=" + define.getDefineStr() + " 定义2=" + defineStr);
throw new RuntimeException("节点类型定义重复:" + name + " 定义1=" + define.getDefineStr() + " 定义2=" + defineStr);
}
define = new NodeType(this, name, defineStr);
diff --git a/src/test/java/com/ql/util/express/bugfix/CompileMemoryTest.java b/src/test/java/com/ql/util/express/bugfix/CompileMemoryTest.java
index e3f3cee70..d8eceecb5 100644
--- a/src/test/java/com/ql/util/express/bugfix/CompileMemoryTest.java
+++ b/src/test/java/com/ql/util/express/bugfix/CompileMemoryTest.java
@@ -5,13 +5,11 @@
import com.ql.util.express.ExpressRunner;
import com.ql.util.express.InstructionSet;
-import com.ql.util.express.match.QLPattern;
import org.junit.Test;
public class CompileMemoryTest {
@Test
public void test() throws Exception {
- QLPattern.printStackDepth = true;
List expressList = new ArrayList<>();
String demo = "fieldList = formDO.getFieldList();\n" +
@@ -123,6 +121,5 @@ public void test() throws Exception {
InstructionSet result2 = runner2.parseInstructionSet(express);
System.out.println(express + " 编译结果如下:\n" + result2);
}
- QLPattern.printStackDepth = false;
}
}
diff --git a/src/test/java/com/ql/util/express/bugfix/StackOverFlowTest.java b/src/test/java/com/ql/util/express/bugfix/StackOverFlowTest.java
index 46772fa71..bcddf507b 100644
--- a/src/test/java/com/ql/util/express/bugfix/StackOverFlowTest.java
+++ b/src/test/java/com/ql/util/express/bugfix/StackOverFlowTest.java
@@ -3,7 +3,6 @@
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import com.ql.util.express.IExpressContext;
-import com.ql.util.express.match.QLPattern;
import org.junit.Test;
public class StackOverFlowTest {
@@ -21,20 +20,15 @@ public void test() throws Exception {
};
for (String express : expressList) {
- QLPattern.printStackDepth = true;
- QLPattern.optimizeStackDepth = false;
ExpressRunner runner = new ExpressRunner();
IExpressContext context = new DefaultContext<>();
Object result = runner.execute(express, context, null, true, false);
System.out.println(express + " = " + result);
System.out.println("优化栈深度之后:");
- QLPattern.printStackDepth = true;
- QLPattern.optimizeStackDepth = true;
ExpressRunner runner2 = new ExpressRunner();
Object result2 = runner2.execute(express, context, null, true, false);
System.out.println(express + " = " + result2);
- QLPattern.printStackDepth = false;
}
}
}
diff --git a/src/test/java/com/ql/util/express/example/WorkflowTest.java b/src/test/java/com/ql/util/express/example/WorkflowTest.java
index b1c9aba23..4c9a028c8 100644
--- a/src/test/java/com/ql/util/express/example/WorkflowTest.java
+++ b/src/test/java/com/ql/util/express/example/WorkflowTest.java
@@ -106,7 +106,7 @@ public void testApprove2() throws Exception {
expressContext.put("申请人", "小强");
expressContext.put("金额", 5000);
- runner.executeByExpressName("example/approve1", expressContext, null, false, false, null);
+ runner.executeByExpressName("example/approve1", expressContext, null, false, false);
}
/**
@@ -135,7 +135,7 @@ public void testApprove3() throws Exception {
expressContext.put("申请人", "小强");
expressContext.put("金额", 6000);
- runner.executeByExpressName("example/approve", expressContext, null, false, false, null);
+ runner.executeByExpressName("example/approve", expressContext, null, false, false);
}
/**
@@ -165,6 +165,6 @@ public void testApprove4() throws Exception {
expressContext.put("申请人", "小强");
expressContext.put("金额", 7000);
- runner.executeByExpressName("example/approve1", expressContext, null, false, false, null);
+ runner.executeByExpressName("example/approve1", expressContext, null, false, false);
}
}
diff --git a/src/test/java/com/ql/util/express/test/AClassDefineSingleTest.java b/src/test/java/com/ql/util/express/test/AClassDefineSingleTest.java
index 223807697..9dc5e78ce 100644
--- a/src/test/java/com/ql/util/express/test/AClassDefineSingleTest.java
+++ b/src/test/java/com/ql/util/express/test/AClassDefineSingleTest.java
@@ -21,7 +21,7 @@ public void testABC() throws Exception {
DefaultContext context = new DefaultContext<>();
expressRunner.loadMultiExpress("", expressDefine);
expressRunner.loadMultiExpress("ClassTest", express);
- Object result = expressRunner.executeByExpressName("ClassTest", context, null, true, false, null);
+ Object result = expressRunner.executeByExpressName("ClassTest", context, null, true, false);
System.out.println("result = " + result);
}
}
diff --git a/src/test/java/com/ql/util/express/test/AClassDefineTest.java b/src/test/java/com/ql/util/express/test/AClassDefineTest.java
index cdbcb9be0..75642267b 100644
--- a/src/test/java/com/ql/util/express/test/AClassDefineTest.java
+++ b/src/test/java/com/ql/util/express/test/AClassDefineTest.java
@@ -21,7 +21,7 @@ public void testNewVClass() throws Exception {
DefaultContext context = new DefaultContext<>();
runner.loadMultiExpress("ClassTest", express);
- Object result = runner.executeByExpressName("ClassTest", context, null, false, false, null);
+ Object result = runner.executeByExpressName("ClassTest", context, null, false, false);
Assert.assertTrue("VClass的作用域错误", result.toString().equalsIgnoreCase("300"));
}
@@ -58,7 +58,7 @@ public void testABC() throws Exception {
DefaultContext context = new DefaultContext<>();
runner.loadMultiExpress("", expressDefine);
runner.loadMultiExpress("ClassTest", express);
- Object r = runner.executeByExpressName("ClassTest", context, null, false, false, null);
+ Object r = runner.executeByExpressName("ClassTest", context, null, false, false);
Assert.assertTrue("VClass的作用域错误", r.toString().equalsIgnoreCase("330--430--xuannan--xuanyu--199.99--11.11"));
}
}
diff --git a/src/test/java/com/ql/util/express/test/ArrayLenCheckTest.java b/src/test/java/com/ql/util/express/test/ArrayLenCheckTest.java
new file mode 100644
index 000000000..08df8ee90
--- /dev/null
+++ b/src/test/java/com/ql/util/express/test/ArrayLenCheckTest.java
@@ -0,0 +1,30 @@
+package com.ql.util.express.test;
+
+import com.ql.util.express.DefaultContext;
+import com.ql.util.express.ExpressRunner;
+import com.ql.util.express.config.QLExpressRunStrategy;
+import com.ql.util.express.exception.QLException;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Author: DQinYuan
+ */
+public class ArrayLenCheckTest {
+
+ @Test
+ public void checkTest() throws Exception {
+ QLExpressRunStrategy.setMaxArrLength(10);
+ ExpressRunner runner = new ExpressRunner();
+ String code = "byte[] a = new byte[11];";
+ try {
+ runner.execute(code, new DefaultContext<>(), null, false, false, 20);
+ Assert.fail();
+ } catch (QLException e) {
+ }
+
+ QLExpressRunStrategy.setMaxArrLength(-1);
+ runner.execute(code, new DefaultContext<>(), null, false, false, 20);
+ }
+
+}
diff --git a/src/test/java/com/ql/util/express/test/DynamicFieldTest.java b/src/test/java/com/ql/util/express/test/DynamicFieldTest.java
index f02dae6e4..9b8bd2f01 100644
--- a/src/test/java/com/ql/util/express/test/DynamicFieldTest.java
+++ b/src/test/java/com/ql/util/express/test/DynamicFieldTest.java
@@ -7,13 +7,10 @@
import com.ql.util.express.ExpressRunner;
import com.ql.util.express.InstructionSet;
import com.ql.util.express.InstructionSetRunner;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
public class DynamicFieldTest {
- private static final Log log = LogFactory.getLog(DynamicFieldTest.class);
@Test
public void testField() throws Exception {
@@ -28,7 +25,7 @@ public void testField() throws Exception {
Map fee = new HashMap<>();
context.put("费用", fee);
InstructionSet set = runner.parseInstructionSet(express);
- InstructionSetRunner.executeOuter(runner, set, null, context, null, true, false, null, true);
+ InstructionSetRunner.executeOuter(runner, set, null, context, null, true, false, true);
runner.execute(express, context, null, false, true);
System.out.println(context.get("费用"));
Assert.assertEquals("动态属性错误", "100", fee.get("张三").toString());
@@ -41,8 +38,7 @@ public void testLoadFromFile() throws Exception {
runner.loadExpress("testFunctionParameterType");
DefaultContext context = new DefaultContext<>();
context.put("auctionUtil", new BeanExample());
- context.put("log", log);
- Object r = runner.executeByExpressName("testFunctionParameterType", context, null, false, false, null);
+ Object r = runner.executeByExpressName("testFunctionParameterType", context, null, false, false);
System.out.println(r);
System.out.println(context);
}
diff --git a/src/test/java/com/ql/util/express/test/ExpressCacheTest.java b/src/test/java/com/ql/util/express/test/ExpressCacheTest.java
index 1b65ae9b4..f26f19be4 100644
--- a/src/test/java/com/ql/util/express/test/ExpressCacheTest.java
+++ b/src/test/java/com/ql/util/express/test/ExpressCacheTest.java
@@ -70,14 +70,14 @@ public void testRemoteCache() {
context.put("数学", 99);
context.put("英语", 95);
//ExpressRemoteCacheRunner都只能执行自己原有的脚本内容,而且相互之间隔离,保证最高的脚本安全性
- echo(cacheRunner.execute("计算平均成绩", context, null, false, false, null));
+ echo(cacheRunner.execute("计算平均成绩", context, null, false, false));
try {
- echo(cacheRunner.execute("计算平均成绩>90", context, null, false, false, null));
+ echo(cacheRunner.execute("计算平均成绩>90", context, null, false, false));
} catch (Exception e) {
echo("ExpressRemoteCacheRunner只支持预先加载的脚本内容");
}
try {
- echo(cacheRunner.execute("是否优秀", context, null, false, false, null));
+ echo(cacheRunner.execute("是否优秀", context, null, false, false));
} catch (Exception e) {
echo("ExpressRemoteCacheRunner不支持脚本间的相互调用");
}
diff --git a/src/test/java/com/ql/util/express/test/ExpressRemoteCacheTest.java b/src/test/java/com/ql/util/express/test/ExpressRemoteCacheTest.java
index 6eb792871..adee999a7 100644
--- a/src/test/java/com/ql/util/express/test/ExpressRemoteCacheTest.java
+++ b/src/test/java/com/ql/util/express/test/ExpressRemoteCacheTest.java
@@ -21,17 +21,17 @@ public void test_cache() {
context.put("b", 2);
if (cacheRunner.getCache("加法计算") != null) {
- Object result = cacheRunner.execute("加法计算", context, null, false, true, null);
+ Object result = cacheRunner.execute("加法计算", context, null, false, true);
Assert.assertTrue("加法计算", result.toString().equalsIgnoreCase("3"));
System.out.println(result);
}
if (cacheRunner.getCache("加法计算") != null) {
- Object result = cacheRunner.execute("减法计算", context, null, false, true, null);
+ Object result = cacheRunner.execute("减法计算", context, null, false, true);
Assert.assertTrue("减法计算", result.toString().equalsIgnoreCase("-1"));
System.out.println(result);
}
if (cacheRunner.getCache("乘法计算") != null) {
- Object result = cacheRunner.execute("乘法计算", context, null, false, true, null);
+ Object result = cacheRunner.execute("乘法计算", context, null, false, true);
Assert.assertTrue("乘法计算", result.toString().equalsIgnoreCase("2"));
System.out.println(result);
} else {
diff --git a/src/test/java/com/ql/util/express/test/LoadExpressFromFileTest.java b/src/test/java/com/ql/util/express/test/LoadExpressFromFileTest.java
index 865656399..e20e80efc 100644
--- a/src/test/java/com/ql/util/express/test/LoadExpressFromFileTest.java
+++ b/src/test/java/com/ql/util/express/test/LoadExpressFromFileTest.java
@@ -3,7 +3,6 @@
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExportItem;
import com.ql.util.express.ExpressRunner;
-import org.apache.commons.logging.Log;
import org.junit.Test;
public class LoadExpressFromFileTest {
@@ -17,13 +16,12 @@ public void testLoadFromFile() throws Exception {
System.out.println(item.getGlobeName());
}
DefaultContext context = new DefaultContext<>();
- Log log = new MyLog("玄难测试");
- Object r = runner.executeByExpressName("main", context, null, false, false, log);
+ Object r = runner.executeByExpressName("main", context, null, false, false);
System.out.println("运行结果" + r);
System.out.println("context:" + context);
context = new DefaultContext<>();
- r = runner.execute("initial;累加;累加;return qh;", context, null, true, false, log);
+ r = runner.execute("initial;累加;累加;return qh;", context, null, true, false);
System.out.println("运行结果" + r);
System.out.println("context:" + context);
@@ -34,7 +32,7 @@ public void testLoadInclude() throws Exception {
ExpressRunner runner = new ExpressRunner(false, true);
runner.loadExpress("includeRoot");
DefaultContext context = new DefaultContext<>();
- Object r = runner.executeByExpressName("includeRoot", context, null, false, false, null);
+ Object r = runner.executeByExpressName("includeRoot", context, null, false, false);
System.out.println(r);
System.out.println(context);
}
diff --git a/src/test/java/com/ql/util/express/test/MyLog.java b/src/test/java/com/ql/util/express/test/MyLog.java
deleted file mode 100644
index a7761eb80..000000000
--- a/src/test/java/com/ql/util/express/test/MyLog.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package com.ql.util.express.test;
-
-import org.apache.commons.logging.Log;
-
-public class MyLog implements Log {
- private final String name;
-
- public MyLog(String name) {
- this.name = name;
- }
-
- public boolean isDebugEnabled() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isErrorEnabled() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isFatalEnabled() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isInfoEnabled() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isTraceEnabled() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isWarnEnabled() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void trace(Object message) {
- // TODO Auto-generated method stub
- }
-
- public void trace(Object message, Throwable t) {
- // TODO Auto-generated method stub
- }
-
- public void debug(Object message) {
- // TODO Auto-generated method stub
- }
-
- public void debug(Object message, Throwable t) {
- // TODO Auto-generated method stub
- }
-
- public void info(Object message) {
- // TODO Auto-generated method stub
- }
-
- public void info(Object message, Throwable t) {
- // TODO Auto-generated method stub
- }
-
- public void warn(Object message) {
- // TODO Auto-generated method stub
- }
-
- public void warn(Object message, Throwable t) {
- // TODO Auto-generated method stub
- }
-
- public void error(Object message) {
- // TODO Auto-generated method stub
- }
-
- public void error(Object message, Throwable t) {
- // TODO Auto-generated method stub
- }
-
- public void fatal(Object message) {
- // TODO Auto-generated method stub
- }
-
- public void fatal(Object message, Throwable t) {
- // TODO Auto-generated method stub
- }
-}
diff --git a/src/test/java/com/ql/util/express/test/rating/RatingTest.java b/src/test/java/com/ql/util/express/test/rating/RatingTest.java
index 1fd942fb6..59dfb5839 100644
--- a/src/test/java/com/ql/util/express/test/rating/RatingTest.java
+++ b/src/test/java/com/ql/util/express/test/rating/RatingTest.java
@@ -38,7 +38,7 @@ public void testRating() throws Exception {
context.put("仓储订单", goodsOrder);
context.put("费用科目", subjectValue);
//执行指令
- runner.executeByExpressName("rating", context, null, false, false, null);
+ runner.executeByExpressName("rating", context, null, false, false);
//runner.executeByExpressName("rating", context, null, false, false, null);
//while (true) {
// runner.executeByExpressName("rating", context, null, false, false, null);
diff --git a/src/test/java/com/ql/util/express/test/rating/RatingWithPropertyTest.java b/src/test/java/com/ql/util/express/test/rating/RatingWithPropertyTest.java
index b23e10395..f2bad83cd 100644
--- a/src/test/java/com/ql/util/express/test/rating/RatingWithPropertyTest.java
+++ b/src/test/java/com/ql/util/express/test/rating/RatingWithPropertyTest.java
@@ -38,7 +38,7 @@ public void testRating() throws Exception {
SubjectManager subjectManager = new SubjectManager();
context.put("费用", subjectManager);
- runner.executeByExpressName("ratingWithProperty", context, null, false, false, null);
+ runner.executeByExpressName("ratingWithProperty", context, null, false, false);
//输出分成结果
System.out.println("----------分成结果----------------");
for (Object item : subjectManager.getSubjectValues()) {
diff --git a/src/test/resources/testFunctionParameterType.ql b/src/test/resources/testFunctionParameterType.ql
index 5364db674..c923efe81 100644
--- a/src/test/resources/testFunctionParameterType.ql
+++ b/src/test/resources/testFunctionParameterType.ql
@@ -4,4 +4,4 @@ java.util.Map auction = new java.util.HashMap();
auction.put("title","title");
auction.put("category","123456");
event.put("auction",auction);
-log.warn(auctionUtil.getText(event.auction.title,event.auction.category));
+System.out.println(auctionUtil.getText(event.auction.title,event.auction.category));