Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1072629

Summary: Behavioral bug in decision table
Product: [Retired] JBoss BRMS Platform 6 Reporter: David Tse <dtse>
Component: BREAssignee: Mario Fusco <mfusco>
Status: CLOSED CURRENTRELEASE QA Contact: Tomas Schlosser <tschloss>
Severity: high Docs Contact:
Priority: high    
Version: 6.0.2CC: dtse, kverlaen, mbaluch
Target Milestone: ER1   
Target Release: 6.0.2   
Hardware: i586   
OS: Windows   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-08-06 19:54:32 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:
Embargoed:
Attachments:
Description Flags
First attachment
none
2nd attachment
none
Compilation issues in BRMS6 associated with using inheritance
none
jUnit reproducer with plain DRL
none
Decision tables modified to exclude undesired facts none

Description David Tse 2014-03-04 23:14:13 UTC
Created attachment 870704 [details]
First attachment

Description of problem:
The rule of inheritance dictated that sub-class should override super class.
For decision table, super class is overriding sub-class.  This is a behavioral bug in decision table.


Version-Release number of selected component (if applicable):
6.0.0.GA


How reproducible:
Occur every time

Steps to Reproduce:
1. Unzip and Import amentra-cdi and amentra-cdi-inheritance
2. Run QATest2.java in amentra-cdi
3. Run QATest2.java in amentra-cdi-inheritance
#2 gives the expected results
#3 gives the actual results because BRE is treating the subclass as its superclass.

Actual results:
Open QATest2.txt
6	fail
5	success
4	fail
3	fail
2	fail
1	fail


Expected results:
Open QATest2.txt
6	success
5	success
4	success
3	success
2	success
1	success


Additional info:
May be able to use template to resolve this issue in the mean time.

Comment 1 David Tse 2014-03-04 23:16:53 UTC
How to add second attachment?

Second attachment is in https://mojo.redhat.com/docs/DOC-940004

Comment 2 David Tse 2014-03-04 23:17:36 UTC
Created attachment 870705 [details]
2nd attachment

Comment 4 Edson Tirelli 2014-03-05 15:10:26 UTC
We will investigate this. Can you clarify if this is a customer support case or a regular ticket caught on internal tests?

Comment 5 David Tse 2014-03-05 17:22:13 UTC
Customer want to use inheritance in decision table.  Inheritance works with drl.  We may be able to use template in the mean time and lower the priority.

Comment 6 Mario Fusco 2014-03-25 11:23:41 UTC
The provided test case is quite huge and then it is a bit difficult to figure out what's going wrong. Anyway my current understanding is the following: in the amentra-cdi-inheritance test AllocatedCashflow extends TypedCashflow that in turn extends Cashflow. In this way, since AllocatedCashflow is both a TypedCashflow and a Cashflow, ALL the rules defined in CashflowDT, TypedCashflowDT and AllocatedTypedCashflowDT fire on the same AllocatedCashflow instances inserted in the session. Even worse they do so in an unpredictable order modifying the same AllocatedCashflow instance multiple times, so at the end of this process it is virtually impossible to say what is the actual amount of a given cashflow. This is why the test is failing and indeed excluding CashflowDT and TypedCashflowDT makes it to succeed. 

To recap I think the test case is flawed because it doesn't take into account that if B extends A, BOTH rules constraining A and B are eligible to be fired and not only the ones related to B.

If my analysis is correct please close this ticket as invalid, otherwise feel free to explain in a bit more details how this test case is supposed to work or even better to provide a bit more isolated test case demonstrating this issue.

