Skip to content

XML codec throw java.util.NoSuchElementException when message is too long #5

@tutufool

Description

@tutufool

Hi,

I got below exception when using XML codec:

java.lang.RuntimeException: java.util.NoSuchElementException
at protobuf.codec.AbstractCodec.toMessage(AbstractCodec.java:74)
at protobuf.codec.AbstractCodec.toMessage(AbstractCodec.java:88)
at protobuf.codec.AbstractCodec.toMessage(AbstractCodec.java:83)

...
...
Caused by: java.util.NoSuchElementException
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1114)
at protobuf.codec.xml.XmlReader.parseElement(XmlReader.java:52)
at protobuf.codec.xml.XmlReader.parse(XmlReader.java:41)
at protobuf.codec.xml.XmlCodec.readFromStream(XmlCodec.java:56)
at protobuf.codec.AbstractCodec.toMessage(AbstractCodec.java:70)
... 26 more

to reproduce:

create a simple proto:

message MyObject{
optional string name = 1;
optional string value = 2;
}

java code:

    try {

        MyObject before = MyObject.newBuilder()
                .setName("123456789")
                //
                .setValue(
                        "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")//
                .build();

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        Codec codec = new XmlCodec();

        codec.fromMessage(before, outputStream);
        System.out.println(outputStream.toString());

        MyObject after = codec.toMessage(MyObject.class, new ByteArrayInputStream(outputStream.toByteArray()));

        Assert.assertEquals(after, before);
        Assert.assertEquals(after.getName(), before.getName());
        Assert.assertEquals(after.getValue(), before.getValue());
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }

You can try using shorter string for setValue() and longer string for setName() to reproduce.

btw, if you change to use JsonCodec, the above case can pass.

Thanks
Ma Ling

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions