Bug 724229 (BRMS-173)

Summary: declaration of 2 variables in the init part of accumulate is not possible
Product: [JBoss] JBoss Enterprise BRMS Platform 5 Reporter: nwallace <nwallace>
Component: unspecifiedAssignee: Edson Tirelli <ed.tirelli>
Status: CLOSED NEXTRELEASE QA Contact:
Severity: unspecified Docs Contact:
Priority: high    
Version: unspecified   
Target Milestone: ---   
Target Release: 5.0.1   
Hardware: Unspecified   
OS: Unspecified   
URL: http://jira.jboss.org/jira/browse/BRMS-173
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-09-01 12:25:36 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description nwallace 2009-07-07 14:49:46 UTC
Date of First Response: 2009-09-10 01:22:02
securitylevel_name: Public

Take a rule with 2 variables int the init part, like
		$maxCa:CompanyCA() from accumulate($ca:CompanyCA($year:year) from $p.cas, 
										init(ecrm.party.CompanyCA currentCA=null;int maxYear = 0;),
										action(maxYear = Math.max(maxYear, $year);),
										result(currentCA)); 
which can return the year and the ca where the ca is max.

It won't compile with the error that company CA is not declare.

The bug is in the class org.drools.rule.builder.dialect.java.JavaAccumulateBuilder
line 194
            int index = 0;
            for ( Iterator it = initCodeAnalysis.getLocalVariablesMap().entrySet().iterator(); it.hasNext(); ) {
                Map.Entry entry = (Map.Entry) it.next();
                attributes[index] = (String) entry.getKey();
                attributesTypes[index] = ((JavaLocalDeclarationDescr) entry.getValue()).getType();
            }
when the variables are put in the context, only the first is put (index stay at 0)

We should increment the index
            int index = 0;
            for ( Iterator it = initCodeAnalysis.getLocalVariablesMap().entrySet().iterator(); it.hasNext(); ) {
                Map.Entry entry = (Map.Entry) it.next();
                attributes[index] = (String) entry.getKey();
                attributesTypes[index] = ((JavaLocalDeclarationDescr) entry.getValue()).getType();
                index ++;
            }

Comment 1 nwallace 2009-07-07 14:51:23 UTC
Link: Added: This issue is related to JBRULES-2058


Comment 2 nwallace 2009-09-01 12:25:36 UTC
Fix in place.

Comment 3 David Le Sage 2009-09-10 05:22:02 UTC
For documenting this in the Release Notes, can you please confirm the following and fill in the missing information. Dot point explanations are fine:

The CAUSE (what was actually broken)
 * There was a bug in the accumulate code.

CONSEQUENCES of the bug (how it impacts users.)
 * one could not declare two variables in the init part of accumulate.


The FIX (what was changed to eliminate this bug) and 
 *

RESULTS of the fix (what now happens for users.)
 * 

Comment 4 David Le Sage 2009-09-23 05:38:21 UTC
We are still awaiting the outstanding information for the Release Notes on this one.  Please provide it as soon as possible. Thanks.

Comment 5 Edson Tirelli 2009-09-23 13:53:46 UTC
The CAUSE (what was actually broken)
 * The code generation logic for java accumulate was broken when multiple variables were defined in the init block, causing compilation errors.

CONSEQUENCES of the bug (how it impacts users.)
 * one could not declare two variables in the init part of accumulate.

The FIX (what was changed to eliminate this bug) and
 * The code generation logic was fixed.

RESULTS of the fix (what now happens for users.)
 * Declaration of multiple variables in the init block of accumulate now works fine.

Comment 6 Dana Mison 2009-09-24 05:42:07 UTC
added to 5.0 CP01 release notes:

JBRULES-1871
Rules with multiple variables defined in the init block of java accumulate would fail to compile.  This is caused by a bug in JavaAccumulateBuilder where only the first variable would be read.  This is now fixed and these rules will compile successfully.