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

ModuleReader instances don't always throw NPE for passed null args

    XMLWordPrintable

Details

    Description

      Specification for "java.lang.module" states that
      "Unless otherwise noted, passing a null argument to a constructor or method of any class or interface in this package will cause a NullPointerException to be thrown."

      This is not always so for ModuleReader instances. Consider the following code sample:

      =====================
      import java.io.IOException;
      import java.lang.module.ModuleFinder;
      import java.lang.module.ModuleReader;

      public class InstalledNONPE {

          public static void main(String[] args) {
              ModuleFinder.ofSystem().findAll().stream().forEach(mref -> {
                  try {
                      mref.open().open((String) null);
                      mref.open().read((String) null);
                      System.out.println("No NPEs");
                  } catch (IOException e) {
                      throw new RuntimeException(e);
                  }
              });
          }
      }
      =====================

      No NPEs will be seen in the output.

      The following JCK tests fail due to this problem

      api/java_lang/module/ModuleReader/index.html#InstalledModules[open_NPE]
      api/java_lang/module/ModuleReader/index.html#InstalledModules[read_NPE]
      api/java_lang/module/ModuleReader/Generic/test.html[release_NPE]

      Attachments

        Activity

          People

            alanb Alan Bateman
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: