Skip to content

Commit d2eb9aa

Browse files
committed
Raise error on file not found
1 parent 94209f0 commit d2eb9aa

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

java_runtime/src/classes/java/io/file_input_stream.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ impl FileInputStream {
3636
let path = jvm.invoke_virtual(&file, "getPath", "()Ljava/lang/String;", ()).await?;
3737
let path = JavaLangString::to_rust_string(jvm, &path).await?;
3838

39-
let rust_file = context.open(&path, false).await.unwrap();
39+
let rust_file = context.open(&path, false).await;
40+
if rust_file.is_err() {
41+
// TODO correct error handling
42+
return Err(jvm.exception("java/io/FileNotFoundException", "File not found").await);
43+
}
4044

41-
let fd = FileDescriptor::from_file(jvm, rust_file).await?;
45+
let fd = FileDescriptor::from_file(jvm, rust_file.unwrap()).await?;
4246

4347
jvm.put_field(&mut this, "fd", "Ljava/io/FileDescriptor;", fd).await?;
4448

java_runtime/src/classes/java/io/random_access_file.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ impl RandomAccessFile {
5555

5656
let write = mode.contains('w');
5757

58-
let rust_file = context.open(&name, write).await.unwrap();
59-
let fd = FileDescriptor::from_file(jvm, rust_file).await?;
58+
let rust_file = context.open(&name, write).await;
59+
if rust_file.is_err() {
60+
// TODO correct error handling
61+
return Err(jvm.exception("java/io/FileNotFoundException", "File not found").await);
62+
}
63+
let fd = FileDescriptor::from_file(jvm, rust_file.unwrap()).await?;
6064
jvm.put_field(&mut this, "fd", "Ljava/io/FileDescriptor;", fd).await?;
6165

6266
Ok(())

0 commit comments

Comments
 (0)