FasterXML / jackson-datatypes-collections

Jackson project that contains various collection-oriented datatype libraries: Eclipse Collections, Guava, HPPC, PCollections
Apache License 2.0
79 stars 53 forks source link

Guava's RangeHelper causing NPE in PropertyNamingStrategy #79

Closed arpit-pp closed 4 years ago

arpit-pp commented 4 years ago

I'm using Dropwizard which automatically configures Jackson at startup using the following code:

private static ObjectMapper configure(ObjectMapper mapper) {
        mapper.registerModule(new GuavaModule());
        mapper.registerModule(new GuavaExtrasModule());
        mapper.registerModule(new JodaModule());
        mapper.registerModule(new AfterburnerModule());
        mapper.registerModule(new FuzzyEnumModule());
        mapper.registerModule(new ParameterNamesModule());
        mapper.registerModule(new Jdk8Module());
        mapper.registerModule(new JavaTimeModule());
        mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
        mapper.setSubtypeResolver(new DiscoverableSubtypeResolver());
        return mapper;
    }

Guava's RangeHelper is calling AnnotationSensitivePropertyNamingStrategy.nameForField with null value for AnnotatedField param which is resulting in an NPE.

Stacktrace:

java.lang.NullPointerException
    at io.dropwizard.jackson.AnnotationSensitivePropertyNamingStrategy.nameForField(AnnotationSensitivePropertyNamingStrategy.java:39)
    at com.fasterxml.jackson.datatype.guava.deser.util.RangeHelper._find(RangeHelper.java:43)
    at com.fasterxml.jackson.datatype.guava.deser.util.RangeHelper.getPropertyNames(RangeHelper.java:35)
    at com.fasterxml.jackson.datatype.guava.deser.RangeDeserializer.createContextual(RangeDeserializer.java:96)
    at com.fasterxml.jackson.databind.DeserializationContext.handlePrimaryContextualization(DeserializationContext.java:665)
cowtowncoder commented 4 years ago

@arpit-pp Ok, looking at code, I think that Guava module should not pass null as accessor (Field, Method), and will see if that can be fixed.

But I would suggest also filing an issue for DropWizard since it may make sense to add a workaround there to work around the issue -- this avoids issues when used with existing Jackson versions.

One challenge here is that the default Jackson PropertyNamingStrategy makes no use of accessor, and hence is not affected by Guava module's call with null.