Skip to content
Open
Show file tree
Hide file tree
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
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,8 +24,13 @@ public class FileClasspathEntry implements ClasspathEntry {

private final File file;

public FileClasspathEntry(String file) {
this(new File(file));
public FileClasspathEntry(String filePath) {
File file = new File(filePath);
if (!file.isDirectory() && !file.getName().toLowerCase().endsWith("jar")) {
String absolutePath = file.getAbsolutePath();
throw new IllegalArgumentException("File must be a jar file or directory '" + absolutePath + "'");
}
this.file = file;
}

public FileClasspathEntry(File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;

class FileClasspathEntryTests {
Expand All @@ -32,4 +33,11 @@ void resolveWhenDoesNotExist() {
.withMessageContaining("Could not find file to add to the classpath");
}

@Test
void constructorWhenNotJarOrDirectoryThrowsIllegalArgumentException() {
String invalidPath = "some-file.txt";
assertThatIllegalArgumentException().isThrownBy(() -> new FileClasspathEntry(invalidPath))
.withMessageContaining("File must be a jar file or directory");
}

}