Skip to content

Commit

Permalink
Added fix for NPE for objects with methods 'get' or 'is' (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
cliedeman authored and bpatters committed Feb 10, 2017
1 parent 541d281 commit ec73016
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,13 @@ private void buildGenericArgumentTypeMap(ParameterizedType type) {

private Optional<String> getFieldNameFromMethod(Method m) {
Optional<String> fieldName = Optional.absent();
if (m.getName().startsWith("get")) {

// Do not match 'get' method
if (m.getName().startsWith("get") && m.getName().length() > 3) {
fieldName = Optional.of(m.getName().substring(3, 4).toLowerCase() + m.getName().substring(4));
}
if (m.getName().startsWith("is")) {
// Do not match 'is' method
if (m.getName().startsWith("is") && m.getName().length() > 2) {
fieldName = Optional.of(m.getName().substring(2, 3).toLowerCase() + m.getName().substring(3));
}
GraphQLQuery query = m.getAnnotation(GraphQLQuery.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,28 @@ public void testAbstractMethods() {
assertEquals("field1", objectType.getFieldDefinition("field1").getName());
assertEquals(Scalars.GraphQLInt, objectType.getFieldDefinition("field1").getType());
}

public class GetAndIs {
public GetAndIs get() {
return this;
}

public boolean is(Object obj) {
return this == obj;
}
}

/**
* Issue #10
*/
@Test
public void testGetAndIs() {
IGraphQLObjectMapper graphQLObjectMapper = newGraphQLObjectMapper(
ImmutableList.<IGraphQLTypeMapper> builder().addAll(GraphQLSchemaBuilder.getDefaultTypeMappers()).build());

GraphQLObjectType objectType = (GraphQLObjectType) graphQLObjectMapper.getOutputType(new TypeToken<GetAndIs>() {
}.getType());

assertTrue(objectType.getFieldDefinitions().isEmpty());
}
}

0 comments on commit ec73016

Please sign in to comment.