Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kennyballou
Copy link

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
Copy link
Member

jose commented May 30, 2023

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
Copy link
Author

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.

Comment on lines -48 to +49
final String separator = System.getProperty("file.separator");
final String JAVA_CMD =
System.getProperty("java.home") + separator + "bin" + separator + "java";
final String JAVA_CMD = Paths.get(System.getProperty("java.home"), "bin", "java").toString();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jose: I have amended the commit to remove the unused separator variable.

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.

Signed-off-by: Kenny Ballou <[email protected]>
@kennyballou
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants