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

encoding/gob: does not allow nil elements in arrays #1501

Closed
rogpeppe opened this issue Feb 11, 2011 · 4 comments
Closed

encoding/gob: does not allow nil elements in arrays #1501

rogpeppe opened this issue Feb 11, 2011 · 4 comments
Assignees

Comments

@rogpeppe
Copy link
Contributor

@rogpeppe rogpeppe commented Feb 11, 2011

This program prints "gob: encodeArray: nil element".

Nil pointers are allowed in structs; why not in arrays?

type X struct {
    I int
}

func main() {
    enc := gob.NewEncoder(new(bytes.Buffer))
    err := enc.Encode([]*X{&X{99}, nil})
    fmt.Println(err)
}
@rsc
Copy link
Contributor

@rsc rsc commented Feb 11, 2011

Comment 1:

Owner changed to r...@golang.org.

Status changed to Accepted.

@robpike
Copy link
Contributor

@robpike robpike commented Feb 12, 2011

Comment 2:

There are no pointers in the encoding, so the best it could do without an encoding
change is a zero value for the object, which is not the same thing.  It's not clear to
me what the right answer would be.

Status changed to Thinking.

@rsc
Copy link
Contributor

@rsc rsc commented Dec 9, 2011

Comment 3:

Labels changed: added priority-later.

@robpike
Copy link
Contributor

@robpike robpike commented Dec 16, 2011

Comment 4:

Status changed to Unfortunate.

@mikioh mikioh changed the title gob: does not allow nil elements in arrays encoding/gob: does not allow nil elements in arrays Feb 26, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.