cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Igor Bukanov <i...@fastmail.fm>
Subject Re: Rhino Usage Warning
Date Wed, 17 Nov 2004 17:29:46 GMT

[Cross-posted to netscape.public.mozilla.jseng: see below]

Jeremy Quinn wrote:
> On 17 Nov 2004, at 06:35, Reinhard Poetz wrote:
> 
>> Jeremy Quinn wrote:
>>
>>> On 16 Nov 2004, at 13:02, Reinhard Poetz wrote:
>>>
>>>> Jeremy Quinn wrote:
>>>>
>>>>> Hi All,
>>>>> I am getting this message appearing in my console for Cocoon 
>>>>> 2.2.0-dev :
>>>>> "file:/Users/jerm/Development/Checkouts/Apache/Cocoon/trunk/build/ 
>>>>> webapp/samples/blocks/querybean/flow/QueryHistory.js", line 25: 
>>>>> RHINO  USAGE WARNING: Missed Context.javaToJS() conversion:
>>>>> Rhino runtime detected object  
>>>>> [org.apache.cocoon.bean.query.SimpleLuceneQueryBean@bd9c37] of 
>>>>> class  java.util.ArrayList where it expected String, Number, 
>>>>> Boolean or  Scriptable instance. Please check your code for missig  
>>>>> Context.javaToJS() call.
>>>>> The code in question is this:
>>>>> 21: // QueryHistory Object Constructor
>>>>> 22: function QueryHistory(attribute_name) {
>>>>> 23:     try {
>>>>> 24:         this._history = 
>>>>> cocoon.session.getAttribute(attribute_name);
>>>>> 25:         if (this._history == null) {
>>>>> 26:             this._history = new ArrayList();
>>>>> 27:             cocoon.session.setAttribute(attribute_name, 
>>>>> this._history);
>>>>> 28:         }
>>>>> 29:     } catch (error) {
>>>>> 30:         cocoon.log.error(error);
>>>>> 31:     }
>>>>> 32: }
>>>>> The history list is an ArrayList of SimpleLuceneQueryBean(s).
>>>>> Am I doing something wrong, or is this an issue with the new Rhino  
>>>>> FlowScript?
>>>>> Thanks
>>>>> regards Jeremy
>>>>
>>>>
>>>>
>>>> Have you been able to solve the problem?
>>>
>>> No
> 
> 
> I failed to mention that the js actually runs fine, I just get this 
> warning message filling up the console though.
> 
>> found this: http://article.gmane.org/gmane.comp.mozilla.devel.jseng/2791
>>
>> Maybe Igor can tell us more ...
> 
> 
> I hope so.

Please post Rhino-related questions to netscape.public.mozilla.jseng 
newsgroup (which is available at least through news.mozilla.org or 
google news).

I look at dev@cocoon.apache.org maillist only occasinaly.

> 
> The code I am using works fine in 'BRANCH_2_1_X' but gives this error 
> only in 'trunk'. I believe 'trunk' is the only one to have the new Rhino 
> implementation, no?
> 
> So my understanding is that this is due somehow to the new infrastructure.

Note that this is not an error, but rather warning and indicate a 
problem with usage of Rhino API. The story behind it  is the following:

Rhino runtime uses String, Number and Boolean to implement corresponding 
JavaScript primitive types and org.mozilla.javascript.Scriptable 
interface for JavaScript objects. Moreover, Rhino runtime expects that 
only instances of String, Number, Boolean and Scriptable should be 
stored in JS objects, variables, runtime stack etc.

It means that before passing any Java object that is not an instance of 
the above types to Rhino API it should be properly wrapped.
Unfortunately it is easy to forget it as Rhino does not enforce this 
requirement and in many cases storing raw Java objects would apparently 
work due to implementation details.

But in other cases the results would be unpredictable and you may get 
ClassCastExceptions etc. So to help to avoid this Rhino now prints a 
warning when it can detect the improper usage but continue to work as 
before for compatibility reasons.

In the particular case of Cocoon it seems that Java code behind 
cocoon.session.getAttribute does not wrap properly its results and 
return raw Java object. That can be fixed either using Context.javaToJS 
method or to be compatible with Rhino 1.5R4-based fork using 
Context.toObject.

Regards, Igor

Mime
View raw message