Skip to content

Commit 3f15d57

Browse files
committed
Remove locale-dependent string checking
We were checking if an exception was caused by a specific reason "Not a directory". Alas, this reason is locale-dependent and can fail on systems that are not set to en_US.UTF-8. This commit addresses this by deriving what the locale-dependent error message would be and using that for comparison with the actual exception thrown. Closes #41689
1 parent 2eca4a6 commit 3f15d57

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

server/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,15 @@ public void testDesktopServicesStoreFiles() throws IOException {
171171
if (Constants.WINDOWS) {
172172
assertThat(e.getCause(), instanceOf(NoSuchFileException.class));
173173
} else {
174-
assertThat(e.getCause(), hasToString(containsString("Not a directory")));
174+
// force a "Not a directory" exception to be thrown so that we can extract the locale-dependent message
175+
final String expected;
176+
try (InputStream ignored = Files.newInputStream(desktopServicesStore.resolve("not-a-directory"))) {
177+
throw new AssertionError();
178+
} catch (final FileSystemException inner) {
179+
// locale-dependent translation of "Not a directory"
180+
expected = inner.getReason();
181+
}
182+
assertThat(e.getCause(), hasToString(containsString(expected)));
175183
}
176184
}
177185
}

0 commit comments

Comments
 (0)