Skip to content

Commit f9549ce

Browse files
authored
Use NoSuchFileException for missing files (#58)
1 parent 0721081 commit f9549ce

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/main/java/cpw/mods/cl/ModuleClassLoader.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import cpw.mods.util.LambdaExceptionUtils;
44

5-
import java.io.FileNotFoundException;
65
import java.io.IOException;
76
import java.io.InputStream;
87
import java.io.UncheckedIOException;
@@ -13,6 +12,7 @@
1312
import java.net.MalformedURLException;
1413
import java.net.URI;
1514
import java.net.URL;
15+
import java.nio.file.NoSuchFileException;
1616
import java.util.*;
1717
import java.util.function.BiFunction;
1818
import java.util.function.Consumer;
@@ -279,8 +279,11 @@ protected Class<?> findClass(final String moduleName, final String name) {
279279
}
280280

281281
protected <T> T loadFromModule(final String moduleName, BiFunction<ModuleReader, ModuleReference, T> lookup) throws IOException {
282-
var module = configuration.findModule(moduleName).orElseThrow(FileNotFoundException::new);
283-
var ref = module.reference();
282+
var module = configuration.findModule(moduleName);
283+
if (module.isEmpty()) {
284+
throw new NoSuchFileException("module " + moduleName);
285+
}
286+
var ref = module.get().reference();
284287
try (var reader = ref.open()) {
285288
return lookup.apply(reader, ref);
286289
}

src/main/java/cpw/mods/niofs/union/UnionFileSystem.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,12 @@ private Path toRealPath(final Path basePath, final UnionPath path) {
365365

366366
public SeekableByteChannel newReadByteChannel(final UnionPath path) throws IOException {
367367
try {
368-
return findFirstFiltered(path)
369-
.map(this::byteChannel)
370-
.orElseThrow(FileNotFoundException::new);
368+
var ret = findFirstFiltered(path).map(this::byteChannel);
369+
if (ret.isPresent()) {
370+
return ret.get();
371+
} else {
372+
throw new NoSuchFileException(path.toString());
373+
}
371374
} catch (UncheckedIOException ioe) {
372375
throw ioe.getCause();
373376
}

src/test/java/cpw/mods/niofs/union/TestUnionFS.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.junit.jupiter.api.Test;
44

5-
import java.io.FileNotFoundException;
65
import java.io.IOException;
76
import java.nio.file.FileSystems;
87
import java.nio.file.Files;
@@ -267,7 +266,7 @@ public void testDirectoryVisitorJar() throws Exception {
267266
.peek(path -> foundFiles.add(path.toString()))
268267
.map(p-> ()-> {
269268
if (!Files.exists(p)) {
270-
throw new FileNotFoundException(p.toString());
269+
throw new NoSuchFileException(p.toString());
271270
}
272271
})
273272
);

0 commit comments

Comments
 (0)