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

NullPointerException in DataInputStream#readFully(byte[] b, int off, int len)

    XMLWordPrintable

Details

    • 16
    • generic
    • generic

    Description

      ADDITIONAL SYSTEM INFORMATION :
      openjdk version "17.0.1" 2021-10-19
      MacOS Monterey 12.1

      A DESCRIPTION OF THE PROBLEM :
      Happens while upgrading a big project from java 11 to java 17.

      During the upgrade, one of the modules using a 3rd party failed on timeout. After further investigation i found the following:

      1. In java 11 the method looks like the following - https://github.com/openjdk/jdk/blob/jdk-11%2B28/src/java.base/share/classes/java/io/DataInputStream.java#L196
      2. In java 17 the method implementation changed - https://github.com/openjdk/jdk/blob/jdk-17+35/src/java.base/share/classes/java/io/DataInputStream.java#L198
      3. For some reason the 3rd party library pass null to `b` which result in a NullPointerException in line 198 when it tries to do `b.length`

      Need to add a null check before going into the logic or continue without doing anything.

      The problematic library is IBM CTG version 9.2 when trying to call a MF with containers

      REGRESSION : Last worked in version 11

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      import java.io.ByteArrayInputStream;
      import java.io.DataInputStream;
      import java.io.IOException;

      public class Main {
          public static void main(String[] args) {
              DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(new byte[] {}));
              try {
                  dataInputStream.readFully(null, 0, 0);
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }

      Code above pass with no exception in java 11 and fail with null pointer in java 17

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Code continue without getting null pointer exception and nothing is printed to the log
      ACTUAL -
      getting null pointer exception and stacktrace is printed to the log

      ---------- BEGIN SOURCE ----------
      import java.io.ByteArrayInputStream;
      import java.io.DataInputStream;
      import java.io.IOException;

      public class Main {
          public static void main(String[] args) {
              DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(new byte[] {}));
              try {
                  dataInputStream.readFully(null, 0, 0);
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No workaround :(

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              bpb Brian Burkhalter
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: