1 /*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package dom;
25
26 import java.io.ByteArrayInputStream;
27
28 import javax.xml.parsers.DocumentBuilder;
29 import javax.xml.parsers.DocumentBuilderFactory;
30 import javax.xml.xpath.XPath;
31 import javax.xml.xpath.XPathConstants;
32 import javax.xml.xpath.XPathExpression;
33 import javax.xml.xpath.XPathFactory;
34
35 import org.testng.Assert;
36 import org.testng.annotations.Test;
37 import org.w3c.dom.Document;
38 import org.w3c.dom.NodeList;
39
40 /*
41 * @bug 6333993
42 * @summary Test NodeList.item(valid index) returns value after NodeList.item(NodeList.getLength()).
43 */
44 public class CR6333993Test {
45
46 @Test
47 public void testNodeList() {
48 int n = 5;
49 while (0 != (n--))
50 ;
51 System.out.println("n=" + n);
52 try {
53 String testXML = "<root>" + " <node/>" + " <node/>" + " <node/>" + " <node/>" + "</root>\n";
54 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
55 // dbf.setNamespaceAware(true);
56 DocumentBuilder builder = dbf.newDocumentBuilder();
57 ByteArrayInputStream bis = new ByteArrayInputStream(testXML.getBytes());
58 Document testDoc = builder.parse(bis);
59 XPathFactory xpathFactory = XPathFactory.newInstance();
60 XPath xpath = xpathFactory.newXPath();
61 XPathExpression expr = xpath.compile("/root/node");
62 NodeList testNodes = (NodeList) expr.evaluate(testDoc, XPathConstants.NODESET);
63 // Node list appears to work correctly
|
1 /*
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package dom;
25
26 import java.io.ByteArrayInputStream;
27
28 import javax.xml.parsers.DocumentBuilder;
29 import javax.xml.parsers.DocumentBuilderFactory;
30 import javax.xml.xpath.XPath;
31 import javax.xml.xpath.XPathConstants;
32 import javax.xml.xpath.XPathExpression;
33 import javax.xml.xpath.XPathFactory;
34
35 import org.testng.Assert;
36 import org.testng.annotations.Listeners;
37 import org.testng.annotations.Test;
38 import org.w3c.dom.Document;
39 import org.w3c.dom.NodeList;
40
41 /*
42 * @bug 6333993
43 * @summary Test NodeList.item(valid index) returns value after NodeList.item(NodeList.getLength()).
44 */
45 @Listeners({jaxp.library.BasePolicy.class})
46 public class CR6333993Test {
47
48 @Test
49 public void testNodeList() {
50 int n = 5;
51 while (0 != (n--))
52 ;
53 System.out.println("n=" + n);
54 try {
55 String testXML = "<root>" + " <node/>" + " <node/>" + " <node/>" + " <node/>" + "</root>\n";
56 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
57 // dbf.setNamespaceAware(true);
58 DocumentBuilder builder = dbf.newDocumentBuilder();
59 ByteArrayInputStream bis = new ByteArrayInputStream(testXML.getBytes());
60 Document testDoc = builder.parse(bis);
61 XPathFactory xpathFactory = XPathFactory.newInstance();
62 XPath xpath = xpathFactory.newXPath();
63 XPathExpression expr = xpath.compile("/root/node");
64 NodeList testNodes = (NodeList) expr.evaluate(testDoc, XPathConstants.NODESET);
65 // Node list appears to work correctly
|