Skip to content
Browse files
8285726: [11u, 17u] Unify fix for JDK-8284548 with version from head
Backport-of: c464f20f41ff8b6b7eb3f1357f9bd5fcd51b13cb
  • Loading branch information
RealCLanger committed May 14, 2022
1 parent 8b0e5ec commit 316c5144c45478175e1a93ea68c9a8bbee455d76
Showing 3 changed files with 83 additions and 54 deletions.
@@ -32,7 +32,7 @@
* This class is in charge of lexical processing of the XPath
* expression into tokens.
* @LastModified: Jan 2022
* @LastModified: Apr 2022
class Lexer
@@ -0,0 +1,82 @@
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit if you need additional information or have any
* questions.

package xpath;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

* @test
* @bug 8284548
* @run testng xpath.XPathExceptionTest
* @summary This is a general test for Exception handling. Additional cases may
* be added with a bug id in the test cases.
public class XPathExceptionTest {

* DataProvider: invalid XPath expressions
* Illegal expressions and structures that may escape the validation check.
@DataProvider(name = "invalid")
public Object[][] getInvalid() throws Exception {
return new Object[][]{
// @bug JDK-8284548: expressions ending with relational operators
// throw StringIndexOutOfBoundsException instead of XPathExpressionException
{"/a/b/c[@d >"},
{"/a/b/c[@d <"},
{"/a/b/c[@d >="},

* Verifies that the XPath processor throws XPathExpressionException upon
* encountering illegal XPath expressions.
* @param invalidExp an illegal XPath expression
* @throws Exception if the test fails
@Test(dataProvider = "invalid")
public void testIllegalExp(String invalidExp) throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new org.xml.sax.InputSource(new StringReader("<A/>")));
Assert.assertThrows(XPathExpressionException.class, () -> evaluate(doc, invalidExp));

private void evaluate(Document doc, String s) throws XPathExpressionException {
XPath xp = XPathFactory.newInstance().newXPath();
XPathExpression xe = xp.compile(s);
xe.evaluateExpression(doc, Node.class);

This file was deleted.

1 comment on commit 316c514

Copy link

@openjdk-notifier openjdk-notifier bot commented on 316c514 May 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.