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

JavapTask passes null to java.io.Writer

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 8-pool
    • tools
    • None
    • b58
    • generic
    • generic
    • Verified

      In JavapTask, if one uses the constructors that take a Writer object, they call getPrintWriterforWriter() on the provided value:

      private static PrintWriter getPrintWriterForWriter(Writer w) {
          if (w == null)
              return getPrintWriterForStream(null);
      ...

      private static PrintWriter getPrintWriterForStream(OutputStream s) {
          return new PrintWriter(s, true);
      }

      if the Writer is null, then null is passed to PrintWriter, OutputStreamWriter, and then Writer. Unfortunately, Writer considers this parameter a lock object which cannot be null:

      /**
       * Creates a new character-stream writer whose critical sections will
       * synchronize on the given object.
       *
       * @param lock
       * Object to synchronize on
       */
      protected Writer(Object lock) {
          if (lock == null) {
              throw new NullPointerException();
          }
      ...

      and then throws the exception.

      Something other than null should be passed in this case.

            jjg Jonathan Gibbons
            ahgross Andrew Gross
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: