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

OpenJDK throws NPE compiling

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Javac version: javac 11.0.17

      Java version: openjdk version "11.0.17" 2022-10-18
      OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu220.04)
      OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu220.04, mixed mode, sharing)

      OS version: NAME="Ubuntu"
      VERSION="20.04.5 LTS (Focal Fossa)"
      ID=ubuntu
      ID_LIKE=debian
      PRETTY_NAME="Ubuntu 20.04.5 LTS"
      VERSION_ID="20.04"


      A DESCRIPTION OF THE PROBLEM :
      Our project (https://github.com/pravega/pravega) was compiling completely fine until we upgraded to JDK 11.0.17. In particular, we noticed a test class inducing a NullPointerException while the compiler was working, despite the IDE tells the user that is valid Java code. The test class that shows the error makes combines instantiating a nested class with an antonymous function that refers to a variable from the outer scope, plus a method used inside the anonymous function that makes use of generics.

      My take is that is the combination of the above what induces the bug in the compiler:
      - If the anonymous function does not refer to any external scope variable, compilation works.
      - If the anonymous function refers to an external scope variable, but does not use a static function with generics, it also compiles.

      It seems to be the combination of the above what induces the failure in the compiler. Also, this seems to be a regression in OpenJDK 11.0.17, as this code has not been changes in years and has always compiled fine.

       




      REGRESSION : Last worked in version 17.0.5

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the provided code with JDK 11.0.17. The compilation will break while processing (despite the IDE indicates that it is actually valid Java code). Compiling the same code with an earlier version of the JDK (i.e., 11.0.16 or lower) compilation works fine.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compilation should complete on the provided piece of code.
      ACTUAL -
      NullPointerException while Javac is compiling the code:
      ```
      compiler message file broken: key=compiler.misc.msg.bug arguments=11.0.17, {1}, {2}, {3}, {4}, {5}, {6}, {7}
      java.lang.NullPointerException
      ```

      ---------- BEGIN SOURCE ----------
      import java.util.HashMap;
      import java.util.Map;
      import java.util.concurrent.ExecutionException;
      import java.util.concurrent.Semaphore;
      import java.util.function.BiFunction;

      public class BugRepro {

          public static void main(String[] args) throws Exception {
              final Map<String, Semaphore> waitOn = new HashMap<>();
              new PrivateClass((operation, segment) -> {
                  handleInterrupted(() -> waitOn.get(operation).acquire());
                  return null;
              });
          }

          private static class PrivateClass {
              private final BiFunction<String, String, Object> methodInvoked;

              private PrivateClass(BiFunction<String, String, Object> methodInvoked) {
                  this.methodInvoked = methodInvoked;
              }
          }

          public static <ExceptionT extends Exception> void handleInterrupted(InterruptibleRun<ExceptionT> run)
                  throws ExceptionT {
              try {
                  run.run();
              } catch (InterruptedException | ExecutionException e) {
                  // Do nothing.
              }
          }

          @FunctionalInterface
          public interface InterruptibleRun<ExceptionT extends Exception> {
              void run() throws InterruptedException, ExecutionException, ExceptionT;
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: