Skip to content

Commit fb2170f

Browse files
committed
Raise AbstractMethodError
1 parent 94358f5 commit fb2170f

File tree

4 files changed

+69
-11
lines changed

4 files changed

+69
-11
lines changed

java_class_proto/src/proto.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ where
7070
where
7171
C: ?Sized + Send,
7272
{
73-
async fn call(&self, _: &Jvm, _: &mut C, _: Box<[JavaValue]>) -> Result<JavaValue, JavaError> {
74-
// TODO java.lang.AbstractMethodError
75-
Err(JavaError::FatalError(format!("Abstract {}{} method called", self.name, self.descriptor)))
73+
async fn call(&self, jvm: &Jvm, _: &mut C, _: Box<[JavaValue]>) -> Result<JavaValue, JavaError> {
74+
Err(jvm
75+
.exception(
76+
"java/lang/AbstractMethodError",
77+
&format!("Abstract {}{} method called", self.name, self.descriptor),
78+
)
79+
.await)
7680
}
7781
}
7882

java_runtime/src/classes/java/lang.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod abstract_method_error;
12
mod arithmetic_exception;
23
mod array_index_out_of_bounds_exception;
34
mod class;
@@ -33,13 +34,14 @@ mod throwable;
3334
mod unsupported_operation_exception;
3435

3536
pub use self::{
36-
arithmetic_exception::ArithmeticException, array_index_out_of_bounds_exception::ArrayIndexOutOfBoundsException, class::Class,
37-
class_cast_exception::ClassCastException, class_loader::ClassLoader, clone_not_supported_exception::CloneNotSupportedException,
38-
cloneable::Cloneable, comparable::Comparable, error::Error, exception::Exception, illegal_argument_exception::IllegalArgumentException,
39-
incompatible_class_change_error::IncompatibleClassChangeError, index_out_of_bounds_exception::IndexOutOfBoundsException,
40-
instantiation_error::InstantiationError, integer::Integer, interrupted_exception::InterruptedException, linkage_error::LinkageError, math::Math,
41-
no_class_def_found_error::NoClassDefFoundError, no_such_field_error::NoSuchFieldError, no_such_method_error::NoSuchMethodError,
42-
null_pointer_exception::NullPointerException, object::Object, runnable::Runnable, runtime::Runtime, runtime_exception::RuntimeException,
43-
security_exception::SecurityException, string::String, string_buffer::StringBuffer, system::System, thread::Thread, throwable::Throwable,
37+
abstract_method_error::AbstractMethodError, arithmetic_exception::ArithmeticException,
38+
array_index_out_of_bounds_exception::ArrayIndexOutOfBoundsException, class::Class, class_cast_exception::ClassCastException,
39+
class_loader::ClassLoader, clone_not_supported_exception::CloneNotSupportedException, cloneable::Cloneable, comparable::Comparable, error::Error,
40+
exception::Exception, illegal_argument_exception::IllegalArgumentException, incompatible_class_change_error::IncompatibleClassChangeError,
41+
index_out_of_bounds_exception::IndexOutOfBoundsException, instantiation_error::InstantiationError, integer::Integer,
42+
interrupted_exception::InterruptedException, linkage_error::LinkageError, math::Math, no_class_def_found_error::NoClassDefFoundError,
43+
no_such_field_error::NoSuchFieldError, no_such_method_error::NoSuchMethodError, null_pointer_exception::NullPointerException, object::Object,
44+
runnable::Runnable, runtime::Runtime, runtime_exception::RuntimeException, security_exception::SecurityException, string::String,
45+
string_buffer::StringBuffer, system::System, thread::Thread, throwable::Throwable,
4446
unsupported_operation_exception::UnsupportedOperationException,
4547
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use alloc::vec;
2+
3+
use java_class_proto::JavaMethodProto;
4+
use jvm::{ClassInstanceRef, Jvm, Result};
5+
6+
use crate::{RuntimeClassProto, RuntimeContext, classes::java::lang::String};
7+
8+
// class java.lang.AbstractMethodError
9+
pub struct AbstractMethodError;
10+
11+
impl AbstractMethodError {
12+
pub fn as_proto() -> RuntimeClassProto {
13+
RuntimeClassProto {
14+
name: "java/lang/AbstractMethodError",
15+
parent_class: Some("java/lang/IncompatibleClassChangeError"),
16+
interfaces: vec![],
17+
methods: vec![
18+
JavaMethodProto::new("<init>", "()V", Self::init, Default::default()),
19+
JavaMethodProto::new("<init>", "(Ljava/lang/String;)V", Self::init_with_message, Default::default()),
20+
],
21+
fields: vec![],
22+
access_flags: Default::default(),
23+
}
24+
}
25+
26+
async fn init(jvm: &Jvm, _: &mut RuntimeContext, this: ClassInstanceRef<Self>) -> Result<()> {
27+
tracing::debug!("java.lang.AbstractMethodError::<init>({:?})", &this);
28+
29+
let _: () = jvm
30+
.invoke_special(&this, "java/lang/IncompatibleClassChangeError", "<init>", "()V", ())
31+
.await?;
32+
33+
Ok(())
34+
}
35+
36+
async fn init_with_message(jvm: &Jvm, _: &mut RuntimeContext, this: ClassInstanceRef<Self>, message: ClassInstanceRef<String>) -> Result<()> {
37+
tracing::debug!("java.lang.AbstractMethodError::<init>({:?}, {:?})", &this, &message);
38+
39+
let _: () = jvm
40+
.invoke_special(
41+
&this,
42+
"java/lang/IncompatibleClassChangeError",
43+
"<init>",
44+
"(Ljava/lang/String;)V",
45+
(message,),
46+
)
47+
.await?;
48+
49+
Ok(())
50+
}
51+
}

java_runtime/src/loader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub fn get_runtime_class_proto(name: &str) -> Option<RuntimeClassProto> {
3232
crate::classes::java::io::Serializable::as_proto(),
3333
crate::classes::java::io::StringWriter::as_proto(),
3434
crate::classes::java::io::Writer::as_proto(),
35+
crate::classes::java::lang::AbstractMethodError::as_proto(),
3536
crate::classes::java::lang::ArrayIndexOutOfBoundsException::as_proto(),
3637
crate::classes::java::lang::Class::as_proto(),
3738
crate::classes::java::lang::ClassCastException::as_proto(),

0 commit comments

Comments
 (0)