-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
rc
-
sparc
-
solaris_8
Name: gm110360 Date: 06/17/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION : Linux 2.4.2
(Redhat 7.1)
ADDITIONAL OPERATING SYSTEMS : SunOS 5.8
A DESCRIPTION OF THE PROBLEM :
The Java Plug-in Guide at
http://java.sun.com/j2se/1.4/docs/guide/plugin/developer_guide/java_js.html#common_dom
,
when explaining accessing DOM, tells to use
DOMAccessor.getDocument() with *no* arguments:
public Object run(DOMAccessor accessor){
HTMLDocument doc = (HTMLDocument) accessor.getDocument();
return doc.getTitle();
}
etc.
Unfortunately, the actual class file for
com.sun.java.browser.dom.DOMAccessor that comes
in j2sdk1.4.0/jre/lib/rt.jar only contains a version
of this method that takes *one* argument, viz.
DOMAccessot.getDocument(Object). The same version is
"documented" in the API pages at
http://java.sun.com/j2se/1.4/docs/guide/plugin/dom/com/sun/java/browser/dom/DOMAccessor.html
,
but unfortunately with no explanation whatsoever
as to what the argument should be. Passing null
as an argumnet does no good (the method simply returns
null).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Cut and paste the example from the Plug-In Guide into
a Java file and try to compile...
2. Get the compiler error message that getDocument(void)
does not exist
3. Look into rt.jar or API docs and find the one-argument
method instead.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Well, I'd expect either a no-argument method to be present
in DOMAccessor (and the actual Sun classes that
implement this interface), or the Plug-In Guide or
the API pages to tell the people how the one-argument
method is supposed to be used, that is what do you pass
to accessor.getDocument(???).
ERROR MESSAGES/STACK TRACES THAT OCCUR :
[javac] /home/vmenkov/work/code/src/AWS/applet/Test.java:31: No method matching
getDocument() found in interface com.sun.java.browser.dom.DOMAccessor.
if trying to use no-arg version; or, getDocument returns null if
trying to pass null instead. I am using Java Plug-in 1.4 with
Netscape 6.2 for Linux.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import java.applet.*;
import java.io.*;
// DOM access experiments
import com.sun.java.browser.dom.*;
import org.w3c.dom.*;
import org.w3c.dom.html.*;
/** As per
http://java.sun.com/j2se/1.4/docs/guide/plugin/developer_guide/java_js.html#common_dom
...
*/
public class Test extends Applet {
public void start() {
DOMService service = null;
try {
service = DOMService.getService( this);
DOMAction action =
new DOMAction() {
public Object run( DOMAccessor accessor) {
// Undocumented argument!!!
Object something = null;
HTMLDocument d =
(HTMLDocument)
accessor.getDocument(something);
if (d == null) {
System.err.println("getDocument returns null");
return null;
} else {
System.err.println("getDocument returned something");
return d.getTitle();
}
}
};
String title=(String)service.invokeAndWait(action);
}
catch (DOMUnsupportedException e1) { }
catch (DOMAccessException e2) { }
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Well, if all you need is just the document URL or
Title, you can always use window.getMember(), or
eval('window_name.document.URL') etc., as long as
the document in question comes from the same codebase
as your applet.
(Review ID: 147053)
======================================================================