aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoehw <unknown>2019-05-31 10:58:10 -0700
committerbell-sw <liberica@bell-sw.com>2019-10-23 16:22:35 +0300
commit7cef4b845cf74e763ed3098bef7a499e51e94d01 (patch)
tree83dbc2f371de0c6469f85ae1c270119803dd9948
parent4e64ac8131966dcbbf8c761bef61ada508ec2058 (diff)
downloadjdk8u_jaxp-7cef4b845cf74e763ed3098bef7a499e51e94d01.tar.gz
8224532: Better Path supports
Reviewed-by: rriggs, lancea, dfuchs, mschoene
-rw-r--r--src/com/sun/org/apache/xpath/internal/XPath.java10
-rw-r--r--src/com/sun/org/apache/xpath/internal/axes/FilterExprWalker.java6
-rw-r--r--src/com/sun/org/apache/xpath/internal/axes/WalkerFactory.java6
-rw-r--r--src/com/sun/org/apache/xpath/internal/compiler/Compiler.java36
-rw-r--r--src/com/sun/org/apache/xpath/internal/res/XPATHErrorResources.java7
5 files changed, 50 insertions, 15 deletions
diff --git a/src/com/sun/org/apache/xpath/internal/XPath.java b/src/com/sun/org/apache/xpath/internal/XPath.java
index 1601ae1..2734cc4 100644
--- a/src/com/sun/org/apache/xpath/internal/XPath.java
+++ b/src/com/sun/org/apache/xpath/internal/XPath.java
@@ -3,7 +3,7 @@
* DO NOT REMOVE OR ALTER!
*/
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2019 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -181,10 +181,12 @@ public class XPath implements Serializable, ExpressionOwner
else if (MATCH == type)
parser.initMatchPattern(compiler, exprString, prefixResolver);
else
- throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); //"Can not deal with XPath type: " + type);
+ throw new RuntimeException(XSLMessages.createXPATHMessage(
+ XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE,
+ new Object[]{Integer.toString(type)}));
// System.out.println("----------------");
- Expression expr = compiler.compile(0);
+ Expression expr = compiler.compileExpression(0);
// System.out.println("expr: "+expr);
this.setExpression(expr);
@@ -236,7 +238,7 @@ public class XPath implements Serializable, ExpressionOwner
//"Can not deal with XPath type: " + type);
// System.out.println("----------------");
- Expression expr = compiler.compile(0);
+ Expression expr = compiler.compileExpression(0);
// System.out.println("expr: "+expr);
this.setExpression(expr);
diff --git a/src/com/sun/org/apache/xpath/internal/axes/FilterExprWalker.java b/src/com/sun/org/apache/xpath/internal/axes/FilterExprWalker.java
index 40638e6..bd64a16 100644
--- a/src/com/sun/org/apache/xpath/internal/axes/FilterExprWalker.java
+++ b/src/com/sun/org/apache/xpath/internal/axes/FilterExprWalker.java
@@ -3,7 +3,7 @@
* DO NOT REMOVE OR ALTER!
*/
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2019 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -75,7 +75,7 @@ public class FilterExprWalker extends AxesWalker
m_mustHardReset = true;
case OpCodes.OP_GROUP :
case OpCodes.OP_VARIABLE :
- m_expr = compiler.compile(opPos);
+ m_expr = compiler.compileExpression(opPos);
m_expr.exprSetParent(this);
//if((OpCodes.OP_FUNCTION == stepType) && (m_expr instanceof com.sun.org.apache.xalan.internal.templates.FuncKey))
if(m_expr instanceof com.sun.org.apache.xpath.internal.operations.Variable)
@@ -85,7 +85,7 @@ public class FilterExprWalker extends AxesWalker
}
break;
default :
- m_expr = compiler.compile(opPos + 2);
+ m_expr = compiler.compileExpression(opPos + 2);
m_expr.exprSetParent(this);
}
// if(m_expr instanceof WalkingIterator)
diff --git a/src/com/sun/org/apache/xpath/internal/axes/WalkerFactory.java b/src/com/sun/org/apache/xpath/internal/axes/WalkerFactory.java
index 2f05535..385eba9 100644
--- a/src/com/sun/org/apache/xpath/internal/axes/WalkerFactory.java
+++ b/src/com/sun/org/apache/xpath/internal/axes/WalkerFactory.java
@@ -3,7 +3,7 @@
* DO NOT REMOVE OR ALTER!
*/
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2019 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1007,10 +1007,10 @@ public class WalkerFactory
case OpCodes.OP_EXTFUNCTION :
case OpCodes.OP_FUNCTION :
case OpCodes.OP_GROUP :
- expr = compiler.compile(opPos);
+ expr = compiler.compileExpression(opPos);
break;
default :
- expr = compiler.compile(opPos + 2);
+ expr = compiler.compileExpression(opPos + 2);
}
axis = Axis.FILTEREDLIST;
diff --git a/src/com/sun/org/apache/xpath/internal/compiler/Compiler.java b/src/com/sun/org/apache/xpath/internal/compiler/Compiler.java
index fd2fbae..b88b4e8 100644
--- a/src/com/sun/org/apache/xpath/internal/compiler/Compiler.java
+++ b/src/com/sun/org/apache/xpath/internal/compiler/Compiler.java
@@ -1,6 +1,5 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
@@ -71,9 +70,12 @@ import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
* of operation codes (op map) and then builds from that into an Expression
* tree.
* @xsl.usage advanced
+ * @LastModified: May 2019
*/
public class Compiler extends OpMap
{
+ // count the number of operations or calls to compileOperation
+ int countOp;
/**
* Construct a Compiler object with a specific ErrorListener and
@@ -107,15 +109,40 @@ public class Compiler extends OpMap
/**
* Execute the XPath object from a given opcode position.
+ *
+ * Note that this method is added so that when StackOverflowError is caught
+ * the address space can be freed to this point allowing further activities
+ * such as reporting the error.
+ *
* @param opPos The current position in the xpath.m_opMap array.
* @return The result of the XPath.
*
* @throws TransformerException if there is a syntax or other error.
* @xsl.usage advanced
*/
- public Expression compile(int opPos) throws TransformerException
- {
+ public Expression compileExpression(int opPos) throws TransformerException
+ {
+ try {
+ countOp = 0;
+ return compile(opPos);
+ } catch (StackOverflowError sof) {
+ error(XPATHErrorResources.ER_COMPILATION_TOO_MANY_OPERATION, new Object[]{countOp});
+ }
+ return null;
+ }
+ /**
+ * This method handles the actual compilation process. It is called from the
+ * compileExpression method as well as the subsequent processes. See the note
+ * for compileExpression.
+ *
+ * @param opPos The current position in the xpath.m_opMap array.
+ * @return The result of the XPath.
+ *
+ * @throws TransformerException if there is a syntax or other error.
+ */
+ private Expression compile(int opPos) throws TransformerException
+ {
int op = getOp(opPos);
Expression expr = null;
@@ -211,6 +238,7 @@ public class Compiler extends OpMap
private Expression compileOperation(Operation operation, int opPos)
throws TransformerException
{
+ ++countOp;
int leftPos = getFirstChildPos(opPos);
int rightPos = getNextOpPos(leftPos);
diff --git a/src/com/sun/org/apache/xpath/internal/res/XPATHErrorResources.java b/src/com/sun/org/apache/xpath/internal/res/XPATHErrorResources.java
index 12a5841..ed55af5 100644
--- a/src/com/sun/org/apache/xpath/internal/res/XPATHErrorResources.java
+++ b/src/com/sun/org/apache/xpath/internal/res/XPATHErrorResources.java
@@ -149,6 +149,8 @@ public class XPATHErrorResources extends ListResourceBundle
"ER_PREDICATE_ILLEGAL_SYNTAX";
public static final String ER_PREDICATE_TOO_MANY_OPEN =
"ER_PREDICATE_TOO_MANY_OPEN";
+ public static final String ER_COMPILATION_TOO_MANY_OPERATION =
+ "ER_COMPILATION_TOO_MANY_OPERATION";
public static final String ER_ILLEGAL_AXIS_NAME = "ER_ILLEGAL_AXIS_NAME";
public static final String ER_UNKNOWN_NODETYPE = "ER_UNKNOWN_NODETYPE";
public static final String ER_PATTERN_LITERAL_NEEDS_BE_QUOTED =
@@ -461,7 +463,10 @@ public static final String ER_IGNORABLE_WHITESPACE_NOT_HANDLED =
"'..[predicate]' or '.[predicate]' is illegal syntax. Use 'self::node()[predicate]' instead."},
{ ER_PREDICATE_TOO_MANY_OPEN,
- "Stack overflow while parsing {0} at {1}. Too many open predicates {2}."},
+ "Stack overflow while parsing {0} at {1}. Too many open predicates({2})."},
+
+ { ER_COMPILATION_TOO_MANY_OPERATION,
+ "Stack overflow while compiling the expression. Too many operations({0})."},
{ ER_ILLEGAL_AXIS_NAME,
"illegal axis name: {0}"},