[jboss-jira] [JBoss JIRA] (DROOLS-410) Problem with inheritance
Michaël Mathieu (JIRA)
issues at jboss.org
Tue Jan 21 07:06:28 EST 2014
Michaël Mathieu created DROOLS-410:
--------------------------------------
Summary: Problem with inheritance
Key: DROOLS-410
URL: https://issues.jboss.org/browse/DROOLS-410
Project: Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Reporter: Michaël Mathieu
Assignee: Mark Proctor
For a very simple rule, with same parameter, the result is sometimes different.
There's a problem with inheritance.
{code}
package test;
public class ARef {
private String ref;
protected ARef(String ref) {
this.ref = ref;
}
public static ARef valueOf(String ref) {
System.out.println("ARef> " + ref);
return new ARef(ref);
}
@Override
public String toString() {
return ref;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((ref == null) ? 0 : ref.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
ARef other = (ARef) obj;
if (ref == null) {
if (other.ref != null) return false;
} else if (!ref.equals(other.ref)) return false;
return true;
}
}
{code}
{code}
package test;
public class BRef extends ARef {
private BRef(String ref) {
super(ref);
}
public static BRef valueOf(String ref) {
System.out.println("BRef> " + ref);
return new BRef(ref);
}
}
{code}
{code}
package test;
public class Criteria {
private BRef ref;
private boolean ok = false;
public Criteria(BRef ref) {
this.ref = ref;
}
public BRef getRef() {
return ref;
}
public boolean isOk() {
return ok;
}
public void setOk() {
this.ok = true;
}
}
{code}
{code}
package test;
import java.io.StringReader;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.StatelessSession;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;
public class Test {
private static final String DRL = "package test\r\n" + "dialect \"mvel\"\r\n" + "import test.*;\r\n" + "rule \"myRule\"\r\n" + "when\r\n"
+ " criteria:Criteria(ref == BRef.valueOf(\"toto\"))\r\n" + "then\r\n" + " criteria.setOk();\r\n" + "end";
public static void main(String[] args) {
System.out.println(DRL);
try {
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(new StringReader(DRL));
Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(pkg);
for (int i = 0; i < 1000; i++) {
Criteria criteria = new Criteria(BRef.valueOf("toto"));
StatelessSession session = ruleBase.newStatelessSession();
session.execute(criteria);
System.out.println("[" + i + "] " + criteria.isOk());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
{code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list