JESS: JessLong Illegal argument exception

View: New views
5 Messages — Rating Filter:   Alert me  

JESS: JessLong Illegal argument exception

by Brian Rogosky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hello,

I’m experiencing an “Illegal Argument” exception when calling the “long” function.  It appears to only happen with one particular number 1157650583 out of hundreds of thousands used.  The number is stored in a slot of Float type.  This number works fine in a test environment with a simple call to the function with the exact number, i.e. (long 1157650583).  However the exception fires with the full set of code in the production environment where I am running Jess 7.0p2 and Java 5.  In production, a call to the Java Long class to do the conversion of the same number works fine, but the Jess long call always fails.  I’ve listed the log output below.

 

Has anyone seen a problem like this?  I have not yet put the code into an environment where I can run a debugger over it but I am considering it.  I am also considering replacing the Jess long call with a call to Long.longValue(). 

 

**** log output ****

 

debugging city id = 1157650583

 

*** call to Java Long works fine *** [Thread-1] DEBUG - In provider-default rule in country.clp: (new java.lang.Long ?city) longValue = 1157650583

 

*** call to (long ?city) throws an exception *** [Thread-1] ERROR -

Jess reported an error in routine long

      while executing (long ?city)

      while executing (printout debug "In provider-default rule in country.clp: It will fail HERE: (long ?city) = " (long ?city) crlf)

      while executing defrule provider-default::provider-default.

  Message: Illegal argument 1157650583.

      at jess.JessLong.call(Unknown Source)

      at jess.FunctionHolder.call(Unknown Source)

      at jess.Funcall.execute(Unknown Source)

      at jess.FuncallValue.resolveValue(Unknown Source)

      at jess.Printout.call(Unknown Source)

      at jess.FunctionHolder.call(Unknown Source)

      at jess.Funcall.execute(Unknown Source)

      at jess.Defrule.fire(Unknown Source)

      at jess.Activation.fire(Unknown Source)

      at jess.Agenda.run(Unknown Source)

      at jess.Agenda.run(Unknown Source)

      at jess.Rete.run(Unknown Source)

      at jess.Rete.run(Unknown Source)

      at com.quova.research.Jessengine.JessRuleAlgorithm.process(JessRuleAlgorithm.java:152)

      at com.quova.research.handler.HandlerImpl.run(HandlerImpl.java:185)

      at com.quova.research.service.NetworkServiceImpl.processNetworkRequest(NetworkServiceImpl.java:36)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

 

Thanks in advance,

Brian

 

 

 


Re: JESS: JessLong Illegal argument exception

by Ernest Friedman-Hill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jun 8, 2009, at 8:19 PM, Brian Rogosky wrote:

> Hello,
> I’m experiencing an “Illegal Argument” exception when calling the  
> “long” function.


Hi Brian,

It'll only throw that exception if the argument isn't a number,  
string, or symbol. For example, a list value with a single number in  
it would produce the error you're seeing; the list would display  
without parens in the error message:

Jess> (long (list 123))
Jess reported an error in routine long
        while executing (long (list 123)).
   Message: Illegal argument 123.
   Program text: ( long ( list 123 ) )  at line 1.

Since it looks like you are able to add a debug print at the point of  
failure, try something like

(printout t "The bad value is of type " (jess-type ?city) crlf)

If it prints anything other than INTEGER, FLOAT, STRING, SYMBOL, or  
FACT, then there's the problem.




---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


RE: JESS: JessLong Illegal argument exception

by Brian Rogosky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ernest,
Great suggestion! It returned type "LONG".  I can see the JessLong class
that implements the Jess function long does not list RU.Long as a type
to be converted, and I must admit I'm a bit perplexed by this.  The
tooltip documentation for the long function states that Jess now allows
long literals.  My reason for using the long function was to convert the
data from a variable of some type (usually float but now obviously
sometimes a long) to a long to be passed to a Java method. The Java
method expects a Java long (primitive type) and I'm using Java 5. Is
this function no longer needed for this usage with Jess 7 onwards?

In any case, I now have several ideas how to fix this.  

For completeness, here is an example showing the behavior and use of
Long.longValue():

(deftemplate x "blah"
    (slot name)
        (slot num (type FLOAT))
    (slot numConverted (default 0)(type LONG))
    )


(defrule convertJessLong
   
    ?xfact <- (x (num ?num) (numConverted ?numConv&:(= ?numConv 0)))
    =>
    (printout t "The value is of type " (jess-type ?num) crlf)
    (modify ?xfact (numConverted (long ?num)) ))

