Skip to content

memory leaks and thread-safety violations when deserializing types with object ids #490

Closed
@hearnden

Description

@hearnden

Problem:
The lifecycle of SimpleObjectIdResolver is obviously meant to be scoped by a call to Object{Mapper,Reader}.readValue(), since it is not threadsafe and accumulates ids forever. However, it is getting cached along with long-lived deserializers, and re-used across threads and across multiple calls to Object{Mapper,Reader}.readValue(). This violates thread safety and is a memory leak.

Jackson version: 2.4+ (ObjectIdResolver appears not to exist in <2.4).

How to reproduce:

  • Make a class Foo that uses object ids with @JsonIdentityInfo
  • Write code like
String json = mapper.writeValueAsString(...);
mapper.readValue(json, Foo.class);
mapper.readValue(json, Foo.class);
  • Put breakpoint in SimpleObjectIdResolver's constructor

Expected results:
SimpleObjectIdResolver is constructed twice (once per call to readValue()).

Observed results:
SimpleObjectIdResolver is constructed only once.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions