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

(aio) AsynchronousChannelGroup.execute doesn't check null command

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The JavaDoc for Executor.execute indicates "NullPointerException – if command is null". But in the testcase it doesn't throw NPE immediately, but throws NPE later in internal thread:

      Exception in thread "pool-1-thread-1" java.lang.NullPointerException: Cannot invoke "java.lang.Runnable.run()" because "this.val$task" is null
      at java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:108)

      REGRESSION : Last worked in version 24.0.2


      ---------- BEGIN SOURCE ----------
      import java.nio.channels.AsynchronousChannelGroup;
      import java.util.concurrent.Executor;
      import java.util.concurrent.Executors;
      import java.util.concurrent.ThreadFactory;
      import java.util.concurrent.TimeUnit;

      public class ExecutorTest {

          public static void main(String[] args) throws Exception {
              // create channel groups
              ThreadFactory factory = Executors.defaultThreadFactory();
              AsynchronousChannelGroup executor = AsynchronousChannelGroup
                  .withThreadPool(Executors.newFixedThreadPool(10, factory));

              try {
                  ((Executor)executor).execute(null);
                  throw new RuntimeException("NullPointerException not thrown for null task in group: " + executor);
              } catch (NullPointerException expected) {
                  // Expected behavior
              }
              executor.shutdown();
              if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
                  System.err.println("WARNING: " + executor + " not terminated after final shutdown attempt");
              }

          }



      }

      ---------- END SOURCE ----------

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

              Created:
              Updated: