Skip to content

Infinite recursion when deserializing a class extending a Map, with a recursive value type. #1658

@newkek

Description

@newkek

Hello, I am using jackson-databind 2.8.8, and have a class with an unusual definition (extending a Map, where the values are of the type of the same class). It seems like I am facing an infinite recursion issue.

To reproduce you can re-use or inspire from the class defined here.

Then, when executing the following code:

        Tree t = new Tree("hello", new Tree("world"));

        ObjectMapper om = new ObjectMapper();
        final TypeResolverBuilder<?> typer = new StdTypeResolverBuilder()
                .init(JsonTypeInfo.Id.CLASS, null)
                .inclusion(JsonTypeInfo.As.PROPERTY)
                .typeProperty(GraphSONTokens.CLASS);
        om.setDefaultTyping(typer);

        String res = om.writeValueAsString(t);
        Object tRead = om.readValue(res, Tree.class);

When calling readValue() the mapper throws a StackOverflowException , here's the stacktrace:

java.lang.StackOverflowError
	at org.apache.tinkerpop.shaded.jackson.databind.type.MapLikeType.equals(MapLikeType.java:305)
	at org.apache.tinkerpop.shaded.jackson.databind.type.ResolvedRecursiveType.equals(ResolvedRecursiveType.java:110)
	at org.apache.tinkerpop.shaded.jackson.databind.type.MapLikeType.equals(MapLikeType.java:305)
	at org.apache.tinkerpop.shaded.jackson.databind.type.ResolvedRecursiveType.equals(ResolvedRecursiveType.java:110)
	at org.apache.tinkerpop.shaded.jackson.databind.type.MapLikeType.equals(MapLikeType.java:305)
	at org.apache.tinkerpop.shaded.jackson.databind.type.ResolvedRecursiveType.equals(ResolvedRecursiveType.java:110)
	at org.apache.tinkerpop.shaded.jackson.databind.type.MapLikeType.equals(MapLikeType.java:305)
	at org.apache.tinkerpop.shaded.jackson.databind.type.ResolvedRecursiveType.equals(ResolvedRecursiveType.java:110)
	at org.apache.tinkerpop.shaded.jackson.databind.type.MapLikeType.equals(MapLikeType.java:305)
[...]

Looking briefly into the code, it seems like because of the recursive definition of the class, the equals call in MapLikeType may never get out of this loop. Any idea?

Thanks.

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