You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// First, the Java Virtual Machine determines whether the bootstrap class loader has
389
-
// already been recorded as an initiating loader of a class or interface denoted by N.
390
-
// If so, this class or interface is C, and no class loading or creation is necessary.
388
+
// First, the Java Virtual Machine determines whether L has already been recorded as an initiating loader
389
+
// of a class or interface denoted by N. If so, this class or interface is C, and no class loading or
390
+
// creation is necessary.
391
391
ifletSome(ret) = self.lookup_class(name){
392
392
returnThrows::Ok(ret);
393
393
}
@@ -630,53 +630,64 @@ impl ClassLoader {
630
630
// Otherwise, the following steps are performed to create C:
631
631
//
632
632
// If the component type is a reference type, the algorithm of this section (§5.3) is applied recursively using L in order to load and thereby create the component type of C.
633
-
letmut descriptor_str = descriptor.as_str();
634
-
// TODO: Could also just skip the parsing entirely and count the number of '[' and strip, since we only need the number of dimensions
635
-
let array = FieldType::parse(&mut descriptor_str.as_bytes()).unwrap();// TODO: Error handling
636
-
letFieldType::Array(mut component) = array else{
637
-
unreachable!("The descriptor was validated as an array prior");
// Just strip '[' until we finally reach the component type.
648
-
//
649
-
// Note that for multidimensional arrays, the component classes are **not** preemptively
650
-
// loaded.
651
-
//
652
-
// So, in the case of `[[Ljava/lang/String;`, only *that* class will be loaded. Not
653
-
// `[Ljava/lang/String;`, unless it is explicitly needed later on.
654
-
component = array_component;
655
-
continue;
656
-
}
657
-
658
-
break;
659
-
}
635
+
// Just strip '[' until we finally reach the component type.
636
+
//
637
+
// Note that for multidimensional arrays, the component classes are **not** preemptively
638
+
// loaded.
639
+
//
640
+
// So, in the case of `[[Ljava/lang/String;`, only *that* class will be loaded. Not
641
+
// `[Ljava/lang/String;`, unless it is explicitly loaded later on.
642
+
let dimensions = descriptor_bytes
643
+
.iter()
644
+
.copied()
645
+
.take_while(|c| *c == b'[')
646
+
.count();
647
+
assert!(
648
+
dimensions > 0,
649
+
"The descriptor was validated as an array prior"
650
+
);
660
651
661
652
// The Java Virtual Machine creates a new array class with the indicated component type and number of dimensions.
662
-
let array_class = unsafe{Class::new_array(descriptor,*component,self)? };
653
+
654
+
// (Handled below)
663
655
664
656
// If the component type is a reference type, the Java Virtual Machine marks C to have the defining loader of the component type as its defining loader.
665
657
// Otherwise, the Java Virtual Machine marks C to have the bootstrap class loader as its defining loader.
666
658
667
-
// (Already handled)
659
+
let component_type = FieldType::parse(&mut&descriptor_bytes[dimensions..]).unwrap();// TODO: Error handling
660
+
letmut array_class = None;// Might need to defer to other loaders
661
+
if component_type.is_primitive(){
662
+
// Only the bootstrap loader can load primitive array classes, defer.
0 commit comments