question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`StackOverflowError` in Dynamic `StdKeySerializer`

See original GitHub issue

There seem to be a problem (checked and doesn’t seem to be fixed in latest version) with the serialize method of the Dynamic static class of the StdKeySerializer.

        @Override
        public void serialize(Object value, JsonGenerator g, SerializerProvider provider)
                throws IOException
        {
            Class<?> cls = value.getClass();
            PropertySerializerMap m = _dynamicSerializers;
            JsonSerializer<Object> ser = m.serializerFor(cls);
            if (ser == null) {
                ser = _findAndAddDynamic(m, cls, provider);
            }
            ser.serialize(value, g, provider);
        }

The problem comes from the fact that when ser is null, the new ser returned by _findAndAddDynamic is incorrectly filled.

        protected JsonSerializer<Object> _findAndAddDynamic(PropertySerializerMap map,
                Class<?> type, SerializerProvider provider) throws JsonMappingException
        {
            PropertySerializerMap.SerializerAndMapResult result =
                    // null -> for now we won't keep ref or pass BeanProperty; could change
                    map.findAndAddKeySerializer(type, provider, null);
            // did we get a new map of serializers? If so, start using it
            if (map != result.map) {
                _dynamicSerializers = result.map;
            }
            return result.serializer;
        }

So say we are in ser#1, ser#1._dynamicSerializers now has the correct PropertySerializerMap$Single. However, result.serializer._dynamicSerializers has PropertySerializerMap$Empty. Therefore, a new call with that result ser#2 is made which ends up creating an infinite loop.

Possible fix:

  • replace _dynamicSerializers = result.map; by result.serializer._dynamicSerializers = result.map

If I’m mistaken please let me know, but It seems obvious when debugging that something’s is not working as intended

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Jun 27, 2017

@kpronovost I think I can figure out this case, but it probably does make sense to use a work-around in the meantime. But I think it’s good to fix this as the reproduction looks like something that would occur quite easily.

0reactions
kpronovostcommented, Jun 27, 2017

Thanks for the quick reply.

I already patched with realistic data in all test cases, I linked this issue to our Merge Request and will remove unneeded patch once this is resolved in a later version.

TLDR: Thanks for the fix; not a blocker.

Read more comments on GitHub >

github_iconTop Results From Across the Web

StackOverflowError in Dynamic StdKeySerializer #1679 - GitHub
There seem to be a problem (checked and doesn't seem to be fixed in latest version) with the serialize method of the Dynamic...
Read more >
java.lang.StackOverflowError with jackson json and spring ...
The problem is that the event object itself references the session object. So if jackson reaches the session field in the event object...
Read more >
StdKeySerializers.Dynamic (jackson-databind 2.9.0 API)
Method that can be called to ask implementation to serialize values of type this serializer handles. Methods inherited from class com.fasterxml.jackson.databind ...
Read more >
com.fasterxml.jackson.databind.ser.std.StdKeySerializers ...
StdKeySerializers maven / gradle build tool code. The class is part of the package ➦ Group: com.fasterxml.jackson.core ➦ Artifact: jackson-databind ...
Read more >
StackOverflowError in Java with examples - GeeksforGeeks
StackOverflowError is an error which Java doesn't allow to catch, for instance, stack running out of space, as it's one of the most...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found