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

JShell: NullPointerException when throwing exception with null message under local ExecutionControl

XMLWordPrintable

    • b21
    • x86_64
    • generic

      FULL PRODUCT VERSION :
      java version "9"
      Java(TM) SE Runtime Environment (build 9+178)
      Java HotSpot(TM) 64-Bit Server VM (build 9+178, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      When using DirectExecutionControl, then exceptions thrown with null messages cause NullPointerExceptions to be thrown in Eval:translateExceptionMessage because it calls equals on the message. The default execution control doesn't because it converts null messages into the empty string.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run main method of given class.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Program should complete normally.
      ACTUAL -
      NullPointerException is thrown.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.NullPointerException
      at jdk.jshell/jdk.jshell.Eval.translateExceptionMessage(Eval.java:763)
      at jdk.jshell/jdk.jshell.Eval.declare(Eval.java:553)
      at jdk.jshell/jdk.jshell.Eval.eval(Eval.java:118)
      at jdk.jshell/jdk.jshell.JShell.eval(JShell.java:493)
      at Main.main(Main.java:23)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.HashMap;
      import java.util.Map;

      import jdk.jshell.JShell;
      import jdk.jshell.execution.DirectExecutionControl;
      import jdk.jshell.spi.ExecutionControl;
      import jdk.jshell.spi.ExecutionControlProvider;
      import jdk.jshell.spi.ExecutionEnv;

      public class Main {
      public static void main(String[] args) {
      JShell jshell = JShell.builder().executionEngine(new ExecutionControlProvider() {
      public ExecutionControl generate(ExecutionEnv env, Map<String, String> param) throws Throwable {
      return new DirectExecutionControl();
      }

      public String name() {
      return "Name";
      }

      }, new HashMap<>()).build();

      jshell.eval("throw new java.io.IOException();");
      }
      }
      ---------- END SOURCE ----------

        1. Main.java
          0.7 kB
          Fairoz Matte

            rfield Robert Field (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: