From 1ae887fbe3e59e8eb1e11d10bdd0eeb0c819a6a0 Mon Sep 17 00:00:00 2001 From: Kyle Larose Date: Wed, 17 Aug 2022 11:24:58 -0400 Subject: [PATCH] use j2se variable and collapse on split The getJVMArgs() function has two problems: - It uses the J2SE pointer directly, rather than its abstraction, leading to null pointer accesses. - It splits on " " without collapsing consecutive occurances of the token, leading to invalid arguments being passed to the JVM (e.g. the main class is passed in as an empty string) when the xml has whitespace in the java-vm-args attribute. Fix these two problems by using the proper variable for accessing the JavaVMArgs, and split them in a fashion that skips consecutive whitespace. In a similar vein, also strip whitespace in the args prior to doing this work so that an entirely empty attribute does not lead to us unnecessarily adding arguments. --- launcher/jnlp/launcher.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/launcher/jnlp/launcher.go b/launcher/jnlp/launcher.go index 42ea128..b0b9116 100644 --- a/launcher/jnlp/launcher.go +++ b/launcher/jnlp/launcher.go @@ -212,12 +212,16 @@ func (launcher *Launcher) getProperties() []Property { } func (launcher *Launcher) getJVMArgs() []string { + splitter := func(c rune) bool { + return c == ' ' + } + var jvmArgs []string relevantResources := launcher.getRelevantResources() for _, resources := range relevantResources { j2se := resources.getJ2SE() - if j2se != nil && j2se.JavaVMArgs != "" { - args := strings.Split(resources.J2SE.JavaVMArgs, " ") + if j2se != nil && strings.Trim(j2se.JavaVMArgs, " ") != "" { + args := strings.FieldsFunc(j2se.JavaVMArgs, splitter) jvmArgs = append(jvmArgs, args...) } }