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

text/template: invalid nil pointer dereference instead of redefinition error #2720

tux21b opened this issue Jan 17, 2012 · 2 comments


Copy link

@tux21b tux21b commented Jan 17, 2012

What steps will reproduce the problem?

1. Create two templates in a set
2. both should contain "{{define "foo"}}...{{end}}"
(see example program below)

What is the expected output?

template: redefinition of template "foo"

What do you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x10 pc=0x424360]

goroutine 1 [running]:
text/template.(*Template).associate(0xf840020100, 0xf840020140, 0x7f3f00000004,
0xf840020140, 0x0, ...)
        /home/christoph/Development/go/src/pkg/text/template/template.go:201 +0x103
text/template.(*Template).Parse(0xf840020100, 0x4d8c6c, 0x6c706d7400000026,
0xf840020100, 0x0, ...)
        /home/christoph/Development/go/src/pkg/text/template/template.go:181 +0x23d
        /home/christoph/gopath/src/test/test.go:18 +0x1dc

Which compiler are you using (5g, 6g, 8g, gccgo)?

Which operating system are you using?
Linux tuxmobil 3.1.8-2.fc16.x86_64 #1 SMP Sat Jan 7 13:35:24 UTC 2012 x86_64 x86_64
x86_64 GNU/Linux

Which revision are you using?  (hg identify)
0640cfa9d9cf tip

Please provide any additional information below.

package main

import (

var tmplText1 string = `template 1 {{define "test"}}foo{{end}}`
var tmplText2 string = `template 2 {{define "test"}}bar{{end}}`

func main() {
    var tmpl *template.Template
    var err error
    if tmpl, err = template.New("tmpl1").Parse(tmplText1); err != nil {
        log.Fatalf("Parse 1: %v", err)
    if _, err = tmpl.New("tmpl2").Parse(tmplText2); err != nil {
        log.Fatalf("Parse 2: %v", err)
    if err = tmpl.ExecuteTemplate(os.Stdout, "tmpl1", nil); err != nil {
        log.Fatalf("ExecuteTemplate: %v", err)
Copy link

@rsc rsc commented Jan 17, 2012

Comment 1:

Labels changed: added priority-go1, removed priority-triage.

Owner changed to @robpike.

Status changed to Accepted.

Copy link

@robpike robpike commented Jan 17, 2012

Comment 2:

This issue was closed by revision 4985ee3.

Status changed to Fixed.

@tux21b tux21b added fixed labels Jan 17, 2012
@rsc rsc added this to the Go1 milestone Apr 10, 2015
@rsc rsc removed the priority-go1 label Apr 10, 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.
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.