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)
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.
Comment 1•22 years ago
|
||
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
Comment 2•22 years ago
|
||
cc'ing Igor -
Comment 3•22 years ago
|
||
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);
Comment 4•22 years ago
|
||
CC to Jim so he will get a message about the previous comment.
Comment 5•22 years ago
|
||
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 "[]"
Comment 6•22 years ago
|
||
Comment 7•22 years ago
|
||
I commited the fix
Comment 8•22 years ago
|
||
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
Comment 9•22 years ago
|
||
Marking Verified. Sonali and Jim: please reopen this bug if the fix doesn't work for you -
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•