JDK-6738770 : REGRESSION:JSException throws when use LiveConnect javascript facility to navigate HTML elements
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 6u10
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-08-19
  • Updated: 2014-03-03
  • Resolved: 2008-11-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u11 b03Fixed 7Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
J2SE Version (please include all output from java -version flag):

java version "1.6.0_10-rc"
Java(TM) SE Runtime Environment (build 1.6.0_10-rc-b28)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)


Does this problem occur on J2SE 1.3, 1.4.x or 1.5?  Yes / No (pick one)

No. 1.6.0_07 is fine.

Operating System Configuration Information (be specific):

Windows XP SP2, IE7


Hardware Configuration Information (be specific):

Standard desktop

Bug Description:

When we use LiveConnect javascript facility to navigate HTML elements using document.all.item, it would cause an JSException when it evalute attributes of an applet tag. I have reduce our production applet into a smaller test case and you can easily catch the exception but using our production applet it crashes the Internet Explorer.

Steps to Reproduce (be specific):

1) Install the following test cases:

TestJSObject.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TestJSObject</title>
</head>
<body>
<applet alt="Java not installed properly" code="TestJSObject" codebase="bin/" width="640" height="480" MAYSCRIPT></applet>
<table>
<TR bgcolor="#123456">
<TD>Testing 1</TD>
<TD>Testing 2</TD>
</TR>
</table>
</body>
</html>

TestJSObject.java:

import javax.swing.JApplet;
import javax.swing.JTextArea;

import netscape.javascript.JSException;
import netscape.javascript.JSObject;


public class TestJSObject extends JApplet {

	@Override
	public void init() {
		JTextArea area = new JTextArea(100,100);
		JSObject appletWindow = JSObject.getWindow(this);
		JSObject document = (JSObject) appletWindow.getMember("document");  
		if( document == null) {
			area.append("Document is null!!!!");
		} else {
			area.append("Document is: "+document);
		}
		area.append("\n");
		
		JSObject documentElement = (JSObject) document.getMember("documentElement");
		area.append("documentElement = "+documentElement);
		area.append("\n");
			
		String innerHTML = (String) documentElement.getMember("innerHTML");
		area.append("innerHTML = "+innerHTML);
		area.append("\n");
		
		JSObject allItem = (JSObject) document.getMember("all");
		area.append("all element="+allItem);
		area.append("\n");
		area.append("item length="+allItem.getMember("length"));
		
		int length = (Integer) allItem.getMember("length");
		area.append("\n");
		
		
		for(int i=0; i<length; i++) {
			try {
				JSObject element = (JSObject) allItem.call("item", new Object[] {i});
				area.append("item "+i+" = "+ element.getMember("tagName")+".localName=s"+element.call("getAttribute",new Object[] {"GSLinkElement"}));
				area.append("\n");
			} catch (JSException jse) {
				area.append("Exception occured\n");
				area.append("Exception = "+jse.getLocalizedMessage());
			}		
		} 
		
		add(area);
		setVisible(true);
		
	}
}

2) When you run this applet, with Java 6 update 7 it will show this:

Document is: [object HTMLDocument]
documentElement = [object HTMLElement]
innerHTML = <HEAD><TITLE>TestJSObject</TITLE>
<META http-equiv=Content-Type content="text/html; charset=ISO-8859-1"></HEAD>
<BODY><!-- 

--><APPLET codeBase=bin/ height=480 alt="Java not installed properly" width=640 code=TestJSObject MAYSCRIPT><PARAM NAME="_cx" VALUE="16933"><PARAM NAME="_cy" VALUE="12700"></APPLET> 
<TABLE>
<TBODY>
<TR bgColor=#123456>
<TD>Testing 1</TD>
<TD>Testing 2</TD></TR></TBODY></TABLE></BODY>
all element=[object HTMLCollection]
item length=13
item 0 = !.localName=snull
item 1 = HTML.localName=snull
item 2 = HEAD.localName=snull
item 3 = TITLE.localName=snull
item 4 = META.localName=snull
item 5 = BODY.localName=snull
item 6 = !.localName=snull
item 7 = APPLET.localName=snull
item 8 = TABLE.localName=snull
item 9 = TBODY.localName=snull
item 10 = TR.localName=snull
item 11 = TD.localName=snull
item 12 = TD.localName=snull

When you run this applet under Java 6 Update 10, it will show this:


Document is: [object]
documentElement = [object]
innerHTML = <HEAD><TITLE>TestJSObject</TITLE>
<META http-equiv=Content-Type content="text/html; charset=ISO-8859-1"></HEAD>
<BODY><!-- 

--><APPLET codeBase=bin/ height=480 alt="Java not installed properly" width=640 code=TestJSObject MAYSCRIPT><PARAM NAME="_cx" VALUE="16933"><PARAM NAME="_cy" VALUE="12700"></APPLET> 
<TABLE>
<TBODY>
<TR bgColor=#123456>
<TD>Testing 1</TD>
<TD>Testing 2</TD></TR></TBODY></TABLE></BODY>
all element=[object]
item length=13
item 0 = !.localName=snull
item 1 = HTML.localName=snull
item 2 = HEAD.localName=snull
item 3 = TITLE.localName=snull
item 4 = META.localName=snull
item 5 = BODY.localName=snull
item 6 = !.localName=snull
Exception occured
Exception = ??o?????o?o??:item 8 = TABLE.localName=snull
item 9 = TBODY.localName=snull
item 10 = TR.localName=snull
item 11 = TD.localName=snull
item 12 = TD.localName=snull
This is the exception.printStackTrace() output from our production application.
 
netscape.javascript.JSException: ?????????????:
 at sun.plugin2.main.client.MessagePassingJSObject.newJSException(MessagePassingJSObject.java:227)
 at sun.plugin2.main.client.MessagePassingJSObject.waitForReply(MessagePassingJSObject.java:141)
 at sun.plugin2.main.client.MessagePassingJSObject.call(MessagePassingJSObject.java:67)
 at com.gs.eq.csc.merch.LiveBrowser.JSObjectHelper.getStringElementAttribute(JSObjectHelper.java:92)
 at com.gs.eq.csc.merch.LiveBrowser.GSLinkController.processDocument(GSLinkController.java:157)
 at com.gs.eq.csc.merch.LiveBrowser.LiveBrowserApplet.run(LiveBrowserApplet.java:464)
 at java.lang.Thread.run(Thread.java:619)

Comments
EVALUATION There are two differences between the new plugin and the old plugin: 1. When call method on <applet> element, the new plugin actually try to call the method on the applet class. getAttribute method is mapped to get the filed of java class. Since the java applet class has no such field, a JSException is thrown. The old plugin simply looks for the attribute of the <applet> HTML element. 2. JavaScript toString. in new plugin the IExplorerPlugin.javaScriptToString() is different than the original code. It is just calling toString() on the JavaScript object. It is simpler, but causes the difference in the string representations of html elements. Need investigate further about the above compatibility issues.
2008-10-08