[rules-users] Problem with mvel trying to coerce a String to a number

Brett M. Bergquist brett at thebergquistfamily.com
Wed Apr 2 14:59:03 EDT 2008


I have a fact that a Map of Strings:

    private Map<String,String> property = new HashMap<String,String>();

    /**
     * Gets the property map
     * @return The property map
     */
    public Map<String, String> getProperty() {
        return property;
    }

    /**
     * Sets the property map
     * @param property The new property map
     */
    public void setProperty(Map<String, String> property) {
        this.property = property;
    }
   
Inside a rule, I am trying to use this map and the rule looks like:

    rule "3-new Notificationcp9145Authentication"
        when
            notification : Notificationcp9145Authentication($againstId :
    targetID,
                                                           
    $badHostString : badHostString,
                                                           
    $applicationName : applicationName)
            not AlarmEventFact(type == AlarmType.ACTIVE,
                               alarmName == "cp9145Authentication",
                               againstId == $againstId,
                               property['badHostString'] == $badHostString,
                               property['applicationName'] ==
    $applicationName
                               )
        then
            alarmEventKnowledge.create(drools, notification,
    "cp9145Authentication",
                                        new Pair("badHostString",
    $badHostString),
                                        new Pair("applicationName",
    $applicationName));

    end

The problem that I am having is that the result of the lookup of 
"property['badHostString']" is a string that looks like "192.168.1.19" 
(an IP address).  The "badHostString" property of the 
Notificationcp9145Authentication fact is a String.  I am getting an 
error when the rule is fired.  It appears that the 
"property['badHostString']" is trying to be interpreted as a number.  
Here is some of the stack traceback:

    Caused by: java.lang.NumberFormatException
            at java.math.BigDecimal.<init>(BigDecimal.java:362)
            at java.math.BigDecimal.<init>(BigDecimal.java:647)
            at
    org.mvel.math.IEEEFloatingPointMath.getBigDecimalFromType(IEEEFloatingPointMath.java:373)
            at
    org.mvel.math.IEEEFloatingPointMath._doOperations(IEEEFloatingPointMath.java:83)
            at
    org.mvel.math.IEEEFloatingPointMath.doOperation(IEEEFloatingPointMath.java:40)
            at org.mvel.util.ParseTools.doOperations(ParseTools.java:753)
            at
    org.mvel.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:20)
            at org.mvel.MVELRuntime.execute(MVELRuntime.java:87)
            at
    org.mvel.CompiledExpression.getValue(CompiledExpression.java:98)
            at org.mvel.MVEL.executeExpression(MVEL.java:202)
            at
    org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.java:36)       
    at
    org.drools.rule.PredicateConstraint.isAllowedCachedLeft(PredicateConstraint.java:206)

If I change the property value to be something like "abc" then this does 
not occur, so I am pretty user that it is trying to convert 
"192.168.1.19" to a number even though it is already a string and the 
$badHostString is a String as well.

How can I force this to not try to convert?

Any help will be greatly appreciated.



More information about the rules-users mailing list