1.背景
代码如下
@Test
public void janinoPerformanceTest4() throws Exception {
String rule = "(inValues(appProtocol, \"http,https\") " +
"&& inValues(direction, \"10,00\")) " +
"&& (destHostName != null) " +
"&& (eventCount != null) " +
"&& (bytesOut != null) " +
"&& (bytesIn != null)";
IExpressionEvaluator evaluator = CompilerFactoryFactory.getDefaultCompilerFactory().newExpressionEvaluator();
evaluator.setExpressionType(boolean.class);
evaluator.setExtendedClass(JaninoContainsIgnoreCaseFunction.class);
evaluator.setParameters(
new String[]{"httpVersion", "requestHeader", "direction"},
new Class[]{String.class, String.class, String.class}
);
evaluator.cook(rule);
Object[] arguments = {"/securityEyeLogType" + i, "/dataType/Add" + i,
"/appProtocol/NetWorkLayer" + i};
Object res = evaluator.evaluate(arguments);
System.out.println(res);
}
报错如下
org.codehaus.commons.compiler.CompileException: Line 1, Column 158: Expression "bytesIn" is not an rvalue
at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:12124)
at org.codehaus.janino.UnitCompiler.toRvalueOrCompileException(UnitCompiler.java:7425)
at org.codehaus.janino.UnitCompiler.getConstantValue2(UnitCompiler.java:5654)
at org.codehaus.janino.UnitCompiler.access$10200(UnitCompiler.java:215)
at org.codehaus.janino.UnitCompiler$17$1.visitAmbiguousName(UnitCompiler.java:5609)
at org.codehaus.janino.Java$AmbiguousName.accept(Java.java:4213)
at org.codehaus.janino.UnitCompiler$17.visitLvalue(UnitCompiler.java:5606)
at org.codehaus.janino.Java$Lvalue.accept(Java.java:4137)
at org.codehaus.janino.UnitCompiler.getConstantValue(UnitCompiler.java:5602)
at org.codehaus.janino.UnitCompiler.getConstantValue2(UnitCompiler.java:5753)
at org.codehaus.janino.UnitCompiler.access$10800(UnitCompiler.java:215)
at org.codehaus.janino.UnitCompiler$17.visitBinaryOperation(UnitCompiler.java:5623)
at org.codehaus.janino.Java$BinaryOperation.accept(Java.java:4853)
at org.codehaus.janino.UnitCompiler.getConstantValue(UnitCompiler.java:5602)
at org.codehaus.janino.UnitCompiler.getConstantValue2(UnitCompiler.java:5919)
at org.codehaus.janino.UnitCompiler.access$10600(UnitCompiler.java:215)
at org.codehaus.janino.UnitCompiler$17$1.visitParenthesizedExpression(UnitCompiler.java:5615)
at org.codehaus.janino.Java$ParenthesizedExpression.accept(Java.java:4913)
at org.codehaus.janino.UnitCompiler$17.visitLvalue(UnitCompiler.java:5606)
at org.codehaus.janino.Java$Lvalue.accept(Java.java:4137)
at org.codehaus.janino.UnitCompiler.getConstantValue(UnitCompiler.java:5602)
at org.codehaus.janino.UnitCompiler.compileBoolean2(UnitCompiler.java:4044)
at org.codehaus.janino.UnitCompiler.access$6600(UnitCompiler.java:215)
at org.codehaus.janino.UnitCompiler$14.visitBinaryOperation(UnitCompiler.java:3955)
at org.codehaus.janino.UnitCompiler$14.visitBinaryOperation(UnitCompiler.java:3933)
at org.codehaus.janino.Java$BinaryOperation.accept(Java.java:4853)
at org.codehaus.janino.UnitCompiler.compileBoolean(UnitCompiler.java:3933)
at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4446)
at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:5002)
at org.codehaus.janino.UnitCompiler.access$8500(UnitCompiler.java:215)
at org.codehaus.janino.UnitCompiler$16.visitBinaryOperation(UnitCompiler.java:4415)
at org.codehaus.janino.UnitCompiler$16.visitBinaryOperation(UnitCompiler.java:4394)
at org.codehaus.janino.Java$BinaryOperation.accept(Java.java:4853)
at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4394)
at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5575)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2649)
at org.codehaus.janino.UnitCompiler.access$2800(UnitCompiler.java:215)
at org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1504)
at org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1487)
at org.codehaus.janino.Java$ReturnStatement.accept(Java.java:3552)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487)
at org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1567)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3388)
at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1357)
at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1330)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:822)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:432)
at org.codehaus.janino.UnitCompiler.access$400(UnitCompiler.java:215)
at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:411)
at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:406)
at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:1414)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:406)
at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:378)
at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:237)
at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:465)
at org.codehaus.janino.ClassBodyEvaluator.compileToClass(ClassBodyEvaluator.java:313)
at org.codehaus.janino.ScriptEvaluator.cook2(ScriptEvaluator.java:608)
at org.codehaus.janino.ScriptEvaluator.cook(ScriptEvaluator.java:597)
at org.codehaus.janino.ScriptEvaluator.cook(ScriptEvaluator.java:534)
at org.codehaus.janino.ScriptEvaluator.cook(ScriptEvaluator.java:503)
at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:207)
at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:80)
at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:75)
at com.janino.demo.JaninoDemoTest.janinoPerformanceTest4(JaninoDemoTest.java:528)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
这是因为你的bytesIn这个字段没有在下面传递new String[]{"httpVersion", "requestHeader", "direction"},
.一一对应就好了。