Comment 7 David Tse 2014-03-26 16:11:20 UTC
Your analysis is incorrect.  BRMS6 is up classing sub class to super class.

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.947 sec <<< FAILURE! - in com.amentra.brms.cdi.SimpleDateTest
test1(com.amentra.brms.cdi.SimpleDateTest)  Time elapsed: 3.902 sec  <<< ERROR!
java.lang.RuntimeException: Error while creating KieBase[Message [id=1, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=167, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=2, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=50, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=3, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=32, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=4, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=14, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=5, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=77, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=6, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=95, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=7, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=149, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=8, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=158, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=9, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=113, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=10, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=5, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=11, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=131, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=12, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=23, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=13, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=68, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=14, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=86, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=15, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=41, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=16, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=140, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=17, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=176, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=18, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=104, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=19, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=59, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date], Message [id=20, level=ERROR, path=com/amentra/brms/fact/SimpleDateDT.xls, line=122, column=0
   text=Rule Compilation error The method setStatus(String) is undefined for the type Date
The method setDateString(String) is undefined for the type Date]]
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:336)
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:481)
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:456)
	at org.drools.compiler.cdi.KieCDIExtension$StatefulKSessionBean.create(KieCDIExtension.java:825)
	at org.drools.compiler.cdi.KieCDIExtension$StatefulKSessionBean.create(KieCDIExtension.java:768)
	at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
	at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90)
	at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104)
	at org.jboss.weld.proxies.KieSession$1366014918$Proxy$_$$_WeldClientProxy.setGlobal(KieSession$1366014918$Proxy$_$$_WeldClientProxy.java)
	at com.amentra.brms.cdi.AmentraCDI.execute(AmentraCDI.java:21)
	at com.amentra.brms.cdi.SimpleDateTest.test1(SimpleDateTest.java:30)

I will attach a second archive and you take a second look at the issues

Comment 8 David Tse 2014-03-26 16:38:55 UTC
Created attachment 879120 [details]
Compilation issues in BRMS6 associated with using inheritance

The BRMS6 is up-classing sub-class to its super-class.  See SimpleDateDT and SimpleDate.java.

Comment 9 Marek Winkler 2014-03-26 19:37:38 UTC
I can confirm that I reproduced this issue. Oddly enough, the build fails only when the fact class (SimpleDate) is a subclass of java.util.Date; when I created the following wrapper class:

import java.io.Serializable;
import java.util.Date;

public class MyDate implements Serializable {

    private final Date wrappedDate;

    public MyDate() {
        this.wrappedDate = new Date();
    }

    public void setTime(final long millis) {
        this.wrappedDate.setTime(millis);
    }
}

and made SimpleDate from the reproducer extend MyDate, instead of java.util.Date, the compilation succeeded.

Comment 10 Marek Winkler 2014-03-27 08:27:46 UTC
Created attachment 879352 [details]
jUnit reproducer with plain DRL

I reproduced the problem without decision tables using DRL only. Attaching reproducer.

Comment 11 Mario Fusco 2014-03-27 09:48:30 UTC
Marek reproduced the compilation problem reported by David in his comment #7 in pure DRL, without using any dtable, and I fixed it with this commit https://github.com/droolsjbpm/drools/commit/36c5478d3 

However this fix only applies to a very specific case, i.e. the extension of the java.util.Date class. This together with 2 other evidences:

1. the bug was reproducible also with plain DRL
2. the bug caused a compilation error and not a silent misbehaviour 

makes me think that the issue I fixed is totally unrelated with the originally reported problem. For that regard I strongly believe that what I wrote in my comment #6 is still perfectly valid.

Comment 12 Mario Fusco 2014-03-27 09:49:19 UTC
Cherry-picked to 6.0.x with https://github.com/droolsjbpm/drools/commit/b4260e6e3

Comment 13 Marek Winkler 2014-03-27 10:19:54 UTC
Created attachment 879389 [details]
Decision tables modified to exclude undesired facts

I have modified the decision tables from David's test from comment #2 to exclude subclasses from the rules which probably should not apply to them (as explained by Mario in comment #6), for example:

 index == $param && !(this instanceof com.amentra.brms.fact.AllocatedCashflow)

With the modified decision tables, the tests pass now:

QATest2.txt:
6	 success
5	 success
4	 success
3	 success
2	 success
1	 success

I believe this confirms Mario's original comment. I am attaching the modified decision tables. David, could you please validate that it works for you?

Comment 14 David Tse 2014-04-04 14:53:28 UTC
Mario, Marek.  Thanks. The solution works.

Comment 15 Tomas Schlosser 2014-04-29 12:46:16 UTC
The bug with extending java.util.Date is gone (verified with 6.0.2 ER2).
The original bug was solved as well. Therefore I mark this as VERIFIED.