Skip to content

Commit 72764a0

Browse files
committed
fix incomplete changes in a9bfb4d .
1 parent 08c907c commit 72764a0

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/main/java/org/cryptomator/cryptofs/DirectoryIdProvider.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111
import com.github.benmanes.caffeine.cache.Cache;
1212
import com.github.benmanes.caffeine.cache.Caffeine;
1313
import com.github.benmanes.caffeine.cache.LoadingCache;
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
1416

1517
import javax.inject.Inject;
1618
import java.io.IOException;
1719
import java.io.UncheckedIOException;
1820
import java.nio.file.Path;
21+
import java.util.concurrent.CompletionException;
1922

2023
@CryptoFileSystemScoped
2124
class DirectoryIdProvider {
2225

26+
private static final Logger LOG = LoggerFactory.getLogger(DirectoryIdProvider.class);
2327
private static final int MAX_CACHE_SIZE = 5000;
2428

2529
private final LoadingCache<Path, String> ids;
@@ -30,7 +34,12 @@ public DirectoryIdProvider(DirectoryIdLoader directoryIdLoader) {
3034
}
3135

3236
public String load(Path dirFilePath) throws IOException {
33-
return ids.get(dirFilePath);
37+
try {
38+
return ids.get(dirFilePath);
39+
} catch (CompletionException e) {
40+
LOG.warn("Failed to load directory id from {}", dirFilePath, e.getCause());
41+
throw (IOException) e.getCause();
42+
}
3443
}
3544

3645
/**

src/test/java/org/cryptomator/cryptofs/DirectoryIdLoaderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ public void testIOExceptionWhenExistingFileIsEmpty() throws IOException {
8484
when(provider.newFileChannel(eq(dirFilePath), any())).thenReturn(channel);
8585
when(channel.size()).thenReturn(0l);
8686

87-
UncheckedIOException e = Assertions.assertThrows(UncheckedIOException.class, () -> {
87+
var ioException = Assertions.assertThrows(IOException.class, () -> {
8888
inTest.load(dirFilePath);
8989
});
90-
MatcherAssert.assertThat(e.getCause().getMessage(), containsString("Invalid, empty directory file"));
90+
MatcherAssert.assertThat(ioException.getMessage(), containsString("Invalid, empty directory file"));
9191
}
9292

9393
@Test
@@ -96,10 +96,10 @@ public void testIOExceptionWhenExistingFileIsTooLarge() throws IOException {
9696
when(provider.newFileChannel(eq(dirFilePath), any())).thenReturn(channel);
9797
when(channel.size()).thenReturn((long) Integer.MAX_VALUE);
9898

99-
UncheckedIOException e = Assertions.assertThrows(UncheckedIOException.class, () -> {
99+
var ioException = Assertions.assertThrows(IOException.class, () -> {
100100
inTest.load(dirFilePath);
101101
});
102-
MatcherAssert.assertThat(e.getCause().getMessage(), containsString("Unexpectedly large directory file"));
102+
MatcherAssert.assertThat(ioException.getMessage(), containsString("Unexpectedly large directory file"));
103103
}
104104

105105
}

src/test/java/org/cryptomator/cryptofs/DirectoryIdProviderTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ public void testLoadInvokesLoader() throws IOException {
3939
}
4040

4141
@Test
42-
public void testIOExceptionFromLoaderIsWrappedAndRethrown() {
42+
public void testIOExceptionFromLoaderIsRethrown() throws IOException {
4343
IOException originalIoException = new IOException();
44-
when(loader.load(aPath)).thenThrow(new UncheckedIOException(originalIoException));
44+
when(loader.load(aPath)).thenThrow(originalIoException);
4545

4646
IOException e = Assertions.assertThrows(IOException.class, () -> {
4747
inTest.load(aPath);
4848
});
49-
Assertions.assertTrue(e.getCause() instanceof UncheckedIOException);
50-
Assertions.assertEquals(originalIoException, e.getCause().getCause());
49+
Assertions.assertSame(originalIoException, e);
5150
}
5251

5352
@Test

0 commit comments

Comments
 (0)