MCPcopy Create free account
hub / github.com/andreabergia/rjvm / extract_str_from_java_lang_string

Function extract_str_from_java_lang_string

vm/src/java_objects_creation.rs:49–62  ·  view source on GitHub ↗

Given an instance of `java.lang.String`, extracts the content as a Rust `String`

(
    vm: &Vm<'a>,
    object: &impl Object<'a>,
)

Source from the content-addressed store, hash-verified

47
48/// Given an instance of `java.lang.String`, extracts the content as a Rust `String`
49pub fn extract_str_from_java_lang_string<'a>(
50 vm: &Vm<'a>,
51 object: &impl Object<'a>,
52) -> Result<String, VmError> {
53 let class = vm.get_class_by_id(object.class_id())?;
54 if class.name == "java/lang/String" {
55 // In our JRE's rt.jar, the first fields of String is
56 // private final char[] value;
57 if let Value::Object(array) = object.get_field(class, 0) {
58 return string_from_char_array(array);
59 }
60 }
61 Err(VmError::ValidationException)
62}
63
64pub fn new_java_lang_class_object<'a>(
65 vm: &mut Vm<'a>,

Callers 3

temp_printFunction · 0.85
get_primitive_classFunction · 0.85
extract_printed_stringFunction · 0.85

Calls 4

string_from_char_arrayFunction · 0.85
get_class_by_idMethod · 0.80
class_idMethod · 0.80
get_fieldMethod · 0.45

Tested by 1

extract_printed_stringFunction · 0.68