Skip to content

Commit aaddff8

Browse files
committed
Add a descriptive error-message for the highly-unexpected case
where a FileSignature is generated for multiple files with the same filename.
1 parent e872905 commit aaddff8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/src/main/java/com/diffplug/spotless/FileSignature.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,21 @@ public static FileSignature signAsSet(File... files) throws IOException {
8383

8484
/** Creates file signature insensitive to the order of the files. */
8585
public static FileSignature signAsSet(Iterable<File> files) throws IOException {
86-
return new FileSignature(toSortedSet(files, comparing(File::getName)));
86+
List<File> natural = toSortedSet(files);
87+
List<File> onNameOnly = toSortedSet(files, comparing(File::getName));
88+
if (natural.size() != onNameOnly.size()) {
89+
StringBuilder builder = new StringBuilder();
90+
builder.append("For these files:\n");
91+
for (File file : files) {
92+
builder.append(" " + file.getAbsolutePath() + "\n");
93+
}
94+
builder.append("a caching signature is being generated, which will be based only on their\n");
95+
builder.append("names, not their full path (foo.txt, not C:\folder\foo.txt). Unexpectedly,\n");
96+
builder.append("you have two files with different paths, but the same names. You must\n");
97+
builder.append("rename one of them so that all files have unique names.");
98+
throw new IllegalArgumentException(builder.toString());
99+
}
100+
return new FileSignature(onNameOnly);
87101
}
88102

89103
private FileSignature(final List<File> files) throws IOException {

0 commit comments

Comments
 (0)