Bug 851310 - Drools cannot resolve functions when argument is a fact type
Drools cannot resolve functions when argument is a fact type
Product: JBoss Enterprise BRMS Platform 5
Classification: JBoss
Component: BRM (Guvnor) (Show other bugs)
BRMS 5.3.1
Unspecified Unspecified
unspecified Severity unspecified
: ER2
: BRMS 5.3.1 GA
Assigned To: Mario Fusco
Tomas Schlosser
Depends On:
  Show dependency treegraph
Reported: 2012-08-23 14:27 EDT by Mario Fusco
Modified: 2013-10-10 20:17 EDT (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
The business rules engine could not resolve functions when a declared type was used as an argument for a function and resulted in compilation failure. This has been resolved by loading the Java Class corresponding to the declared type when compiling the function. It is now possible to use a declared type as an argument for a function.
Story Points: ---
Clone Of:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Repository export (3.06 KB, application/zip)
2012-09-17 07:00 EDT, Tomas Schlosser
no flags Details
Error messages (124.13 KB, image/png)
2012-09-17 10:26 EDT, Tomas Schlosser
no flags Details

External Trackers
Tracker ID Priority Status Summary Last Updated
JBoss Issue Tracker JBRULES-3562 Major Resolved Drools cannot resolve functions when argument is a fact type 2016-04-04 16:55 EDT

  None (edit)
Description Mario Fusco 2012-08-23 14:27:02 EDT

Comment 1 Tomas Schlosser 2012-09-17 05:27:20 EDT
Tested on brms-standalone-5.3.0 and the problem described in JIRA still occurs.
Comment 3 Mario Fusco 2012-09-17 06:18:08 EDT
This issue should have been fixed only on the 5.3.1.ER1 indeed.
Could you please verify?
Comment 4 Tomas Schlosser 2012-09-17 06:30:08 EDT
I did try with brms-standalone-5.3.1 I just wrote the comment wrong. Sorry about confusion.
Comment 5 Mario Fusco 2012-09-17 06:34:51 EDT
It works for me. Could you please attach the test you used to verify it?
Comment 6 Tomas Schlosser 2012-09-17 07:00:45 EDT
Created attachment 613628 [details]
Repository export

I manually created this repository to verify bug. It is impossible to build the testPackage.
Comment 7 Mario Fusco 2012-09-17 09:51:13 EDT
That repository works for me. Also I added a further unit test in the code base of the 5.3.x branch using exactly the same DRL generated by that repository and it passes without any problem. I am pasting the source code of that test below:

    public void testMvelFunctionWithDeclaredTypeArg() {
        // JBRULES-3562
        String rule = "package testPackage\n" +
                "declare Person\n" +
                "name: String\n" +
                "age: Integer\n" +
                "end\n" +
                "\n" +
                "function String PersonToString(Person p) {\n" +
                "String result = \"\";\n" +
                "result = p.getName() + \", age: \" + p.getAge();\n" +
                "return result;\n" +
                "}\n" +
                "\n" +
                "rule \"testRule1\"\n" +
                "dialect \"mvel\"\n" +
                "when\n" +
                "p : Person( )\n" +
                "then\n" +
                "System.out.println(PersonToString(p));\n" +
                "end\n" +
                "\n" +
                "rule 'testRule2'\n" +
                "dialect 'mvel'\n" +
                "when\n" +
                "$p : Person()\n" +
                "then\n" +
                "System.out.println(PersonToString($p));\n" +

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        kbuilder.add( ResourceFactory.newByteArrayResource(rule.getBytes()), ResourceType.DRL );

        if ( kbuilder.hasErrors() ) {
            fail( kbuilder.getErrors().toString() );

        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
Comment 8 Tomas Schlosser 2012-09-17 10:26:16 EDT
Created attachment 613683 [details]
Error messages

I tried again with this [1] version of BRMS using these steps:
1) imported repository
2) opened testPackage
3) tried to build

All I got is attached exception (including BRMS version for clarity).

[1] http://jawa05.englab.brq.redhat.com/candidate/BRMS-5.3.1-ER1/brms-p-5.3.1.ER1-standalone.zip
Comment 9 Mario Fusco 2012-09-17 11:06:49 EDT
Sorry, but I am really not able to reproduce this issue- I don't know how to proceed about it.
Comment 10 Tomas Schlosser 2012-09-25 07:22:06 EDT
I had a colleague of mine trying the same thing and we got the exactly same behaviour as I did.
Are you sure, you tried importing the repository into BRMS-5.3.1-ER1? I used the standalone version as it works out of the box, could you please try to download and run the same?
Comment 11 Mario Fusco 2012-09-27 08:08:48 EDT
I reproduced the problem, but now it seems a Guvnor issue, so I talked to Toni and assigned this ticket to him.
Comment 12 Toni Rikkola 2012-09-28 09:52:24 EDT
I managed to isolate what Guvnor does in this unit test:

    public void testMvelFunctionWithDeclaredTypeArg2() throws IOException, DroolsParserException {

        String function = "function String getFieldValue(Bean bean) {" +
                "   return bean.getField();" +
        String declaredFactType = "declare Bean \n" +
                "   field : String \n" +
                "end \n";
        String rule = "rule R2 \n" +
                "dialect 'mvel'\n" +
                "when \n" +
                "   $bean : Bean( ) \n" +
                "then \n" +
                "   System.out.println( getFieldValue($bean) ); \n" +

        PackageBuilder packageBuilder = new PackageBuilder();
        packageBuilder.addPackageFromDrl(new StringReader(declaredFactType));
        packageBuilder.addPackageFromDrl(new StringReader(function));
        packageBuilder.addPackageFromDrl(new StringReader(rule));

        for (KnowledgeBuilderError error : packageBuilder.getErrors()) {

Currently the test fails to pass. If the dialect for the Rule R2 is removed it works.

There are few solutions: 

#1 We remove the PackageBuilder from Guvnor and replace it with KnowledgeBuilder. This is a not a small task and will take a week or more.

#2 We make PackageBuilder work with how Guvnor is using it. 

Mario is taking a look at #2. Hopefully there is an easy fix.
Comment 13 Toni Rikkola 2012-09-28 12:52:54 EDT
#2 is not easy.

I have an idea that might work, but the problem is that it will change how Guvnor packages are being built. So there is a possibility that the end result will not be 100% the same as before.
Comment 14 Mario Fusco 2012-09-30 12:56:57 EDT
Thank to the test provided by Toni, I've been able to fix this issue in Drools (no need to change Guvnor). Toni also helped me to check that the attached repository export compiles without error now.
Comment 15 Tomas Schlosser 2012-10-08 07:51:15 EDT
In BRMS-5.3.1-ER2 the problem is gone. Thank you

Note You need to log in before you can comment on or make changes to this bug.