Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Comments

@tutufool
Copy link

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 pushed a commit to tutufool/protobuf-codec that referenced this issue Jan 22, 2013
sijuv#5
XML codec throw java.util.NoSuchElementException when message is too long

sijuv#4
XML codec failed due to special charecter like '\u0000'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant