[jboss-jira] [JBoss JIRA] Assigned: (JBRULES-977) Foo(this != $i) fails when using ShadowProxy
Edson Tirelli (JIRA)
jira-events at lists.jboss.org
Tue Jul 10 12:47:34 EDT 2007
[ http://jira.jboss.com/jira/browse/JBRULES-977?page=all ]
Edson Tirelli reassigned JBRULES-977:
-------------------------------------
Assignee: Edson Tirelli (was: Mark Proctor)
> Foo(this != $i) fails when using ShadowProxy
> --------------------------------------------
>
> Key: JBRULES-977
> URL: http://jira.jboss.com/jira/browse/JBRULES-977
> Project: JBoss Rules
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Affects Versions: 4.0.0.MR4
> Reporter: Brian Stiles
> Assigned To: Edson Tirelli
>
> The self reference field "this" doesn't behave as expected when shadow proxies are used.
> when
> $i : Foo()
> Foo(this != $i)
> the above always fires.
> The following code exhibits the problem.
> --------
> /*
> * Created on Apr 26, 2007
> */
> package sample;
> import java.io.StringReader;
> import org.drools.RuleBase;
> import org.drools.RuleBaseConfiguration;
> import org.drools.RuleBaseFactory;
> import org.drools.StatefulSession;
> import org.drools.compiler.PackageBuilder;
> import org.drools.compiler.PackageBuilderConfiguration;
> public class ThisProblem {
> public static class Foo {
> private final int _number;
> public Foo(int number) {
> _number = number;
> }
> public int getNumber() {
> return _number;
> }
> public int hashCode() {
> return _number;
> }
> public boolean equals(Object obj) {
> if (obj == this) {
> return true;
> }
> if (obj instanceof Foo) {
> final Foo other = (Foo) obj;
> return _number == other._number;
> }
> return false;
> }
> public String toString() {
> return String.valueOf(_number);
> }
> }
> public static void main(String[] args) throws Exception {
> fail();
> System.out.println("********************************************");
> succeed();
> }
> private static void fail() throws Exception {
> test(true);
> }
> private static void succeed() throws Exception {
> test(false);
> }
> private static void test(boolean useShadowProxy) throws Exception {
> final PackageBuilderConfiguration packageBuilderConfiguration =
> new PackageBuilderConfiguration();
> final PackageBuilder packageBuilder = new PackageBuilder(packageBuilderConfiguration);
> packageBuilder.addPackageFromDrl(new StringReader("\n"
> + "package sample\n"
> + "\n"
> + "import sample.ThisProblem.Foo;"
> + "\n"
> + "rule MyRule\n"
> + " dialect \"java\"\n"
> + "\n"
> + " when\n"
> + " $i : Foo()\n"
> + " $k : Foo(this != $i)\n"
> + " then \n"
> + " System.out.println(\"-------------\");\n"
> + " System.out.println($i + \": \" + System.identityHashCode($i));\n"
> + " System.out.println($k + \": \" + System.identityHashCode($k));\n"
> + "end \n"));
> final RuleBaseConfiguration ruleBaseConfiguration = new RuleBaseConfiguration();
> ruleBaseConfiguration.setShadowProxy(useShadowProxy);
> final RuleBase ruleBase = RuleBaseFactory.newRuleBase(ruleBaseConfiguration);
> ruleBase.addPackage(packageBuilder.getPackage());
> final StatefulSession session = ruleBase.newStatefulSession();
> session.insert(new Foo(1));
> session.fireAllRules();
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list