[rules-users] Internal type used together with function throws ClassCastException

Edson Tirelli tirelli at post.com
Mon Mar 16 18:34:22 EDT 2009


   Michal,

   Are you using trunk or CR1?

   I found a bug last Saturday that I believe is the exact same one you
found here. Mark fixed it on trunk. So, if you are not using trunk, can you
do it and let us know if it is working for you?

   Thanks,
      Edson

2009/3/16 Michal Bali <michalbali at gmail.com>

> Hi,
>
> Internal type together with a function in one drl file cause
> ClassCastException when setting properties of a new instance of this type.
>
> java.lang.ClassCastException: org.drools.generatedbeans.Cheese cannot be
> cast to org.drools.generatedbeans.Cheese
>     at
> org.drools.base.org.drools.generatedbeans.Cheese6778431$setType.setValue(Unknown
> Source)
>     at org.drools.base.ClassFieldWriter.setValue(ClassFieldWriter.java:195)
>     at
> org.drools.base.ClassFieldAccessor.setValue(ClassFieldAccessor.java:319)
>     at org.drools.factmodel.ClassDefinition.set(ClassDefinition.java:207)
>     at
> org.drools.integrationtests.MiscTest.testGeneratedBeansWithFunction(MiscTest.java:1072)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke(Method.java:616)
>     at junit.framework.TestCase.runTest(TestCase.java:154)
>     at junit.framework.TestCase.runBare(TestCase.java:127)
>     at junit.framework.TestResult$1.protect(TestResult.java:106)
>     at junit.framework.TestResult.runProtected(TestResult.java:124)
>     at junit.framework.TestResult.run(TestResult.java:109)
>     at junit.framework.TestCase.run(TestCase.java:118)
>     at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
>     at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>     at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
>     at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
>     at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
>     at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
>
>
> Test case to reproduce:
> test_GeneratedBeansWithFunction.drl:
> -------------------------------
> package org.drools.generatedbeans;
>
> function void someFunction(String arg) {
>     System.out.println("hello");
> }
>
> declare Cheese
>     type: String
> end
> -------------------------------
>
> test method:
> public void testGeneratedBeansWithFunction() throws Exception {
>         final KnowledgeBuilder kbuilder =
> KnowledgeBuilderFactory.newKnowledgeBuilder();
>         kbuilder.add( ResourceFactory.newInputStreamResource(
> getClass().getResourceAsStream( "test_GeneratedBeansWithFunction.drl" ) ),
>                       ResourceType.DRL );
>         assertFalse( kbuilder.getErrors().toString(),
>                      kbuilder.hasErrors() );
>
>         KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
>         kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
>
>         // Retrieve the generated fact type
>         FactType cheeseFact = kbase.getFactType(
> "org.drools.generatedbeans",
>                                                  "Cheese" );
>
>         // Create a new Fact instance
>         Object cheese = cheeseFact.newInstance();
>
>         cheeseFact.set( cheese,
>                         "type",
>                         "stilton" );
>     }
>
> The last line throws the ClassCastException. If we remove the function from
> the drl file all works fine.
> Best Regards,
> Michal
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>


-- 
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090316/b8959941/attachment.html 


More information about the rules-users mailing list