Skip to content

Commit 5c242a1

Browse files
committed
graphql-java#1650 - fixing annoying async test
1 parent 1ea2ed2 commit 5c242a1

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎src/main/java/graphql/GraphqlErrorBuilder.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ private GraphqlErrorBuilder() {
5050
}
5151

5252
public GraphqlErrorBuilder message(String message, Object... formatArgs) {
53-
this.message = String.format(assertNotNull(message), formatArgs);
53+
if (formatArgs == null || formatArgs.length == 0) {
54+
this.message = assertNotNull(message);
55+
} else {
56+
this.message = String.format(assertNotNull(message), formatArgs);
57+
}
5458
return this;
5559
}
5660

‎src/test/groovy/graphql/GraphqlErrorBuilderTest.groovy‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,38 @@ class GraphqlErrorBuilderTest extends Specification {
7676
graphQLError.getPath() == ["field"]
7777
graphQLError.getLocations() == [new SourceLocation(1, 3)]
7878
}
79+
80+
def "java string format is safe"() {
81+
when:
82+
def gqlErr = GraphqlErrorBuilder.newError().message("This has %s in it").build()
83+
then:
84+
gqlErr.getMessage() == "This has %s in it"
85+
86+
when:
87+
gqlErr = GraphqlErrorBuilder.newError().message("This has %s in it", null).build()
88+
then:
89+
gqlErr.getMessage() == "This has %s in it"
90+
91+
when:
92+
gqlErr = GraphqlErrorBuilder.newError().message("This has %s in it", new Object[0]).build()
93+
then:
94+
gqlErr.getMessage() == "This has %s in it"
95+
96+
when:
97+
gqlErr = GraphqlErrorBuilder.newError().message("This has %s in it", "data").build()
98+
then:
99+
gqlErr.getMessage() == "This has data in it"
100+
}
101+
102+
def "null message is not acceptable"() {
103+
when:
104+
GraphqlErrorBuilder.newError().message(null, "a", "b").build()
105+
then:
106+
thrown(AssertException)
107+
108+
when:
109+
GraphqlErrorBuilder.newError().message(null).build()
110+
then:
111+
thrown(AssertException)
112+
}
79113
}

0 commit comments

Comments
 (0)