Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2078695 | 5.0 | Ramesh Mandava | P3 | Closed | Fixed | b36 |
Name: eaR10174 Date: 12/26/2003
The methods
javax.xml.xpath.XPath.evaluate(String, Object, QName)
javax.xml.xpath.XPath.evaluate(String, InputSource, QName)
javax.xml.xpath.XPath.evaluate(String, URL, QName)
do not throw IllegalArgumentException in case when a return type is not one of the types defined in
XPathConstants. The methods should throw the exception according to the javadoc.
The bug affects new JCK1.5 tests (not integrated yet):
api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate052]
api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate056]
api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate062]
The following test fails running on JDK 1.5.0-beta-b32.
See below the test source and the execution log:
------------------------------------test.xml------------------------------
<?xml version='1.0'?>
<root/>
------------------------------------Test.java-----------------------------
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathConstants;
import javax.xml.namespace.QName;
import java.io.StringReader;
import java.io.File;
import org.xml.sax.InputSource;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Node;
public class Test {
public static final String XML = "<?xml version='1.0'?>\n"
+ "<root/>\n";
private XPath xpath;
public static void main (String[] args) {
try {
Test test = new Test();
test.case01();
test.case02();
test.case03();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public Test() throws Exception {
XPathFactory xpf = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);
xpath = xpf.newXPath();
}
public void case01() {
System.out.print("case01 - ");
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
StringReader reader = new StringReader(XML);
InputSource inSource = new InputSource(reader);
Node document = docBuilder.parse(inSource);
xpath.evaluate("/", document, new QName("object"));
System.out.println("Failed: exception was not thrown.");
} catch (IllegalArgumentException e) {
System.out.println("OK");
} catch (Exception e) {
System.out.println("Failed: " + e.toString());
}
}
public void case02() {
System.out.print("case02 - ");
try {
StringReader reader = new StringReader(XML);
InputSource inSource = new InputSource(reader);
xpath.evaluate("/", inSource, new QName("object"));
System.out.println("Failed: exception was not thrown.");
} catch (IllegalArgumentException e) {
System.out.println("OK");
} catch (Exception e) {
System.out.println("Failed: " + e.toString());
}
}
public void case03() {
System.out.print("case03 - ");
try {
URL url = new File("test.xml").toURL();
xpath.evaluate("/", url, new QName("object"));
System.out.println("Failed: exception was not thrown.");
} catch (IllegalArgumentException e) {
System.out.println("OK");
} catch (Exception e) {
System.out.println("Failed: " + e.toString());
}
}
}
--------------------------------------------------------------------------
% java -showversion test
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32, mixed mode)
case01 - Failed: exception was not thrown.
case02 - Failed: exception was not thrown.
case03 - Failed: exception was not thrown.
--------------------------------------------------------------------------
======================================================================
- backported by
-
JDK-2078695 XPath.evaluate: IAE is not thrown for illegal return types
- Closed