Skip to content

Commit 7a8e903

Browse files
author
omavi
authored
Avoids ArrayIndexOutOfBoundsException for description of only newline (#2053) (#2069)
* Adds test for field description of only a newline character (#2053) * Avoids ArrayIndexOutOfBoundsException for description of only newline (#2053)
1 parent 558aeaa commit 7a8e903

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/main/java/graphql/schema/idl/SchemaPrinter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ private void printComments(PrintWriter out, Object graphQLType, String prefix) {
945945
List<String> lines = Arrays.asList(descriptionText.split("\n"));
946946
if (options.isDescriptionsAsHashComments()) {
947947
printMultiLineHashDescription(out, prefix, lines);
948-
} else {
948+
} else if (!lines.isEmpty()) {
949949
if (lines.size() > 1) {
950950
printMultiLineDescription(out, prefix, lines);
951951
} else {

src/test/groovy/graphql/schema/idl/SchemaPrinterTest.groovy

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,28 @@ type Query {
663663
'''
664664
}
665665

666+
def "arrayIndexOutOfBoundsException should not occur if a field description of only a newline is passed"() {
667+
given:
668+
GraphQLFieldDefinition fieldDefinition = newFieldDefinition()
669+
.name("field")
670+
.description("\n")
671+
.type(GraphQLString)
672+
.build()
673+
674+
def queryType = new MyTestGraphQLObjectType("Query", "test", Arrays.asList(fieldDefinition))
675+
def schema = GraphQLSchema.newSchema().query(queryType).build()
676+
677+
when:
678+
def result = new SchemaPrinter(noDirectivesOption).print(schema)
679+
680+
then:
681+
result == '''"test"
682+
type Query {
683+
field: String
684+
}
685+
'''
686+
}
687+
666688
def "schema will be sorted"() {
667689
def schema = TestUtil.schema("""
668690
type Query {

0 commit comments

Comments
 (0)