Closed Bug 96270 Opened 23 years ago Closed 22 years ago

Unable to create java objects from within a javascript.

Categories

(Rhino Graveyard :: Core, defect)

x86
Windows 2000
defect
Not set
blocker

Tracking

(Not tracked)

VERIFIED FIXED
1.5R4.1

People

(Reporter: sonali, Assigned: norrisboyd)

References

Details

Attachments

(1 file)

Hi,
I want to create a new insatnce of my java class from within a javascript.

//JAVASCRIPT CODE
 importClass(Packages.com.sonicsw.xs.envelope.Address)
 address = new Packages.com.sonicsw.xs.envelope.Address("Queue1");

I'm using BSF 2.2 and Rhino Javascript Engine 1.5 on Windows 2000, 
to execute this javascript.

However, the execution just hangs at the 2nd line written above.
The Address class is in classpath too.
Please let me know what am I missing here.
Having the same problem. Scripts that worked fine in 1.5R3 now get something 
like this in 1.5R4:

com.ibm.bsf.BSFException: JavaScript Error: Function importClass must be called 
with a class; had "[JavaPackage 
com.emaritz.mario.participation.FindParticipationStatusByDateCmd]" instead. (; 
line 5)

Jim Cakalic
james.cakalic@Maritz.com
cc'ing Igor -
Jim, do you set any classloaders in your application? And what the following
script will print under 1.5R4 and 1.5R3:

java.lang.System.out.println(Packages.org.mozilla.javascript.Context.currentContext.optimizationLevel)

var cl =
java.lang.Class.forName("com.emaritz.mario.participation.FindParticipationStatusByDateCmd");

java.lang.System.out.println(cl);
CC to Jim so he will get a message about the previous comment.
This is indeed a regression since 1.5R3 caused by the fact that 1.5R4 uses
ScriptableObject.has to check for property existence instead of checking
ScriptableObject.get != NOT_FOUND. In this way an assignment to a property which
initial value is initialized on the first read access would not need to create
the default value. See CVS log for org/mozilla/javascript/ScriptRutime.java from
2002-04-11.

Unfortunately not all classes are updated for this pattern change and in
particular ImporterTopLevel does not have proper has method, which can be seen
if the following script is run in Rhino shell with optimization level -1:

importPackage(java.util);
var v = Vector();
print(v);

which gives:

js: "/home/igor/js/x/test.js", line 2: uncaught JavaScript exception:
ReferenceError: "Vector" is not defined. (/home/igor/js/x/test.js; line 2)

As far as I can see the bug is visible only when calling constructors of Java
objects imported through importPackage without using new keyword. If the above
example will be changed to 

importPackage(java.util);
var v = new Vector();
print(v);

it correctly prints "[]"

I commited the fix
Marking FIXED - the tests given by Igor in Comment #5 both pass now.
I tested this in the Rhino shell with optimization levels -1, 0, 1, 9.
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Marking Verified.

Sonali and Jim: please reopen this bug if the fix doesn't work for you -
Status: RESOLVED → VERIFIED
Blocks: 196149
Targeting as resolved against 1.5R4.1
Target Milestone: --- → 1.5R4.1
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: