Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8263632

Improve exception handling of APIs in classLoader.cpp

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 17
    • 17
    • hotspot
    • b16

    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.

      Attachments

        Issue Links

          Activity

            People

              ccheung Calvin Cheung
              iklam Ioi Lam
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: