提交 9a5646b4 编写于 作者: T tianqiao

update runner.getOutFunctionNames nullPointer exception

上级 5f921d8d
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<groupId>com.taobao.util</groupId> <groupId>com.taobao.util</groupId>
<artifactId>taobao-express</artifactId> <artifactId>taobao-express</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>3.1.6</version> <version>3.1.7</version>
<name>taobao-express</name> <name>taobao-express</name>
<dependencies> <dependencies>
......
...@@ -99,17 +99,19 @@ public class InstructionSet implements Serializable{ ...@@ -99,17 +99,19 @@ public class InstructionSet implements Serializable{
if (instruction instanceof InstructionOperator) { if (instruction instanceof InstructionOperator) {
String opName = ((InstructionOperator) instruction) String opName = ((InstructionOperator) instruction)
.getOperator().getName(); .getOperator().getName();
if (opName.equalsIgnoreCase("def") if(opName != null){//addOperator(op)中op.name有可能为空
|| opName.equalsIgnoreCase("exportDef")) { if (opName.equalsIgnoreCase("def")
String varLocalName = (String) ((InstructionConstData) instructionList[i - 1]) || opName.equalsIgnoreCase("exportDef")) {
.getOperateData().getObject(null); String varLocalName = (String) ((InstructionConstData) instructionList[i - 1])
result.remove(varLocalName); .getOperateData().getObject(null);
} else if (opName.equalsIgnoreCase("alias") result.remove(varLocalName);
|| opName.equalsIgnoreCase("exportAlias")) { } else if (opName.equalsIgnoreCase("alias")
String varLocalName = (String) ((InstructionConstData) instructionList[i - 2]) || opName.equalsIgnoreCase("exportAlias")) {
.getOperateData().getObject(null); String varLocalName = (String) ((InstructionConstData) instructionList[i - 2])
result.remove(varLocalName); .getOperateData().getObject(null);
} result.remove(varLocalName);
}
}
} }
} }
return result.keySet().toArray(new String[0]); return result.keySet().toArray(new String[0]);
......
package com.ql.util.express.example; package com.ql.util.express.example;
import com.ql.util.express.DefaultContext; import com.ql.util.express.*;
import com.ql.util.express.ExpressRunner; import com.ql.util.express.instruction.op.OperatorBase;
import com.ql.util.express.IExpressContext; import org.apache.commons.lang.builder.ToStringBuilder;
import com.ql.util.express.Operator; import org.apache.commons.lang.builder.ToStringStyle;
import org.junit.Test; import org.junit.Test;
/** /**
...@@ -60,4 +60,50 @@ public class ArgumentTypeMismatchTest { ...@@ -60,4 +60,50 @@ public class ArgumentTypeMismatchTest {
} }
System.out.print("test ok!"); System.out.print("test ok!");
} }
@Test
public void test3() throws Exception {
ExpressRunner runner = new ExpressRunner();
runner.addFunction("abc", new Operator() {
@Override
public Object executeInner(Object[] list) throws Exception {
Long paramA = Long.valueOf(list[0].toString());
Integer paramB = Integer.valueOf(list[1].toString());
String paramC = list[2].toString();
singleton.functionABC(paramA, paramB, paramC);
return null;
}
});
OperatorBase function = runner.getFunciton("abc");
System.out.println("function = " + ToStringBuilder.reflectionToString(function, ToStringStyle.MULTI_LINE_STYLE));
String exp = "abc(a,b,c)";
IExpressContext<String, Object> context = new DefaultContext<String, Object>();
context.put("a", "1");
context.put("b", "2");
context.put("c", "3");
InstructionSet instructionSet = runner.getInstructionSetFromLocalCache(exp);
String[] outFunctionNames = runner.getOutFunctionNames(exp);
String[] outVarNames = runner.getOutVarNames(exp);
System.out.println("before execute instructionSet = " + instructionSet);
System.out.println("outFunctionNames = " + ToStringBuilder.reflectionToString(outFunctionNames, ToStringStyle.MULTI_LINE_STYLE));
System.out.println("outVarNames = " + ToStringBuilder.reflectionToString(outVarNames, ToStringStyle.MULTI_LINE_STYLE));
try {
runner.execute(exp, context, null, false, false);
} catch (Exception e) {
e.printStackTrace();
}
instructionSet = runner.getInstructionSetFromLocalCache(exp);
outFunctionNames = runner.getOutFunctionNames(exp);
outVarNames = runner.getOutVarNames(exp);
System.out.println("after execute instructionSet = " + instructionSet);
System.out.println("outFunctionNames = " + ToStringBuilder.reflectionToString(outFunctionNames, ToStringStyle.MULTI_LINE_STYLE));
System.out.println("outVarNames = " + ToStringBuilder.reflectionToString(outVarNames, ToStringStyle.MULTI_LINE_STYLE));
System.out.println("test ok!");
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册