Skip to content

encoding/gob doesn't mention panic behavior with nil pointers in Encode & EncodeValue #16258

Closed
@odeke-em

Description

@odeke-em

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    All versions of Go.
  2. What did you do?
    If possible, provide a recipe for reproducing the error.
    https://play.golang.org/p/SKQxgP2jjz

Nothing is mentioned in the docs about how encoding/gob.Encode and EncodeValue handles nil pointers
screen shot 2016-07-03 at 2 25 24 pm
While investigating issue #16204, I dug through the source code of encoding/gob/encoder.go https://github.com/golang/go/blob/master/src/encoding/gob/encoder.go#L215.
The first comment in the method internally mentions what to do with nil pointers
screen shot 2016-07-03 at 2 25 47 pm
However the docs do not and I don't see any tests that test out this expected behavior expect for https://github.com/golang/go/blob/master/src/encoding/gob/encoder_test.go#L833 and moreover that test only ensures that a panic provides a useful message, its focus isn't on checking that nil pointers panic.

I made https://play.golang.org/p/8PB1oN2eFO and in it I pass in some nil pointers

  1. What did you expect to see?
    The doc should be explicit about nil pointers and also we need some tests in there since panicking is the behavior in the implementation of EncodeValue which goes into Encode too.

I have a CL prepared to fix this and I'll submit it ASAP.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions