Skip to content

Commit 80d2802

Browse files
fgualliniJoeWang-Java
authored andcommittedMay 5, 2020
8183266: [TESTBUG]Add test to cover XPathEvaluationResult.XPathResultType.getQNameType method
Reviewed-by: joehw
1 parent a899004 commit 80d2802

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed
 

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, 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
@@ -85,25 +85,38 @@ public static enum XPathResultType {
8585
/**
8686
* Compares this type to the specified class type.
8787
* @param clsType class type
88-
* @return true if the argument is not null and is a class type that
88+
* @return true if the argument is not null and is a class type or accepted subtype that
8989
* matches that this type represents, false otherwise.
9090
*/
9191
private boolean equalsClassType(Class<?> clsType) {
92-
Objects.nonNull(clsType);
93-
if (clsType.isAssignableFrom(this.clsType)) {
92+
if (Objects.nonNull(clsType) && this.clsType.isAssignableFrom(clsType)) {
93+
if (this.clsType == Number.class) {
94+
return isAcceptedNumberSubType(clsType);
95+
}
9496
return true;
9597
}
9698
return false;
9799
}
98100

101+
/**
102+
* Compares the specified class type to accepted subtypes of number.
103+
* @param clsType class type
104+
* @return true if class type is an accepted subtype of Number, false otherwise
105+
*/
106+
private boolean isAcceptedNumberSubType(Class<?> clsType) {
107+
return clsType.isAssignableFrom(Double.class) ||
108+
clsType.isAssignableFrom(Integer.class) ||
109+
clsType.isAssignableFrom(Long.class);
110+
}
111+
99112
/**
100113
* Returns the QName type as specified in {@link XPathConstants} that
101114
* corresponds to the specified class type.
102115
* @param clsType a class type that the enum type supports
103116
* @return the QName type that matches with the specified class type,
104117
* null if there is no match
105118
*/
106-
static public QName getQNameType(Class<?> clsType) {
119+
static public QName getQNameType(Class<?> clsType) {
107120
for (XPathResultType type : XPathResultType.values()) {
108121
if (type.equalsClassType(clsType)) {
109122
return type.qnameType;

0 commit comments

Comments
 (0)
Please sign in to comment.