Skip to content

TypeFactory.constructFromCanonical() throws NPE for Unparameterized generic canonical strings #1941

@ayushgp

Description

@ayushgp

When TypeFactory.constructFromCanonical(returnType) is used in 2.6.1, the returnType string for generic types is not expected to have parameterized type information. For example, the following code runs fine on 2.6.1:

returnType = "java.util.List";
objectMapper.getTypeFactory().constructFromCanonical(returnType);

But in version 2.8.7, the same code gives a NullPointerException with the stack trace:

java.rmi.RemoteException: java.lang.NullPointerException:null. 
    at com.fasterxml.jackson.databind.type.TypeFactory._fromVariable(TypeFactory.java:1421)
    at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1182)
    at com.fasterxml.jackson.databind.type.TypeFactory._fromParamType(TypeFactory.java:1404)
    at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1172)
    at com.fasterxml.jackson.databind.type.TypeFactory._resolveSuperInterfaces(TypeFactory.java:1318)
    at com.fasterxml.jackson.databind.type.TypeFactory._fromClass(TypeFactory.java:1261)
    at com.fasterxml.jackson.databind.type.TypeParser.parseType(TypeParser.java:60)
    at com.fasterxml.jackson.databind.type.TypeParser.parse(TypeParser.java:33)
    at com.fasterxml.jackson.databind.type.TypeFactory.constructFromCanonical(TypeFactory.java:544)
    at foo.company.package.serialize.Serializer.deserialize(Serializer.java:355)

But if the returnType string is passed with the generic type information, even if it is passed as Object, ie, returnType = "java.util.List<java.lang.Object>";, it works fine.

I have 2 questions, is there a way to make this change backward compatible? If not, how can I work around this? PS: The workaround given by Tatu in the mailing list is not clear to me, if someone can give me an example, it'd be great help. Thanks!

Link to google groups thread.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions