File tree Expand file tree Collapse file tree 3 files changed +17
-9
lines changed
main/java/org/cryptomator/cryptofs
test/java/org/cryptomator/cryptofs Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 1111import com .github .benmanes .caffeine .cache .Cache ;
1212import com .github .benmanes .caffeine .cache .Caffeine ;
1313import com .github .benmanes .caffeine .cache .LoadingCache ;
14+ import org .slf4j .Logger ;
15+ import org .slf4j .LoggerFactory ;
1416
1517import javax .inject .Inject ;
1618import java .io .IOException ;
1719import java .io .UncheckedIOException ;
1820import java .nio .file .Path ;
21+ import java .util .concurrent .CompletionException ;
1922
2023@ CryptoFileSystemScoped
2124class 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 /**
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments