Creating a ScriptableOutputStream throws IllegalArgumentException: Object for excluded name XML not found

RESOLVED FIXED

Status

Rhino
Core
--
major
RESOLVED FIXED
12 years ago
12 years ago

People

(Reporter: A. Hill, Assigned: Attila Szegedi)

Tracking

Details

Attachments

(1 attachment)

(Reporter)

Description

12 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3
Build Identifier: Rhino 1.6 release 2 2005 09 19

The exception is thrown when attempting to create the ScriptableOutputStream:

ie:
ScriptableOutputStream scriptableOs = new ScriptableOutputStream(outputStream,scope);

java.lang.IllegalArgumentException: Object for excluded name XML not found.
	at org.mozilla.javascript.serialize.ScriptableOutputStream.addExcludedName(ScriptableOutputStream.java:91)
	at org.mozilla.javascript.serialize.ScriptableOutputStream.excludeStandardObjectNames(ScriptableOutputStream.java:131)
	at org.mozilla.javascript.serialize.ScriptableOutputStream.<init>(ScriptableOutputStream.java:78)
	at RhinoSerializationBug.run(RhinoSerializationBug.java:45)

This error is not present in 1.6R1. A workaround is to create 'dummy' objects and prototypes for XML and XMLList.

Reproducible: Always

Steps to Reproduce:
1. Enter a context, create the standard objects, and then evaluate a script that creates/defines something - a function say (fwiw: I originally noticed this trying to serialize a Continuation).
ie:
function example() { return 42; }

2. Back in java get the Function you created in the javascript from the scope, create a ScriptableOutputStream around a normal FileOutputStream.

3. In 1.6R2 this throws the exception. In 1.6R1 it does not and you can write the Function to the stream.

To demonstrate the workaround, follow the steps above, but in addition to the function, also create dummy objects for XML, XMLList and their prototypes. ie:
var XML = new Object(); XML.prototype=new Object();
var XMLList = new Object(); XMLList.prototype=new Object();
function example() { return 42; }



Expected Results:  
Not thrown the exception

Ill try and attach some code and its output that reproduces the problem.
(Reporter)

Comment 1

12 years ago
Created attachment 208206 [details]
Java code demonstrating the bug

Zip contains src for a class that demonstrates the issue, and a txt file that shows output produced when run against 1.6R2 and 1.6R1
(Assignee)

Comment 2

12 years ago
This happens when you use rhino without Apache XML Beans library on the classpath. For now, either add it to the classpath, add a fake XML and XMLImpl objects to the scope, create a subclass of ScriptableOutputStream that'll override the relevant method and swallow the exception:

    public void addExcludedName(String name)
    {
        // Workaround for mysterious cases when "XML" global object is not 
        // found.
        try
        {
            super.addExcludedName(name);
        }
        catch(IllegalArgumentException e)
        {
            logger.debug(e.getMessage());
        }
    }

I was bitten by this myself in my own application that uses Rhino... I have committed a fix for this in the CVS -- next release will no longer suffer from this problem.

Updated

12 years ago
Assignee: igor.bukanov → szegedia

Comment 3

12 years ago
Marking as resolved per comment 2.
Status: NEW → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.