Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The java demo in the instruction manual will fail to execute #350

Open
YesOrNo828 opened this issue Aug 29, 2024 · 0 comments
Open

The java demo in the instruction manual will fail to execute #350

YesOrNo828 opened this issue Aug 29, 2024 · 0 comments

Comments

@YesOrNo828
Copy link

Version: 3.3.3
Junit Test Execute failed:

    @Test
    public void testJava() throws Exception {

        ExpressRunner runner = new ExpressRunner();
        String express = "n = 10;\n" +
                "sum = 0;\n" +
                "for(i = 0; i < n; i++) {\n" +
                "   sum = sum + i;\n" +
                "}\n" +
                "return sum;";
        Object r = runner.execute(express, null, null, true, false);
        System.out.println(r);
    }

the exact exception:

com.ql.util.express.exception.QLBizException: run QlExpress Exception at line 1 :

	at com.ql.util.express.instruction.detail.InstructionOperator.execute(InstructionOperator.java:38)
	at com.ql.util.express.InstructionSet.executeInnerOriginalInstruction(InstructionSet.java:200)
	at com.ql.util.express.InstructionSet.execute(InstructionSet.java:164)
	at com.ql.util.express.InstructionSetRunner.execute(InstructionSetRunner.java:64)
	at com.ql.util.express.InstructionSetRunner.execute(InstructionSetRunner.java:55)
	at com.ql.util.express.InstructionSetRunner.executeOuter(InstructionSetRunner.java:19)
	at com.ql.util.express.ExpressRunner.executeReentrant(ExpressRunner.java:655)
	at com.ql.util.express.ExpressRunner.executeInner(ExpressRunner.java:641)
	at com.ql.util.express.ExpressRunner.execute(ExpressRunner.java:629)
	at com.ql.util.express.self.TestQuickStart.testJava(TestQuickStart.java:36)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
	at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
	at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
	at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
	at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
	at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
	at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:130)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: 没有定义局部变量:n,而且没有全局上下文
	at com.ql.util.express.instruction.opdata.OperateDataAttr.setObject(OperateDataAttr.java:92)
	at com.ql.util.express.instruction.op.OperatorEvaluate.executeInner(OperatorEvaluate.java:40)
	at com.ql.util.express.instruction.op.OperatorEvaluate.executeInner(OperatorEvaluate.java:22)
	at com.ql.util.express.instruction.op.OperatorBase.execute(OperatorBase.java:56)
	at com.ql.util.express.instruction.detail.InstructionOperator.execute(InstructionOperator.java:32)
	... 32 more
Caused by: java.lang.RuntimeException: 没有定义局部变量:n,而且没有全局上下文
	at com.ql.util.express.InstructionSetContext.put(InstructionSetContext.java:143)
	at com.ql.util.express.instruction.opdata.OperateDataAttr.setObject(OperateDataAttr.java:90)
	... 36 more


Process finished with exit code 255

But execute successfully:

    @Test
    public void testJavaType() throws Exception {

        ExpressRunner runner = new ExpressRunner();
        String express = "int n = 10;\n" +
                "int sum = 0;\n" +
                "for(int i = 0; i < n; i++) {\n" +
                "   sum = sum + i;\n" +
                "}\n" +
                "return sum;";
        Object r = runner.execute(express, null, null, true, false);
        System.out.println(r);
    }

Maybe we should modify the guideline in the README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant