Skip to content

Commit 7e5987e

Browse files
authored
ResultPath: Check object type before casting to int (graphql-java#3765)
* Check object type before casting to int * ResultPathTest: Check object type before casting to int
1 parent 3e5c77b commit 7e5987e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/main/java/graphql/execution/ResultPath.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ public static ResultPath fromList(List<?> objects) {
149149
for (Object object : objects) {
150150
if (object instanceof String) {
151151
path = path.segment(((String) object));
152-
} else {
152+
} else if (object instanceof Integer) {
153153
path = path.segment((int) object);
154+
} else if (object != null) {
155+
path = path.segment(object.toString());
154156
}
155157
}
156158
return path;

src/test/groovy/graphql/execution/ResultPathTest.groovy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ class ResultPathTest extends Specification {
212212
path.toList() == ["a", "b"]
213213
}
214214

215+
def "pass any other object than string or int"(){
216+
when:
217+
ResultPath.fromList(["a", "b", true])
218+
219+
then:
220+
notThrown(ClassCastException)
221+
}
215222

216223
def "can append paths"() {
217224
when:

0 commit comments

Comments
 (0)