Skip to content

Commit 46b817b

Browse files
committed
8333363: ubsan: instanceKlass.cpp: runtime error: member call on null pointer of type 'struct AnnotationArray'
Reviewed-by: coleenp, stefank
1 parent 0fc5b27 commit 46b817b

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

src/hotspot/share/oops/instanceKlass.cpp

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,9 +3539,7 @@ void InstanceKlass::print_on(outputStream* st) const {
35393539
}
35403540
}
35413541
}
3542-
if (default_vtable_indices() != nullptr) {
3543-
st->print(BULLET"default vtable indices: "); default_vtable_indices()->print_value_on(st); st->cr();
3544-
}
3542+
print_on_maybe_null(st, BULLET"default vtable indices: ", default_vtable_indices());
35453543
st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr();
35463544
st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
35473545

@@ -3568,25 +3566,18 @@ void InstanceKlass::print_on(outputStream* st) const {
35683566
}
35693567
}
35703568
st->print(BULLET"constants: "); constants()->print_value_on(st); st->cr();
3571-
if (class_loader_data() != nullptr) {
3572-
st->print(BULLET"class loader data: ");
3573-
class_loader_data()->print_value_on(st);
3574-
st->cr();
3575-
}
3576-
if (source_file_name() != nullptr) {
3577-
st->print(BULLET"source file: ");
3578-
source_file_name()->print_value_on(st);
3579-
st->cr();
3580-
}
3569+
3570+
print_on_maybe_null(st, BULLET"class loader data: ", class_loader_data());
3571+
print_on_maybe_null(st, BULLET"source file: ", source_file_name());
35813572
if (source_debug_extension() != nullptr) {
35823573
st->print(BULLET"source debug extension: ");
35833574
st->print("%s", source_debug_extension());
35843575
st->cr();
35853576
}
3586-
st->print(BULLET"class annotations: "); class_annotations()->print_value_on(st); st->cr();
3587-
st->print(BULLET"class type annotations: "); class_type_annotations()->print_value_on(st); st->cr();
3588-
st->print(BULLET"field annotations: "); fields_annotations()->print_value_on(st); st->cr();
3589-
st->print(BULLET"field type annotations: "); fields_type_annotations()->print_value_on(st); st->cr();
3577+
print_on_maybe_null(st, BULLET"class annotations: ", class_annotations());
3578+
print_on_maybe_null(st, BULLET"class type annotations: ", class_type_annotations());
3579+
print_on_maybe_null(st, BULLET"field annotations: ", fields_annotations());
3580+
print_on_maybe_null(st, BULLET"field type annotations: ", fields_type_annotations());
35903581
{
35913582
bool have_pv = false;
35923583
// previous versions are linked together through the InstanceKlass
@@ -3601,16 +3592,10 @@ void InstanceKlass::print_on(outputStream* st) const {
36013592
if (have_pv) st->cr();
36023593
}
36033594

3604-
if (generic_signature() != nullptr) {
3605-
st->print(BULLET"generic signature: ");
3606-
generic_signature()->print_value_on(st);
3607-
st->cr();
3608-
}
3595+
print_on_maybe_null(st, BULLET"generic signature: ", generic_signature());
36093596
st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr();
36103597
st->print(BULLET"nest members: "); nest_members()->print_value_on(st); st->cr();
3611-
if (record_components() != nullptr) {
3612-
st->print(BULLET"record components: "); record_components()->print_value_on(st); st->cr();
3613-
}
3598+
print_on_maybe_null(st, BULLET"record components: ", record_components());
36143599
st->print(BULLET"permitted subclasses: "); permitted_subclasses()->print_value_on(st); st->cr();
36153600
if (java_mirror() != nullptr) {
36163601
st->print(BULLET"java mirror: ");

src/hotspot/share/oops/metadata.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,13 @@ class Metadata : public MetaspaceObj {
7676
static void mark_on_stack(Metadata* m) { m->set_on_stack(true); }
7777
};
7878

79+
template <typename M>
80+
static void print_on_maybe_null(outputStream* st, const char* str, const M* m) {
81+
if (nullptr != m) {
82+
st->print_raw(str);
83+
m->print_value_on(st);
84+
st->cr();
85+
}
86+
}
87+
7988
#endif // SHARE_OOPS_METADATA_HPP

0 commit comments

Comments
 (0)