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

Do not use endsWith on Path object for string comparison #46711

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,17 @@ public static Path getAppClassLocation(Class<?> testClass) {
* @return directory or JAR containing the application being tested by a test from the given location
*/
public static Path getAppClassLocationForTestLocation(Path testClassLocationPath) {
if (testClassLocationPath.endsWith(".jar")) {
if (testClassLocationPath.endsWith("-tests.jar")) {
String testClassLocation = testClassLocationPath.toString();
String testClassLocation = testClassLocationPath.toString();

if (testClassLocation.endsWith(".jar")) {
if (testClassLocation.endsWith("-tests.jar")) {
return Paths.get(new StringBuilder()
.append(testClassLocation, 0, testClassLocation.length() - "-tests.jar".length())
.append(".jar")
.toString());
}
return testClassLocationPath;
}
String testClassLocation = testClassLocationPath.toString();
Optional<Path> mainClassesDir = TEST_TO_MAIN_DIR_FRAGMENTS.entrySet().stream()
.filter(e -> testClassLocation.contains(e.getKey()))
.map(e -> {
Expand All @@ -211,7 +211,7 @@ public static Path getAppClassLocationForTestLocation(Path testClassLocationPath
}
// could be a custom test classes dir under the 'target' dir with the main
// classes still under 'target/classes'
p = Path.of(testClassLocation).getParent();
p = testClassLocationPath.getParent();
if (p != null && p.getFileName().toString().equals(TARGET)) {
p = p.resolve("classes");
if (Files.exists(p)) {
Expand Down
Loading