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

Using ArrayOf in MediaType→Attributes→Attribute causes generator crash #990

danderson opened this issue Dec 26, 2016 · 1 comment


Copy link

@danderson danderson commented Dec 26, 2016

I have a DSL that causes a nil pointer dereference crash when running goagen. This is not an ideal way of telling me I made a mistake :P. Minimal repro design:

package design

import (
	. ""
	. ""

var _ = API("crash", func() {})

var _ = MediaType("thing", func() {
	Attributes(func() {
		Attribute("rec", ArrayOf("thing"))

	View("default", func() {

The error in this design is that I should have used CollectionOf, not ArrayOf.

Running goagen bootstrap on this design results in a nil pointer dereference crash:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4a37e2]

goroutine 1 [running]:
panic(0x795780, 0xc4200100e0)
	/usr/lib/go/src/runtime/panic.go:500 +0x1a1*UserTypeDefinition).IsPrimitive(0x0, 0xc420163670)
	/home/dave/hack/go/src/ +0x22*AttributeDefinition).Validate(0xc42018be80, 0xc420163680, 0xf, 0x9ebd60, 0xc42018bf00, 0xc420163670)
	/home/dave/hack/go/src/ +0x139*AttributeDefinition).Validate(0xc42018bf00, 0xc420163670, 0xc, 0x9ebfe0, 0xc420168e80, 0xc420163660)
	/home/dave/hack/go/src/ +0x982*AttributeDefinition).Validate(0xc42018bd80, 0x0, 0x0, 0x9ebfe0, 0xc420168e80, 0xc41fff4d49)
	/home/dave/hack/go/src/ +0x451*UserTypeDefinition).Validate(0xc420168e80, 0x0, 0x0, 0x9ebea0, 0xc42016f3c0, 0x40f69e)
	/home/dave/hack/go/src/ +0xa8*MediaTypeDefinition).Validate(0xc42016f3c0, 0x9f13a0)
	/home/dave/hack/go/src/ +0xa6*APIDefinition).Validate.func2(0xc42016f3c0, 0xc4201c6510, 0xc4201634c0)
	/home/dave/hack/go/src/ +0x49*APIDefinition).IterateMediaTypes(0xc4201922c0, 0xc42020f9d8, 0x0, 0x0)
	/home/dave/hack/go/src/ +0x1d8*APIDefinition).Validate(0xc4201922c0, 0x9ebce0, 0xc4201922c0)
	/home/dave/hack/go/src/ +0x333, 0x1, 0x1, 0xa2b908, 0x0)
	/home/dave/hack/go/src/ +0x120*APIDefinition).IterateSets(0xc4201922c0, 0x84ca30)
	/home/dave/hack/go/src/ +0x96, 0xc420168ea0)
	/home/dave/hack/go/src/ +0x197
	/home/dave/hack/go/src/ +0x63
Copy link

@raphael raphael commented Dec 28, 2016

Thanks for the report. It's actually legal to use ArrayOf on a media type - unusual but legal. The difference between CollectionOf and ArrayOf is in what they produce (media type vs. user type) - not in what they accept as parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants