[rules-users] Map<String, String> and modify() can't be together

raojinghai at gmail.com raojinghai at gmail.com
Sat May 17 22:27:11 EDT 2014


Hi Wolfgang,

You are right. It only happens for variable declaration. It has no problem
on the right side. For example

Map a = new HashMap<String,String>()

has no problem.

I am using 6.0.1-Final.

Thanks.

Jinghai


On Fri, May 16, 2014 at 11:58 PM, Wolfgang Laun <wolfgang.laun at gmail.com>wrote:

> This also works:
>      Map<String,String> a = new HashMap<>();
>
> More ways to run into an error
>      Map<String,String> a;
>      a = new HashMap<String,String>();
> etc.
>
> Using 6.0.0-Final
> -W
>
> On 17/05/2014, rjh <raojinghai at gmail.com> wrote:
> > Hi,
> >
> > I got a weird problem. A Java List/Map with generics can be used together
> > with modify() in the same rule. For example, a simple rule like the
> > following:
> >
> > package com.sample
> >
> > import java.util.Map;
> > import java.util.HashMap;
> >
> > declare TestFact
> >     @propertyReactive
> >     data : String
> > end
> >
> > rule "init"
> >     when
> >         not TestFact()
> >     then
> >         insert (new TestFact());
> > end
> >
> > rule "Test Rule"
> >     when
> >         $fact : TestFact()
> >     then
> >         System.out.println( "Hello" );
> >         Map<String,String> a = new HashMap<String,String>();
> >         modify ($fact) {setData("0")}
> > end
> >
> > I got the following error message:
> >
> > java.lang.RuntimeException: Error while creating KieBase[Message [id=1,
> > level=ERROR, path=rules/Sample.drl, line=18, column=0
> >    text=Unable to resolve type Map<String,String>:
> > Unable to find class 'Map<String,String>']]
> >       at
> >
> org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:260)
> >       at
> >
> org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:400)
> >       at
> >
> org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:375)
> >       at com.sample.DroolsTest.main(DroolsTest.java:17)
> >
> > However, if I remove "<String,String>" from "Map<String,String>", or
> remove
> > the "modify" line, the code is correct then.
> >
> > Thank you!
> >
> > Jinghai
> >
> >
> >
> >
> > --
> > View this message in context:
> >
> http://drools.46999.n3.nabble.com/Map-String-String-and-modify-can-t-be-together-tp4029591.html
> > Sent from the Drools: User forum mailing list archive at Nabble.com.
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20140517/813f3cc4/attachment.html 


More information about the rules-users mailing list