Hi again Wolfgang,
I properly reproduced the problem with the following test case and indeed it fails as you anticipated
public class Convention {
private final Map<String, List<String>> comms;
public Convention( Map<String, List<String>> comms ) {
this.comms = comms;
}
public Map<String, List<String>> getComms(){
return comms;
}
}
@Test
public void testGenericInference() {
// DROOLS-
String drl = "package com.sample\n" +
"import " + Convention.class.getCanonicalName() + ";\n" +
"global java.util.List list;\n" +
"rule R when\n" +
" $conv : Convention()\n" +
" $s : String() from $conv.getComms().get(\"test\")\n" +
"then\n" +
" list.add($s);" +
"end\n";
KieSession kSession = new KieHelper().addContent( drl, ResourceType.DRL ).build().newKieSession();
List<String> list = new ArrayList<String>();
kSession.setGlobal( "list", list );
Map<String, List<String>> comms = new HashMap<String, List<String>>();
comms.put("test", asList("result"));
kSession.insert( new Convention( comms ) );
kSession.fireAllRules();
assertEquals( 1, list.size() );
assertEquals( "result", list.get(0) );
}
However the interesting thing here is that just putting a couple of parenthesis around $conv.getComms() without adding any further explicit cast like in
" $s : String() from ($conv.getComms()).get(\"test\")\n" +
is enough to fix the problem. Having noticed this another obvious way to workaround this issue is binding the map in the previous pattern like in
" $conv : Convention( $comms : comms )\n" +
" $s : String() from $comms.get(\"test\")\n" +
Unfortunately the problem seems to be caused by mvel since the exception raised internally is the following:
java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
at org.mvel2.compiler.PropertyVerifier.getMethod(PropertyVerifier.java:642)
at org.mvel2.compiler.PropertyVerifier.analyze(PropertyVerifier.java:120)
at org.mvel2.compiler.ExpressionCompiler.verify(ExpressionCompiler.java:373)
at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:266)
at org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:52)
at org.mvel2.MVEL.analyze(MVEL.java:680)
at org.mvel2.MVEL.analyze(MVEL.java:685)
at org.drools.compiler.rule.builder.dialect.mvel.MVELExprAnalyzer.analyzeExpression(MVELExprAnalyzer.java:214)
at org.drools.compiler.rule.builder.dialect.mvel.MVELDialect.analyzeExpression(MVELDialect.java:510)
I'll try to reproduce and fix this issue inside mvel, but I cannot commit on when I'll have time to do this.
Will you add these further info to the StackOverflow question or do you want me to do that?
Regards,
Mario