[jboss-jira] [JBoss JIRA] Created: (JBRULES-1517) NumberFormatException in ObjectEqualsComparator.equals

Brian Stiles (JIRA) jira-events at lists.jboss.org
Wed Mar 19 20:16:50 EDT 2008


NumberFormatException in ObjectEqualsComparator.equals 
-------------------------------------------------------

                 Key: JBRULES-1517
                 URL: http://jira.jboss.com/jira/browse/JBRULES-1517
             Project: JBoss Drools
          Issue Type: Bug
      Security Level: Public (Everyone can see)
    Affects Versions: 4.0.5
            Reporter: Brian Stiles
         Assigned To: Mark Proctor


It's not clear to me whether the ObjectFactory.ObjectEqualsComparator.equals implementation is incorrect or whether it is being used incorrectly, but it assumes that if the first argument is a Number and the second is a String, the second must be a number encoded as a string.  From the following example, you can see that this leads to a NumberFormatException in a valid rule.

--

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 EqualsProblem {

    public static class Foo {

        private final Object _prop;

        public Foo(Object value) {
            _prop = value;
        }

        public Object getProp() {
            return _prop;
        }

    }

    public static void main(String[] args) throws Exception {

        final PackageBuilderConfiguration packageBuilderConfiguration =
                new PackageBuilderConfiguration();
        final PackageBuilder packageBuilder = new PackageBuilder(packageBuilderConfiguration);

        packageBuilder.addPackageFromDrl(new StringReader("\n"
                + "package sample\n"
                + "\n"
                + "import java.lang.Integer;\n"
                + "import sample.EqualsProblem.Foo;\n"
                + "\n"
                + "rule MyRule\n"
                + "\n"
                + "    when\n"
                + "        $f : Foo(prop == \"\")\n"
                + "    then \n"
                + "        System.out.println($f);\n"
                + "end \n"));

        final RuleBaseConfiguration ruleBaseConfiguration = new RuleBaseConfiguration();
        final RuleBase ruleBase = RuleBaseFactory.newRuleBase(ruleBaseConfiguration);
        ruleBase.addPackage(packageBuilder.getPackage());
        final StatefulSession session = ruleBase.newStatefulSession();
        session.insert(new Foo(3));
        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