Issue was added for this: http://code.google.com/p/protobuf/issues/detail?id=57
and a potential patch was submitted.

Any chance for this in 2.0.3?

On Nov 13, 1:43 pm, Kenton Varda <[EMAIL PROTECTED]> wrote:
> I agree, the setters should either throw NPE or should treat setFoo(null)
> the same as clearField().
>
> On Thu, Nov 13, 2008 at 7:39 AM, bivas <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> > I'm using the Java output feature of protobuf for my app.
> > I found that protobuf doesn't handle null values as well as i would
> > expect it.
>
> > for example:
>
> > message MyMessage {
> >   required int32 id = 1;
> >   optional string code = 2;
> > }
>
> > in java:
>
> > MyMessage message = MyMessage.newBuilder().setId(3).setCode(null).build
> > ();
> > message.writeTo(System.out); // <--- this will result a
> > NullPointerException when trying to write the code field
>
> > the reason is that in the created java source the setCode() method
> > looks like this:
>
> > public Builder setCode(java.lang.String value) {
> >        result.hasCode = true; // the field flag indicate a value
> > while there isn't!
> >        result.code_ = value;
> >        return this;
> > }
>
> > method should look like:
>
> > // for optional fields
> > public Builder setCode(java.lang.String value) {
> >        result.hasCode = (value != null) ;
> >        result.code_ = value;
> >        return this;
> > }
>
> > // for required fields
> > public Builder setCode(java.lang.String value) {
> >        assert value != null;
> >        result.hasCode = true;
> >        result.code_ = value;
> >        return this;
> > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to