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

Open
tutufool opened this Issue Jan 18, 2013 · 0 comments

1 participant

@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

@tutufool tutufool pushed a commit to tutufool/protobuf-codec that referenced this issue Jan 22, 2013
lma fix bugs:
#5
XML codec throw java.util.NoSuchElementException when message is too long

#4
XML codec failed due to special charecter like '\u0000'
199d2f0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment