Summary
When java_home is empty in the config (e.g. jvms init was never run), jvms switch <ver> produces a misleading error and destructively overwrites the machine JAVA_HOME to an empty string before failing.
Steps to reproduce
- Fresh setup, place
jvms.exe, run jvms install 25 (do not run jvms init).
- In an elevated shell:
jvms switch 25.
Actual result
Switch jdk failed, symlink C:\Program Files\jvms\store\25 : The system cannot find the path specified.
The version is correctly installed (jvms list shows it; store\25 contains a valid JDK). The empty gap between store\25 and : is the missing link target. Before this error, setx JAVA_HOME "" /M has already run, wiping any previously-set machine JAVA_HOME.
Root cause (internal/cmdCli/switch.go)
config.JavaHome is "". switchFunc then:
- runs
setx JAVA_HOME "" /M (treated as success), then
- calls
os.Symlink(filepath.Join(config.Store, v), config.JavaHome) with an empty newname, which Windows rejects.
There is no guard that config.JavaHome is non-empty. Confirmed via %APPDATA%\jvms\jvms.json: "java_home": "".
Suggested fix
- Early in
switchFunc (and init), if config.JavaHome == "", return a clear error: "JAVA_HOME location not configured — run jvms init [--java_home <path>] first."
- Do not run
setx JAVA_HOME ... /M until the target is validated, so a failed switch can't clear an existing JAVA_HOME.
Environment
- jvms
v2.1.14, default new branch index
- Windows 11 Pro (10.0.26200), x64
Summary
When
java_homeis empty in the config (e.g.jvms initwas never run),jvms switch <ver>produces a misleading error and destructively overwrites the machineJAVA_HOMEto an empty string before failing.Steps to reproduce
jvms.exe, runjvms install 25(do not runjvms init).jvms switch 25.Actual result
The version is correctly installed (
jvms listshows it;store\25contains a valid JDK). The empty gap betweenstore\25and:is the missing link target. Before this error,setx JAVA_HOME "" /Mhas already run, wiping any previously-set machineJAVA_HOME.Root cause (
internal/cmdCli/switch.go)config.JavaHomeis"".switchFuncthen:setx JAVA_HOME "" /M(treated as success), thenos.Symlink(filepath.Join(config.Store, v), config.JavaHome)with an emptynewname, which Windows rejects.There is no guard that
config.JavaHomeis non-empty. Confirmed via%APPDATA%\jvms\jvms.json:"java_home": "".Suggested fix
switchFunc(andinit), ifconfig.JavaHome == "", return a clear error: "JAVA_HOME location not configured — runjvms init [--java_home <path>]first."setx JAVA_HOME ... /Muntil the target is validated, so a failed switch can't clear an existingJAVA_HOME.Environment
v2.1.14, defaultnewbranch index