1
votes

I am developing a Client-Server-application which uses Google Protocol Buffers. Unfortunatelly when I am building the protocol buffer response on the server side using the builder pattern I get a IndexOutOfBoundsException:

This is the line where I build the protobuf file:

Builder getVGResonseBuilder = App_getVGResponse.GetVGResponse.newBuilder().getVGBuilder(0);
[some more code that uses the builder patterns]
getVGResponseBuilder.set...
getVGResponseBuilder.set...

the error occures in the first line of code.

here is the protobuf definition (ofc I have compiled it! The compiled calss is App_getVGResponse):

message GetVGResponse {

    message VG {
        optional string id = 1;
        optional string g_id = 2;
        optional int64 f_id = 3;
        optional string g_name = 4;
    }

    repeated VG v_gp = 1;
}

Here is a excerpt of my stacktrace

Exception in thread "main" com.google.protobuf.InvalidProtocolBufferException: **Protocol message tag had invalid wire type.**
    at com.google.protobuf.InvalidProtocolBufferException.invalidWireType(InvalidProtocolBufferException.java:78)
    at com.google.protobuf.UnknownFieldSet$Builder.mergeFieldFrom(UnknownFieldSet.java:498)
    at com.google.protobuf.GeneratedMessage$Builder.parseUnknownField(GeneratedMessage.java:439)

and the debugger at runtime shows ma the variable:

e
-> cause: IndexOutOfBoundsException (id=12291)
-> detaiMessage: Index: 0, Size: 0 (id=12324)
-> stackTrace null
1
which implementation is this?Marc Gravell
I don t fully understand which information you need. The server and the client both run java code. I use the protobuf 2.4.1 library.RCK69
that was the question I was asking; there are lots of implementations (some by Google, some by the community), and many of the implementations will have very similar usage semantics. Knowing that you're using the java version narrows it down a lot!Marc Gravell
added stack trace and runtime variable to initial questionRCK69

1 Answers

1
votes

personally I create the "child builder" then add it to the parent builder. i.e.

    App_GetVGResponse.GetVGResponse.Builder bldr = App_GetVGResponse.GetVGResponse.newBuilder();
    App_GetVGResponse.GetVGResponse.VG.Builder childBldr = App_GetVGResponse.GetVGResponse.VG.newBuilder();

    childBldr.setId(value);
            ...........

    bldr.addVGp(childBldr);

I think the error is because you get the "child" builder before adding one