(reset)
(assert (x (name "long from Java Long.longValue")(num ((new Long
1157650583) longValue))))

--
Jess, the Rule Engine for the Java Platform
Copyright (C) 2008 Sandia Corporation
Jess Version 7.1p2 11/5/2008

MAIN::convertJessLong: +1+1+1+t
 ==> Focus MAIN
 ==> f-0 (MAIN::initial-fact)
 ==> f-1 (MAIN::x (name "long from Java Long.longValue") (num
1157650583) (numConverted 0))
==> Activation: MAIN::convertJessLong :  f-1
FIRE 1 MAIN::convertJessLong f-1
The value is of type LONG
Jess reported an error in routine long
        while executing (long ?num)
        while executing (modify ?xfact (numConverted (long ?num)))
        while executing defrule MAIN::convertJessLong
        while executing (run).
  Message: Illegal argument 1157650583.
  Program text: ( run )  at line 48 in file
C:\dev\BrianSamples\src\debug-jess-long\testJessLong.clp.
f-0   (MAIN::initial-fact)
f-1   (MAIN::x (name "long from Java Long.longValue") (num 1157650583)
(numConverted 0))
For a total of 2 facts in module MAIN.

Thanks,
Brian

-----Original Message-----
From: owner-jess-users@... [mailto:owner-jess-users@...]
On Behalf Of Ernest Friedman-Hill
Sent: Monday, June 08, 2009 5:41 PM
To: jess-users
Subject: Re: JESS: JessLong Illegal argument exception


On Jun 8, 2009, at 8:19 PM, Brian Rogosky wrote:

> Hello,
> I'm experiencing an "Illegal Argument" exception when calling the  
> "long" function.


Hi Brian,

It'll only throw that exception if the argument isn't a number,  
string, or symbol. For example, a list value with a single number in  
it would produce the error you're seeing; the list would display  
without parens in the error message:

Jess> (long (list 123))
Jess reported an error in routine long
        while executing (long (list 123)).
   Message: Illegal argument 123.
   Program text: ( long ( list 123 ) )  at line 1.

Since it looks like you are able to add a debug print at the point of  
failure, try something like

(printout t "The bad value is of type " (jess-type ?city) crlf)

If it prints anything other than INTEGER, FLOAT, STRING, SYMBOL, or  
FACT, then there's the problem.




---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify
owner-jess-users@....
--------------------------------------------------------------------



--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


Re: JESS: JessLong Illegal argument exception

by Ernest Friedman-Hill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Jun 10, 2009, at 7:43 PM, Brian Rogosky wrote:

> Hi Ernest,
> Great suggestion! It returned type "LONG".  I can see the JessLong  
> class
> that implements the Jess function long does not list RU.Long as a type
> to be converted, and I must admit I'm a bit perplexed by this.  The
> tooltip documentation for the long function states that Jess now  
> allows
> long literals.

I would say that's an oversight; just because it's not a useful  
conversion doesn't mean it can't just pass the value through. We have  
a 7.1p3 release coming up soon, so I'll make sure this gets fixed for  
that. Thanks for the report.

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


RE: JESS: JessLong Illegal argument exception

by Brian Rogosky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks.  

Based on your comments, I was able to patch the current production and
development versions I'm using (7.0p2 and 7.1p2).  
I also created a Java unit test for the fix. If anyone on this list is
interested in the details, let me know.

Brian

-----Original Message-----
From: owner-jess-users@... [mailto:owner-jess-users@...]
On Behalf Of Ernest Friedman-Hill
Sent: Wednesday, June 10, 2009 9:06 PM
To: jess-users
Subject: Re: JESS: JessLong Illegal argument exception

On Jun 10, 2009, at 7:43 PM, Brian Rogosky wrote:

> Hi Ernest,
> Great suggestion! It returned type "LONG".  I can see the JessLong  
> class
> that implements the Jess function long does not list RU.Long as a type
> to be converted, and I must admit I'm a bit perplexed by this.  The
> tooltip documentation for the long function states that Jess now  
> allows
> long literals.

I would say that's an oversight; just because it's not a useful  
conversion doesn't mean it can't just pass the value through. We have  
a 7.1p3 release coming up soon, so I'll make sure this gets fixed for  
that. Thanks for the report.

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify
owner-jess-users@....
--------------------------------------------------------------------



--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------