EvoSuite / evosuite

EvoSuite - automated generation of JUnit test suites for Java classes
http://www.evosuite.org
GNU Lesser General Public License v3.0
823 stars 341 forks source link

JavaExecCmdUtil: use `Paths.get` to join file paths #454

Open kennyballou opened 1 year ago

kennyballou commented 1 year ago

Instead of relying on the values of the retrieved variables correctly handling trailing slashes, simply use the Paths utility methods to combine directory/path objects.

jose commented 1 year ago

Hi @kennyballou,

Thank you for taking the time to contribute to the EvoSuite project. If understood correctly, you're proposing

final String JAVA_CMD = java.nio.file.Paths.get(System.getProperty("java.home"), "bin", "java").toString();

as an alternative to

final String separator = System.getProperty("file.separator");
final String JAVA_CMD = System.getProperty("java.home") + separator + "bin" + separator + "java";

right?

kennyballou commented 1 year ago

That's correct. I didn't remove the separator variable because it was used in other locations. The change is limited to a single test. It's possible this pattern can/should be used in other parts of the codebase.

kennyballou commented 9 months ago

@jose: I think to further explain this change, sometimes the values returned by "java.home" or other environment variables have a trailing path separator, e.g., "/", included; as is the case for me while using Guix. Therefore, the manual separator interpolating version causes the test suite to fail while looking for the Java executable. The Paths.get version automatically handles trailing slashes and intersperses the appropriate OS separator between path elements.