Skip to content

panic: reflect: call of reflect.flag.mustBeExported on zero Value #75

Description

@lnxbil

Hi everyone,

I'm in the progress of migrating a project from perl to go and have problems with a previously working JSON schema file with conflate. I first tried gojsonschema and the schema was valid there, but had no default value integration, so I turned to conflate.

I ran into a panic (with my code and the conflate binary)

$ ~/go/bin/conflate -data testdata/data.yaml -schema schema/data.schema.json -validate -defaults
panic: reflect: call of reflect.flag.mustBeExported on zero Value

goroutine 1 [running]:
reflect.flag.mustBeExportedSlow(0x0)
        /usr/local/Cellar/go/1.13.4/libexec/src/reflect/value.go:222 +0xad
reflect.flag.mustBeExported(...)
        /usr/local/Cellar/go/1.13.4/libexec/src/reflect/value.go:216
reflect.Value.Set(0x147fbe0, 0xc000267c50, 0x194, 0x0, 0x0, 0x0)
        /usr/local/Cellar/go/1.13.4/libexec/src/reflect/value.go:1532 +0x56
github.com/miracl/conflate.applyDefaultsRecursive(0xc00026a850, 0xb, 0x14816e0, 0xc0001dab10, 0x1453340, 0xc000267c50, 0x14816e0, 0xc0001dade0, 0x0, 0x0)
        /Users/andreas/go/pkg/mod/github.com/miracl/conflate@v1.1.0/schema.go:208 +0xa1f
github.com/miracl/conflate.applyObjectDefaults(0xc00026a780, 0x6, 0x14816e0, 0xc0001dab10, 0x14816e0, 0xc0001da0f0, 0xc0001dad80, 0x0, 0x0)
        /Users/andreas/go/pkg/mod/github.com/miracl/conflate@v1.1.0/schema.go:247 +0x294
github.com/miracl/conflate.applyDefaultsRecursive(0xc00026a780, 0x6, 0x14816e0, 0xc0001dab10, 0x1453340, 0xc0002678e0, 0x14816e0, 0xc0001dad80, 0x0, 0x0)
        /Users/andreas/go/pkg/mod/github.com/miracl/conflate@v1.1.0/schema.go:215 +0x959
github.com/miracl/conflate.applyObjectDefaults(0x150ad41, 0x1, 0x14816e0, 0xc0001dab10, 0x14816e0, 0xc0001da060, 0xc0001dab10, 0x10bd, 0x12bd)
        /Users/andreas/go/pkg/mod/github.com/miracl/conflate@v1.1.0/schema.go:247 +0x294
github.com/miracl/conflate.applyDefaultsRecursive(0x150ad41, 0x1, 0x14816e0, 0xc0001dab10, 0x1453340, 0xc0000ba980, 0x14816e0, 0xc0001dab10, 0xc000188417, 0x0)
        /Users/andreas/go/pkg/mod/github.com/miracl/conflate@v1.1.0/schema.go:215 +0x959
github.com/miracl/conflate.applyDefaults(0x1453340, 0xc0000ba980, 0x14816e0, 0xc0001dab10, 0x0, 0x0)
        /Users/andreas/go/pkg/mod/github.com/miracl/conflate@v1.1.0/schema.go:160 +0x6c
github.com/miracl/conflate.(*Schema).ApplyDefaults(0xc000267820, 0x1453340, 0xc0000ba980, 0x0, 0x0)
        /Users/andreas/go/pkg/mod/github.com/miracl/conflate@v1.1.0/schema.go:77 +0x54
github.com/miracl/conflate.(*Conflate).ApplyDefaults(...)
        /Users/andreas/go/pkg/mod/github.com/miracl/conflate@v1.1.0/conflate.go:112
main.main()
        /Users/andreas/go/pkg/mod/github.com/miracl/conflate@v1.1.0/conflate/main.go:72 +0x7f2

with this schema properties:

...
"host" : {
          "type": [ "string", "null" ],
          "description": "Hostname",
          "pattern": "^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])$",
          "default": null
        },
...

If I change it to use only string (and allow the empty string in the validation), it works:

"host" : {
          "type": "string",
          "description": "Hostname",
          "pattern": "^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9]|)$",
          "default": ""
        },

It's not a big limitation, but I need to change my previously working schema file in order to get it to work with conflate.

Is this a bug worth noting?

Best,
Andreas

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions