The file you attached is not useful without source code. But what would be even better is if you could provide the stack trace for the NullPointerException. The parser should never throw NPE and I'm not aware of any bugs which cause it to throw NPE.
BTW, it's very easy for bytes which are not actually a protocol buffer to parse correctly as a protocol buffer. The protobuf encoding is pretty dense. So I would suggest that you instead use some sort of tagging mechanism to distinguish protobuf data from other kinds of data that you need to process. On Mon, Dec 6, 2010 at 2:41 AM, jim horng <jimho...@gmail.com> wrote: > Hi all, > > It occur to me that when I'm trying to parse any of the binary data > files I listed below, > using <Message>.parseFrom(byte ). it said nullpointer exception. > > To my best knowledge, I think when the raw bytes does not contain > required field, protobuf API should return invalidprotobufexception > when using .parseFrom(), or at least it will throw > uninitializeprotobuf exception when .build(). > so that client will know what happen and have change to handle them > correctly. > But if it return nullpointerexception, it will be hard to know what > really happen, it can only be roughly assumed message parsing is > failed. > My goal is just to determine if the received binary files is an > expected protobuf message or not. > > Please kindly advise or if this is work as design under some reason. > Thanks a lot ! > > > > <code snippet> > String filepath = "np1.pb"; > byte file_byteary = getBytesFromFile(new File(filepath)); > > xxx.Connection.Builder conn_builder = > xxx.Connection.newBuilder(); > xxx.Connection MB_tmp = > xxx.Connection.parseFrom(file_byteary); > conn_builder.mergeFrom(MB_tmp); > System.out.println("is init?" + conn_builder.isInitialized()); > assertTrue(conn_builder.build() != null); > </code snippet> > > * test data > > https://docs.google.com/leaf?id=0B9CkCymjWlZLNWMyMGNiNjEtMDJiZi00NDY0LTgzMWUtMjI1N2I0MWVhNjlh&hl=en > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To post to this group, send email to proto...@googlegroups.com. > To unsubscribe from this group, send email to > protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/protobuf?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.