Bug Tracker

Opened 13 years ago

Closed 13 years ago

#1453 closed bug (fixed)

java.lang.String passed to append/jQuery.clean throws Exception

Reported by: joern Owned by: joern
Priority: major Milestone: 1.1.4
Component: web Version: 1.1.3
Keywords: Cc:
Blocked by: Blocking:

Description

Passing a java.lang.String to jQuery.clean throws a EvaluatorException, caused by/in this line:

if ( arg[0] == undefined || jQuery.nodeName(arg, "form") || arg.options )

Would be nice to find a fix that doesn't require a modification of jQuery.js.

The obvious workaround converts the java String to a native String first: $("...").append("" + javaString)

Typical stacktrace:

org.mozilla.javascript.EvaluatorException: Java class "java.lang.String" has no public instance field or method named "0". (C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js#537)
	org.mozilla.javascript.tools.ToolErrorReporter.runtimeError(ToolErrorReporter.java:142)
	org.mozilla.javascript.Context.reportRuntimeError(Context.java:1030)
	org.mozilla.javascript.Context.reportRuntimeError(Context.java:1086)
	org.mozilla.javascript.Context.reportRuntimeError2(Context.java:1056)
	org.mozilla.javascript.JavaMembers.reportMemberNotFound(JavaMembers.java:785)
	org.mozilla.javascript.NativeJavaObject.get(NativeJavaObject.java:117)
	org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:1572)
	org.mozilla.javascript.ScriptRuntime.getObjectElem(ScriptRuntime.java:1342)
	org.mozilla.javascript.ScriptRuntime.getObjectElem(ScriptRuntime.java:1326)
	org.mozilla.javascript.gen.c140._c64(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js:537)
	org.mozilla.javascript.gen.c140.call(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js)
	org.mozilla.javascript.ScriptRuntime.applyOrCall(ScriptRuntime.java:2234)
	org.mozilla.javascript.BaseFunction.execIdCall(BaseFunction.java:257)
	org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:127)
	org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
	org.mozilla.javascript.gen.c140._c49(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js:339)
	org.mozilla.javascript.gen.c140.call(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js)
	org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
	org.mozilla.javascript.gen.c140._c63(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js:473)
	org.mozilla.javascript.gen.c140.call(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js)
	org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
	org.mozilla.javascript.gen.c140._c42(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js:274)
	org.mozilla.javascript.gen.c140.call(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js)
	org.mozilla.javascript.ScriptRuntime.applyOrCall(ScriptRuntime.java:2234)
	org.mozilla.javascript.BaseFunction.execIdCall(BaseFunction.java:257)
	org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:127)
	org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
	org.mozilla.javascript.gen.c140._c49(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js:339)
	org.mozilla.javascript.gen.c140.call(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js)
	org.mozilla.javascript.optimizer.OptRuntime.callN(OptRuntime.java:86)
	org.mozilla.javascript.gen.c140._c7(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js:92)
	org.mozilla.javascript.gen.c140.call(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js)
	org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
	org.mozilla.javascript.gen.c140._c41(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js:272)
	org.mozilla.javascript.gen.c140.call(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js)
	org.mozilla.javascript.optimizer.OptRuntime.callN(OptRuntime.java:86)
	org.mozilla.javascript.gen.c140._c18(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js:168)
	org.mozilla.javascript.gen.c140.call(C:\dev\workspace-rad7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\jQueryWeb\WEB-INF/jquery.js)

Testcode, where getName() returns a java.lang.String:

$("#navmenu").append(blog.getName());

Change History (1)

comment:1 Changed 13 years ago by joern

Resolution: fixed
Status: newclosed

Fixed in [2719] by adding this to the context initalisation:

Context.getCurrentContext().getWrapFactory().setJavaPrimitiveWrap(false);
Note: See TracTickets for help on using tickets.