Ignore:
Timestamp:
2013-04-26T00:35:45+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #8561 - fix restart on 6u45/7u21 (wrong call to Runtime.exec(String))

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/RestartAction.java

    r5857 r5904  
    1010import java.io.IOException;
    1111import java.lang.management.ManagementFactory;
     12import java.util.ArrayList;
     13import java.util.Arrays;
     14import java.util.Collections;
    1215import java.util.List;
    1316
     
    5255        try {
    5356            // java binary
    54             String java = System.getProperty("java.home") + "/bin/java";
     57            final List<String> cmd = new ArrayList<String>(Collections.singleton(System.getProperty("java.home") + "/bin/java"));
    5558            // vm arguments
    56             List<String> vmArguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
    57             StringBuffer vmArgsOneLine = new StringBuffer();
    58             for (String arg : vmArguments) {
     59            for (String arg : ManagementFactory.getRuntimeMXBean().getInputArguments()) {
    5960                // if it's the agent argument : we ignore it otherwise the
    6061                // address of the old application and the new one will be in conflict
    6162                if (!arg.contains("-agentlib")) {
    62                     vmArgsOneLine.append(arg);
    63                     vmArgsOneLine.append(" ");
     63                    cmd.add(arg);
    6464                }
    6565            }
    66             // init the command to execute, add the vm args
    67             final StringBuffer cmd = new StringBuffer("\"" + java + "\" " + vmArgsOneLine);
    6866            // program main and program arguments (be careful a sun property. might not be supported by all JVM)
    6967            String[] mainCommand = System.getProperty("sun.java.command").split(" ");
     
    7169            if (mainCommand[0].endsWith(".jar")) {
    7270                // if it's a jar, add -jar mainJar
    73                 cmd.append("-jar " + new File(mainCommand[0]).getPath());
     71                cmd.add("-jar");
     72                cmd.add(new File(mainCommand[0]).getPath());
    7473            } else {
    7574                // else it's a .class, add the classpath and mainClass
    76                 cmd.append("-cp \"" + System.getProperty("java.class.path") + "\" " + mainCommand[0]);
     75                cmd.add("-cp");
     76                cmd.add("\"" + System.getProperty("java.class.path") + "\"");
     77                cmd.add(mainCommand[0]);
    7778            }
    7879            // finally add program arguments
    79             for (String arg : Main.commandLineArgs) {
    80                 cmd.append(" ");
    81                 cmd.append(arg);
    82             }
     80            cmd.addAll(Arrays.asList(Main.commandLineArgs));
    8381            // execute the command in a shutdown hook, to be sure that all the
    8482            // resources have been disposed before restarting the application
     
    8785                public void run() {
    8886                    try {
    89                         Runtime.getRuntime().exec(cmd.toString());
     87                        Runtime.getRuntime().exec(cmd.toArray(new String[]{}));
    9088                    } catch (IOException e) {
    9189                        e.printStackTrace();
Note: See TracChangeset for help on using the changeset viewer.