Skip to content

Nested serialization throws NullPointerException #508

@thaarok

Description

@thaarok

When serializing object whose getter use MessagePack serialization, the inner serialization breaks the outer serialization and it throws NullPointerException:

java.lang.NullPointerException
	at com.fasterxml.jackson.core.util.ByteArrayBuilder.write(ByteArrayBuilder.java:224)
	at org.msgpack.core.buffer.OutputStreamBufferOutput.write(OutputStreamBufferOutput.java:78)
	at org.msgpack.core.buffer.OutputStreamBufferOutput.writeBuffer(OutputStreamBufferOutput.java:71)
	at org.msgpack.core.MessagePacker.flushBuffer(MessagePacker.java:306)
	at org.msgpack.core.MessagePacker.flush(MessagePacker.java:281)
	at org.msgpack.core.MessagePacker.close(MessagePacker.java:296)
	at org.msgpack.jackson.dataformat.MessagePackGenerator.close(MessagePackGenerator.java:509)
	at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3911)
	at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsBytes(ObjectMapper.java:3244)
	at org.msgpack.jackson.dataformat.MessagePackFactoryTest.testNestedSerialization(MessagePackFactoryTest.java:62)

It tries to write into ByteArrayBuilder which is already released/closed.

Reproducible using following test: (feel free to include this or derivated into msgpack tests)

    @Test
    public void testNestedSerialization() throws Exception
    {
        ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
        objectMapper.writeValueAsBytes(new OuterClass());
    }

    public class OuterClass
    {
        public String getInner() throws JsonProcessingException
        {
            ObjectMapper m = new ObjectMapper(new MessagePackFactory());
            m.writeValueAsBytes(new InnerClass());
            return "EFG";
        }
    }

    public class InnerClass
    {
        public String getName()
        {
            return "ABC";
        }
    }

Identical test using standard (JSON) ObjectMapper works ok - only MessagePack is affected.

Metadata

Metadata

Assignees

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