goimport: prevent panic on parsing local prefix
The existing flag parsing logic doesn't initialize a ProcessEnv struct,
which results in a nil dereference when trying to access the LocalPrefix
property. The fix is to initialize the default options with an initialized
ProcessEnv.
Fixes #39862
Change-Id: I57cff249d6bf0ced6bb70e53174b2515fe9fbb97
GitHub-Last-Rev: 2d6e5f3af226088ddc4ed88198edd5c5ea469240
GitHub-Pull-Request: golang/tools#239
Reviewed-on: https://go-review.googlesource.com/c/tools/+/240019
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
diff --git a/cmd/goimports/goimports.go b/cmd/goimports/goimports.go
index f7fc3d5..f177b2d 100644
--- a/cmd/goimports/goimports.go
+++ b/cmd/goimports/goimports.go
@@ -42,6 +42,7 @@
TabIndent: true,
Comments: true,
Fragment: true,
+ Env: &imports.ProcessEnv{},
}
exitCode = 0
)