Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guava's RangeHelper causing NPE in PropertyNamingStrategy #79

Closed
arpit-pp opened this issue Oct 20, 2020 · 1 comment
Closed

Guava's RangeHelper causing NPE in PropertyNamingStrategy #79

arpit-pp opened this issue Oct 20, 2020 · 1 comment
Milestone

Comments

@arpit-pp
Copy link

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
Copy link
Member

cowtowncoder commented Oct 20, 2020

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants