Skip to content

Commit 7530c00

Browse files
committed
8266559: XPathEvaluationResult.XPathResultType.NODESET maps to incorrect type
Reviewed-by: lancea, naoto
1 parent b98e52a commit 7530c00

File tree

4 files changed

+77
-49
lines changed

4 files changed

+77
-49
lines changed

src/java.xml/share/classes/javax/xml/xpath/XPath.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -347,7 +347,11 @@ public String evaluate(String expression, InputSource source)
347347
* @param <T> The class type that will be returned by the XPath expression.
348348
* @param expression The XPath expression.
349349
* @param item The context the XPath expression will be evaluated in.
350-
* @param type The class type expected to be returned by the XPath expression.
350+
* @param type The class type expected to be returned by the XPath expression,
351+
* must be one of the types described in section
352+
* <a href="package-summary.html#XPath.Datatypes.Class">3.2 Class types</a>
353+
* in the package summary.
354+
*
351355
*
352356
* @return The result of evaluating the expression.
353357
*
@@ -440,7 +444,10 @@ default XPathEvaluationResult<?> evaluateExpression(String expression, Object it
440444
* @param <T> The class type that will be returned by the XPath expression.
441445
* @param expression The XPath expression.
442446
* @param source The input source of the document to evaluate over.
443-
* @param type The class type expected to be returned by the XPath expression.
447+
* @param type The class type expected to be returned by the XPath expression,
448+
* must be one of the types described in section
449+
* <a href="package-summary.html#XPath.Datatypes.Class">3.2 Class types</a>
450+
* in the package summary.
444451
*
445452
* @return The result of evaluating the expression.
446453
*

src/java.xml/share/classes/javax/xml/xpath/XPathEvaluationResult.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -67,11 +67,11 @@ public static enum XPathResultType {
6767
*/
6868
STRING(XPathConstants.STRING, String.class),
6969
/**
70-
* The XPath 1.0 NodeSet data type. Maps to {@link org.w3c.dom.NodeList}.
70+
* The XPath 1.0 NodeSet data type. Maps to {@link XPathNodes}.
7171
*/
7272
NODESET(XPathConstants.NODESET, XPathNodes.class),
7373
/**
74-
* The XPath 1.0 NodeSet data type. Maps to {@link org.w3c.dom.Node}.
74+
* The XPath 1.0 Node data type. Maps to {@link org.w3c.dom.Node}.
7575
*/
7676
NODE(XPathConstants.NODE, Node.class);
7777

src/java.xml/share/classes/javax/xml/xpath/XPathExpression.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -239,7 +239,10 @@ public String evaluate(InputSource source)
239239
*
240240
* @param <T> The class type that will be returned by the XPath expression.
241241
* @param item The context the XPath expression will be evaluated in.
242-
* @param type The class type expected to be returned by the XPath expression.
242+
* @param type The class type expected to be returned by the XPath expression,
243+
* must be one of the types described in section
244+
* <a href="package-summary.html#XPath.Datatypes.Class">3.2 Class types</a>
245+
* in the package summary.
243246
*
244247
* @return The result of evaluating the expression.
245248
*
@@ -330,7 +333,10 @@ default XPathEvaluationResult<?> evaluateExpression(Object item)
330333
*
331334
* @param <T> The class type that will be returned by the XPath expression.
332335
* @param source The {@code InputSource} of the document to evaluate over.
333-
* @param type The class type expected to be returned by the XPath expression.
336+
* @param type The class type expected to be returned by the XPath expression,
337+
* must be one of the types described in section
338+
* <a href="package-summary.html#XPath.Datatypes.Class">3.2 Class types</a>
339+
* in the package summary.
334340
*
335341
* @return The result of evaluating the expression.
336342
*

src/java.xml/share/classes/javax/xml/xpath/package-info.java

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -87,7 +87,7 @@
8787
* </blockquote>
8888
*
8989
* <p>
90-
* This example would select the <code>&lt;bar&gt;</code> element in
90+
* This example would select the {@code <bar>} element in
9191
* an XML document such as the following:
9292
*
9393
* <blockquote>
@@ -98,12 +98,12 @@
9898
* </pre>
9999
* </blockquote>
100100
*
101-
* <p>The expression <code>/foo/bar</code> is an example of a location
101+
* <p>The expression {@code /foo/bar} is an example of a location
102102
* path. While XPath location paths resemble Unix-style file system
103103
* paths, an important distinction is that XPath expressions return
104104
* <em>all</em> nodes that match the expression. Thus, all three
105-
* <code>&lt;bar&gt;</code> elements in the following document would be
106-
* selected by the <code>/foo/bar</code> expression:
105+
* {@code <bar>} elements in the following document would be
106+
* selected by the {@code /foo/bar} expression:
107107
*
108108
* <blockquote>
109109
* <pre>
@@ -116,9 +116,9 @@
116116
* </blockquote>
117117
*
118118
* <p>
119-
* A special location path operator, <code>//</code>, selects nodes at
119+
* A special location path operator, {@code //}, selects nodes at
120120
* any depth in an XML document. The following example selects all
121-
* <code>&lt;bar&gt;</code> elements regardless of their location in a
121+
* {@code <bar>} elements regardless of their location in a
122122
* document:
123123
*
124124
* <blockquote>
@@ -130,7 +130,7 @@
130130
* <p>
131131
* A wildcard operator, *, causes all element nodes to be selected.
132132
* The following example selects all children elements of a
133-
* <code>&lt;foo&gt;</code> element:
133+
* {@code <foo>} element:
134134
*
135135
* <blockquote>
136136
* <pre>
@@ -158,30 +158,30 @@
158158
* <code>/foo/bar/<strong>@id</strong></code>
159159
* </th>
160160
* <td>
161-
* Selects the attribute <code>id</code> of the <code>&lt;bar&gt;</code> element
161+
* Selects the attribute {@code id} of the {@code <bar>} element
162162
* </td>
163163
* </tr>
164164
* <tr>
165165
* <th scope="row"><code>/foo/bar/<strong>text()</strong></code>
166166
* </th>
167167
* <td>
168-
* Selects the text nodes of the <code>&lt;bar&gt;</code> element. No
168+
* Selects the text nodes of the {@code <bar>} element. No
169169
* distinction is made between escaped and non-escaped character data.
170170
* </td>
171171
* </tr>
172172
* <tr>
173173
* <th scope="row"><code>/foo/bar/<strong>comment()</strong></code>
174174
* </th>
175175
* <td>
176-
* Selects all comment nodes contained in the <code>&lt;bar&gt;</code> element.
176+
* Selects all comment nodes contained in the {@code <bar>} element.
177177
* </td>
178178
* </tr>
179179
* <tr>
180180
* <th scope="row"><code>/foo/bar/<strong>processing-instruction()</strong></code>
181181
* </th>
182182
* <td>
183183
* Selects all processing-instruction nodes contained in the
184-
* <code>&lt;bar&gt;</code> element.
184+
* {@code <bar>} element.
185185
* </td>
186186
* </tr>
187187
* </tbody>
@@ -191,8 +191,8 @@
191191
* Predicates allow for refining the nodes selected by an XPath
192192
* location path. Predicates are of the form
193193
* <code>[<em>expression</em>]</code>. The following example selects all
194-
* <code>&lt;foo&gt;</code> elements that contain an <code>include</code>
195-
* attribute with the value of <code>true</code>:
194+
* {@code <foo>} elements that contain an {@code include}
195+
* attribute with the value of {@code true}:
196196
*
197197
* <blockquote>
198198
* <pre>
@@ -219,9 +219,9 @@
219219
* following data types:
220220
*
221221
* <ul>
222-
* <li><code>Boolean</code></li>
223-
* <li><code>Number</code></li>
224-
* <li><code>String</code></li>
222+
* <li>{@code Boolean}</li>
223+
* <li>{@code Number}</li>
224+
* <li>{@code String}</li>
225225
* </ul>
226226
*
227227
* <a id="XPath.Datatypes.QName"></a>
@@ -239,55 +239,70 @@
239239
* <p>
240240
* The return type is specified by a {@link javax.xml.namespace.QName} parameter
241241
* in method call used to evaluate the expression, which is either a call to
242-
* <code>XPathExpression.evalute(...)</code> or <code>XPath.evaluate(...)</code>
242+
* {@code XPathExpression.evalute(...)} or {@code XPath.evaluate(...)}
243243
* methods.
244244
*
245245
* <p>
246-
* When a <code>Boolean</code> return type is requested,
247-
* <code>Boolean.TRUE</code> is returned if one or more nodes were
248-
* selected; otherwise, <code>Boolean.FALSE</code> is returned.
246+
* When a {@code Boolean} return type is requested,
247+
* {@code Boolean.TRUE} is returned if one or more nodes were
248+
* selected; otherwise, {@code Boolean.FALSE} is returned.
249249
*
250250
* <p>
251-
* The <code>String</code> return type is a convenience for retrieving
251+
* The {@code String} return type is a convenience for retrieving
252252
* the character data from a text node, attribute node, comment node, or
253253
* processing-instruction node. When used on an element node, the value
254254
* of the child text nodes is returned.
255255
*
256256
* <p>
257-
* The <code>Number</code> return type attempts to coalesce the text
258-
* of a node to a <code>double</code> data type.
257+
* The {@code Number} return type attempts to coalesce the text
258+
* of a node to a {@code double} data type.
259259
*
260260
* <a id="XPath.Datatypes.Class"></a>
261261
* <h2>3.2 Class types</h2>
262262
* In addition to the QName types, the XPath API supports the use of Class types
263-
* through the <code>XPathExpression.evaluteExpression(...)</code> or
264-
* <code>XPath.evaluateExpression(...)</code> methods.
263+
* through the {@code XPathExpression.evaluateExpression(...)} or
264+
* {@code XPath.evaluateExpression(...)} methods.
265265
*
266266
* The XPath data types are mapped to Class types as follows:
267267
* <ul>
268-
* <li><code>Boolean</code> -- <code>Boolean.class</code></li>
269-
* <li><code>Number</code> -- <code>Number.class</code></li>
270-
* <li><code>String</code> -- <code>String.class</code></li>
271-
* <li><code>Nodeset</code> -- <code>XPathNodes.class</code></li>
272-
* <li><code>Node</code> -- <code>Node.class</code></li>
268+
* <li>{@code Boolean} -- {@code Boolean.class}</li>
269+
* <li>{@code Number} -- {@code Number.class}</li>
270+
* <li>{@code String} -- {@code String.class}</li>
271+
* <li>{@code Nodeset} -- {@code XPathNodes.class}</li>
272+
* <li>{@code Node} -- {@code Node.class}</li>
273273
* </ul>
274274
*
275275
* <p>
276-
* Of the subtypes of Number, only Double, Integer and Long are supported.
276+
* Of the subtypes of {@code Number}, only {@code Double, Integer} and {@code Long} are supported.
277277
*
278278
* <a id="XPath.Datatypes.Enum"></a>
279279
* <h2>3.3 Enum types</h2>
280280
* Enum types are defined in {@link javax.xml.xpath.XPathEvaluationResult.XPathResultType}
281281
* that provide mappings between the QName and Class types above. The result of
282-
* evaluating an expression using the <code>XPathExpression.evaluteExpression(...)</code>
283-
* or <code>XPath.evaluateExpression(...)</code> methods will be of one of these types.
282+
* evaluating an expression using the {@code XPathExpression.evaluateExpression(...)}
283+
* or {@code XPath.evaluateExpression(...)} methods will be of one of these types.
284+
* <p>
285+
* Note the differences between the Enum and <a href="#XPath.Datatypes.QName">QName</a>
286+
* mappings:
287+
* <ul>
288+
* <li>{@link javax.xml.xpath.XPathConstants#NUMBER NUMBER}<br>
289+
* The Enum mapping for {@link javax.xml.xpath.XPathConstants#NUMBER NUMBER}
290+
* supports {@code Double, Integer} and {@code Long}.<br><br>
291+
* </li>
292+
* <li>{@link javax.xml.xpath.XPathConstants#NODESET NODESET}<br>
293+
* The Enum mapping for {@link javax.xml.xpath.XPathConstants#NODESET NODESET}
294+
* is {@link javax.xml.xpath.XPathNodes XPathNodes} instead of
295+
* {@link org.w3c.dom.NodeList NodeList} in the
296+
* <a href="#XPath.Datatypes.QName">QName</a> mapping.
297+
* </li>
298+
* </ul>
284299
*
285300
* <a id="XPath.Context"></a>
286301
* <h2>4. XPath Context</h2>
287302
*
288303
* <p>
289304
* XPath location paths may be relative to a particular node in the
290-
* document, known as the <code>context</code>. A context consists of:
305+
* document, known as the {@code context}. A context consists of:
291306
* <ul>
292307
* <li>a node (the context node)</li>
293308
* <li>a pair of non-zero positive integers (the context position and the context size)</li>
@@ -316,7 +331,7 @@
316331
* </blockquote>
317332
*
318333
* <p>
319-
* The <code>&lt;widget&gt;</code> element can be selected with the following process:
334+
* The {@code <widget>} element can be selected with the following process:
320335
*
321336
* <blockquote>
322337
* <pre>
@@ -335,9 +350,9 @@
335350
* </blockquote>
336351
*
337352
* <p>
338-
* With a reference to the <code>&lt;widget&gt;</code> element, a
353+
* With a reference to the {@code <widget>} element, a
339354
* relative XPath expression can be written to select the
340-
* <code>&lt;manufacturer&gt;</code> child element:
355+
* {@code <manufacturer>} child element:
341356
*
342357
* <blockquote>
343358
* <pre>
@@ -363,7 +378,7 @@
363378
* NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
364379
*
365380
* //or using the evaluateExpression method
366-
* XPathNodes nodes = xpath.evaluate(expression, inputSource, XPathNodes.class);
381+
* XPathNodes nodes = xpath.evaluateExpression(expression, inputSource, XPathNodes.class);
367382
* </pre>
368383
* </blockquote>
369384
*
@@ -390,7 +405,7 @@
390405
* {@code evaluateExpression} method such as the following code:
391406
* <blockquote>
392407
* <pre>
393-
* int count = xpath.evaluate("count(/widgets/widget)", document, Integer.class);
408+
* int count = xpath.evaluateExpression("count(/widgets/widget)", document, Integer.class);
394409
* </pre>
395410
* </blockquote>
396411
*

0 commit comments

Comments
 (0)