Blame SOURCES/jdk8284548-jaxp_regression.patch

35d9f7
From 722bf5b20de2ee64e0fdabb2f5e5fa89e043e3f1 Mon Sep 17 00:00:00 2001
35d9f7
From: Christoph Langer <clanger@openjdk.org>
35d9f7
Date: Fri, 8 Apr 2022 14:06:47 +0200
35d9f7
Subject: [PATCH] 8284548: Unexpected StringIndexOutOfBoundsException can occur
35d9f7
 for invalid XPath expressions after JDK-8270504
35d9f7
35d9f7
---
35d9f7
 .../apache/xpath/internal/compiler/Lexer.java |  4 +-
35d9f7
 .../javax/xml/jaxp/XPath/InvalidXPath.java    | 53 +++++++++++++++++++
35d9f7
 2 files changed, 54 insertions(+), 3 deletions(-)
35d9f7
 create mode 100644 test/jdk/javax/xml/jaxp/XPath/InvalidXPath.java
35d9f7
35d9f7
diff --git openjdk.orig/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/compiler/Lexer.java openjdk/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/compiler/Lexer.java
35d9f7
index 54595e2d036..b7b3f419eb2 100644
35d9f7
--- openjdk.orig/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/compiler/Lexer.java
35d9f7
+++ openjdk/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/compiler/Lexer.java
35d9f7
@@ -24,7 +24,6 @@ import com.sun.org.apache.xalan.internal.res.XSLMessages;
35d9f7
 import com.sun.org.apache.xml.internal.utils.PrefixResolver;
35d9f7
 import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
35d9f7
 import java.util.List;
35d9f7
-import java.util.Objects;
35d9f7
 import javax.xml.transform.TransformerException;
35d9f7
 import jdk.xml.internal.XMLSecurityManager;
35d9f7
 import jdk.xml.internal.XMLSecurityManager.Limit;
35d9f7
@@ -451,8 +450,7 @@ class Lexer
35d9f7
    * @return the next char
35d9f7
    */
35d9f7
   private char peekNext(String s, int index) {
35d9f7
-      Objects.checkIndex(index, s.length());
35d9f7
-      if (s.length() > index) {
35d9f7
+      if (index >= 0 && index < s.length() - 1) {
35d9f7
           return s.charAt(index + 1);
35d9f7
       }
35d9f7
       return 0;
35d9f7
diff --git openjdk.orig/test/jdk/javax/xml/jaxp/XPath/InvalidXPath.java openjdk/test/jdk/javax/xml/jaxp/XPath/InvalidXPath.java
35d9f7
new file mode 100644
35d9f7
index 00000000000..478f4212d5b
35d9f7
--- /dev/null
35d9f7
+++ openjdk/test/jdk/javax/xml/jaxp/XPath/InvalidXPath.java
35d9f7
@@ -0,0 +1,53 @@
35d9f7
+/*
35d9f7
+ * Copyright (c) 2022, SAP SE. All rights reserved.
35d9f7
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35d9f7
+ *
35d9f7
+ * This code is free software; you can redistribute it and/or modify it
35d9f7
+ * under the terms of the GNU General Public License version 2 only, as
35d9f7
+ * published by the Free Software Foundation.
35d9f7
+ *
35d9f7
+ * This code is distributed in the hope that it will be useful, but WITHOUT
35d9f7
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35d9f7
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
35d9f7
+ * version 2 for more details (a copy is included in the LICENSE file that
35d9f7
+ * accompanied this code).
35d9f7
+ *
35d9f7
+ * You should have received a copy of the GNU General Public License version
35d9f7
+ * 2 along with this work; if not, write to the Free Software Foundation,
35d9f7
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35d9f7
+ *
35d9f7
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
35d9f7
+ * or visit www.oracle.com if you need additional information or have any
35d9f7
+ * questions.
35d9f7
+ */
35d9f7
+
35d9f7
+/*
35d9f7
+ * @test
35d9f7
+ * @bug 8284548
35d9f7
+ * @summary Test whether the expected exception is thrown when
35d9f7
+ *           trying to compile an invalid XPath expression.
35d9f7
+ * @run main InvalidXPath
35d9f7
+ */
35d9f7
+
35d9f7
+import javax.xml.xpath.XPathExpressionException;
35d9f7
+import javax.xml.xpath.XPathFactory;
35d9f7
+
35d9f7
+public class InvalidXPath {
35d9f7
+
35d9f7
+    public static void main(String... args) {
35d9f7
+        // define an invalid XPath expression
35d9f7
+        final String invalidXPath = ">>";
35d9f7
+
35d9f7
+        // expect XPathExpressionException when the invalid XPath expression is compiled
35d9f7
+        try {
35d9f7
+            XPathFactory.newInstance().newXPath().compile(invalidXPath);
35d9f7
+        } catch (XPathExpressionException e) {
35d9f7
+            System.out.println("Caught expected exception: " + e.getClass().getName() +
35d9f7
+                    "(" + e.getMessage() + ").");
35d9f7
+        } catch (Exception e) {
35d9f7
+            System.out.println("Caught unexpected exception: " + e.getClass().getName() +
35d9f7
+                    "(" + e.getMessage() + ")!");
35d9f7
+            throw e;
35d9f7
+        }
35d9f7
+    }
35d9f7
+}
35d9f7
-- 
35d9f7
2.35.1.windows.2
35d9f7