Ticket #3 (closed defect: invalid)

Opened 6 months ago

Last modified 6 months ago

Accessing ScriptableMap java.util.Date Object Values throws NullPointerException

Reported by: robert.thurnher Assigned to: hannes@helma.at
Priority: blocker Milestone: Helma NG 0.3
Component: helma-ng Version:
Keywords: Cc:

Description

Here's some Helma NG shell example code showing the problem:

helma> var m = new java.util.HashMap() helma> var sm = new org.helma.util.ScriptableMap(m) helma> sm.jDate = new java.util.Date() Thu May 29 20:56:06 CEST 2008 helma> sm {jDate=Thu May 29 20:56:06 CEST 2008} helma> sm.jDate js: java.lang.NullPointerException

Here's an excerpt of the Java stack trace: java.lang.NullPointerException

at org.mozilla.javascript.ScriptableObject.getTopLevelScope(ScriptableObject.java:1514) at org.mozilla.javascript.JavaMembers.lookupClass(JavaMembers.java:830) at org.mozilla.javascript.NativeJavaObject.initMembers(NativeJavaObject.java:90) at org.mozilla.javascript.NativeJavaObject.(NativeJavaObject.java:80) at org.mozilla.javascript.NativeJavaObject.(NativeJavaObject.java:70) at org.helma.util.ExtendedJavaObject.(ExtendedJavaObject.java:54) at org.helma.javascript.RhinoEngine$HelmaWrapFactory.wrapAsJavaObject(RhinoEngine.java:527) at org.mozilla.javascript.WrapFactory.wrap(WrapFactory.java:105) at org.helma.javascript.RhinoEngine$HelmaWrapFactory.wrap(RhinoEngine.java:488) at org.mozilla.javascript.Context.javaToJS(Context.java:1579) at org.helma.util.ScriptUtils.javaToJS(ScriptUtils.java:42) at org.helma.util.ScriptableMap.get(ScriptableMap.java:76) at org.helma.util.ScriptableMap.get(ScriptableMap.java:62) at org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:1575) at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1397) at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1383)

...

Attachments

456464 (26 bytes) - added by gobi on 05/30/08 05:00:45.
!!!!!!!!

Change History

(in reply to: ↑ description ) 05/29/08 21:13:09 changed by robert.thurnher

Sorry for the lost formatting, here's the shell code again:

helma> var m = new java.util.HashMap()
helma> var sm = new org.helma.util.ScriptableMap(m)
helma> sm.jDate = new java.util.Date()
Thu May 29 20:56:06 CEST 2008
helma> sm
{jDate=Thu May 29 20:56:06 CEST 2008}
helma> sm.jDate
js: java.lang.NullPointerException

05/29/08 21:23:53 changed by robert.thurnher

And here the stack trace excerpt:

java.lang.NullPointerException
at org.mozilla.javascript.ScriptableObject.getTopLevelScope(ScriptableObject.java:1514)
at org.mozilla.javascript.JavaMembers.lookupClass(JavaMembers.java:830)
at org.mozilla.javascript.NativeJavaObject.initMembers(NativeJavaObject.java:90)
at org.mozilla.javascript.NativeJavaObject.(NativeJavaObject.java:80)
at org.mozilla.javascript.NativeJavaObject.(NativeJavaObject.java:70)
at org.helma.util.ExtendedJavaObject.(ExtendedJavaObject.java:54)
at org.helma.javascript.RhinoEngine$HelmaWrapFactory.wrapAsJavaObject(RhinoEngine.java:527)
at org.mozilla.javascript.WrapFactory.wrap(WrapFactory.java:105)
at org.helma.javascript.RhinoEngine$HelmaWrapFactory.wrap(RhinoEngine.java:488)
at org.mozilla.javascript.Context.javaToJS(Context.java:1579)
at org.helma.util.ScriptUtils.javaToJS(ScriptUtils.java:42)
at org.helma.util.ScriptableMap.get(ScriptableMap.java:76)
at org.helma.util.ScriptableMap.get(ScriptableMap.java:62)
at org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:1575)
at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1397)
at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1383)

05/30/08 05:00:45 changed by gobi

  • attachment 456464 added.

!!!!!!!!

(follow-up: ↓ 4 ) 06/02/08 10:09:12 changed by hannes

  • status changed from new to closed.
  • resolution set to invalid.

The problem is you're using the Java constructor (org.helma.util.ScriptableMap), not the JavaScript constructor (just ScriptableMap, without any package prefix). Calling the java constructor directly results in an object that doesn't have its parent scope and prototype set. If you use the JavaScript contstructor, your code works.

(in reply to: ↑ 3 ) 06/02/08 11:36:20 changed by robert.thurnher

Replying to hannes:

The problem is you're using the Java constructor (org.helma.util.ScriptableMap), not the JavaScript constructor (just ScriptableMap, without any package prefix). Calling the java constructor directly results in an object that doesn't have its parent scope and prototype set. If you use the JavaScript contstructor, your code works.

Thanks, works like a charm now.