Consider this test:
---
package tests;
import java.lang.reflect.Method;
dialect "mvel"
rule "Rule #1"
when
then
Class clazz = Class.forName("java.lang.Class");
System.out.println("clazz = " + clazz);
Method m = clazz.getDeclaredMethod("forName", new Class [] {
java.lang.String.class });
System.out.println("m = " + m);
end
--
(which runs correctly when dialect "java" is given), fails in Drools
4.0.4/MVEL 1.4 with:
org.mvel.CompileException: could not create constructor:
java.lang.Class.<init>()
at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeObjectCreation(ReflectiveAccessorOptimizer.java:688)
at org.mvel.ast.NewObjectNode.getReducedValueAccelerated(NewObjectNode.java:191)
at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
at org.mvel.CompiledExpression.getValue(CompiledExpression.java:106)
at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:521)
at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:260)
at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:109)
at
org.mvel.ast.VariableDeepPropertyNode.getReducedValueAccelerated(VariableDeepPropertyNode.java:29)
at org.mvel.ast.PropertyASTNode.initializePropertyNode(PropertyASTNode.java:77)
at
org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(PropertyASTNode.java:26)
at org.mvel.ExecutableAccessor.getValue(ExecutableAccessor.java:45)
at org.mvel.ast.TypedVarNode.getReducedValueAccelerated(TypedVarNode.java:43)
at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
at org.mvel.MVEL.executeExpression(MVEL.java:235)
at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:47)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:471)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:433)
at org.libx.autodetect.DroolsDriver$Host.fireAllRules(DroolsDriver.java:63)
at org.libx.autodetect.DroolsDriver.main(DroolsDriver.java:136)
It appears to be looking for a constructor for "new java.lang.Class()"
rather than constructing an array.)
Similarly, "o.method(new String [] { ... })" fails because it looks
for a method taking a String, rather than String[].
- Godmar
Show replies by date