Description
Some APIs in classLoader.cpp have a TRAPS declaration, which means they can throw an exception under error conditions:
E.g.,
ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const struct stat* st,
bool throw_exception,
bool is_boot_append,
bool from_class_path_attr,
TRAPS) {
But this function can also return NULL to indicate an error (if throw_exception==false). This makes the callers look rather awkward:
ClassPathEntry* new_entry = NULL;
new_entry = create_class_path_entry(path, &st, /*throw_exception=*/true, is_boot_append, from_class_path_attr, CHECK_false);
if (new_entry == NULL) {
return false;
}
To improve readability, we should add new functions like:
- create_class_path_entry_or_fail(...TRAPS) - throw exception on error (never return NULL on success)
- create_class_path_entry_or_null - return NULL on error (never throw exceptions)
Also, there are APIs like ClassPathEntry::open_stream() that are declared with TRAPS but the implementations never throw exceptions.
E.g.,
ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const struct stat* st,
bool throw_exception,
bool is_boot_append,
bool from_class_path_attr,
TRAPS) {
But this function can also return NULL to indicate an error (if throw_exception==false). This makes the callers look rather awkward:
ClassPathEntry* new_entry = NULL;
new_entry = create_class_path_entry(path, &st, /*throw_exception=*/true, is_boot_append, from_class_path_attr, CHECK_false);
if (new_entry == NULL) {
return false;
}
To improve readability, we should add new functions like:
- create_class_path_entry_or_fail(...TRAPS) - throw exception on error (never return NULL on success)
- create_class_path_entry_or_null - return NULL on error (never throw exceptions)
Also, there are APIs like ClassPathEntry::open_stream() that are declared with TRAPS but the implementations never throw exceptions.
Attachments
Issue Links
- relates to
-
JDK-8261480 MetaspaceShared::preload_and_dump should check exceptions
-
- Resolved
-