Skip to content

encoding/xml: panic: reflect: Index out of range #69949

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

Closed
otaxhu opened this issue Oct 20, 2024 · 3 comments
Closed

encoding/xml: panic: reflect: Index out of range #69949

otaxhu opened this issue Oct 20, 2024 · 3 comments

Comments

@otaxhu
Copy link

otaxhu commented Oct 20, 2024

Go version

go version go1.23.2 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/albian/.cache/go-build'
GOENV='/home/albian/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/albian/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/albian/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/albian/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/albian/dev/problem/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3479115519=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Tried to unmarshal a xml document to a struct

Somehow I cannot reproduce the panic with a minimal reproducible program, so I'm gonna copy and paste part of the original code:
https://go.dev/play/p/8fc1X8qJOXt

What did you see happen?

Got following panic message:

panic: reflect: Field index out of range

What did you expect to see?

Unmarshal the document:

<problem xmlns="urn:whatever">
</problem>

To the struct:

struct {
    RegisteredProblem

    Custom string `xml:"custom"`
}

And not to panic.

@otaxhu
Copy link
Author

otaxhu commented Oct 20, 2024

Issue #16497 seems to have the same problem that I have, It worked flipping the XMLName field to be the first instead of the last.

Working example https://go.dev/play/p/EMAgchRIE4y

@seankhliao
Copy link
Member

Duplicate of #16497

@seankhliao seankhliao marked this as a duplicate of #16497 Oct 20, 2024
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants