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

LineEvent.toString() throws unexpected NullPointerException

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.4.1
    • Fix Version/s: 5.0
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      tiger
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: abR10010 Date: 04/23/2002




      The specification for the constructor of the javax.sound.sampled.LineEvent
      class doesn't forbid its parameters of reference type to be set to null value.

      However the test (see below) shows the LineEvent.toString() method throws
      a NullPointerException for the LineEvent instance created by the
      constructor if the LineEvent.Type parameter is equal to null value.

      Also the test shows the LineEvent constructor throws
      an IllegalArgumentException if the Line parameter is equal to null value.

      This Exception is looks reasonable for such case but the spec should say explicitly
      about the IllegalArgumentException.

      Please note also that the IllegalArgumentException is thrown by the
      constructor of the java.util.EventObject class, not by the LineEvent
      constructor itself.

      Such behavior is shown by the test running with JDK 1.4.1-beta-b08.


      Please, see test log:

      % java -version
      java version "1.4.1-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b08)
      Java HotSpot(TM) Client VM (build 1.4.1-beta-b08, mixed mode)

      % java test

      ==> Test for LineEvent class:

      >> LineEvent constructor for Line = null:
      > PASSED: expected IllegalArgumentException was thrown:
      java.lang.IllegalArgumentException: null source
      at java.util.EventObject.<init>(EventObject.java:34)
      at javax.sound.sampled.LineEvent.<init>(LineEvent.java:61)
      at test.run(test.java:31)
      at test.main(test.java:13)

      >> LineEvent constructor for LineEvent.Type = null:
      > No any Exception was thrown!
      > testedLineEvent.getType():
      > PASSED: producedType = null
      > testedLineEvent.toString():
      ## FAILED: unexpected Exception was thrown:
      java.lang.NullPointerException
      at javax.sound.sampled.LineEvent.toString(LineEvent.java:116)
      at test.run(test.java:86)
      at test.main(test.java:13)

      ==> test FAILED!
       
       
      The test source:
      ------------------------------- test.java --------------------------------
      // File: %Z%%M% %I% %E%
      // Copyright %G% Sun Microsystems, Inc. All Rights Reserved

      import javax.sound.sampled.*;

      public class test {

          static final int STATUS_PASSED = 0;
          static final int STATUS_FAILED = 2;
          static final int STATUS_TEMP = 95;
          
          public static void main(String argv[]) {
              int testExitStatus = run(argv, System.out) + STATUS_TEMP;
              System.exit(testExitStatus);
          }

          public static int run(String argv[], java.io.PrintStream out) {
              int testResult = STATUS_PASSED;
          
              out.println("\n==> Test for LineEvent class:");
          
              Line testLine = new TestLine();
              Line nullLine = null;

              LineEvent.Type testLineEventType = LineEvent.Type.OPEN;
              LineEvent.Type nullLineEventType = null;

              LineEvent testedLineEvent = null;
              out.println("\n>> LineEvent constructor for Line = null: ");
              try {
                  testedLineEvent =
                      new LineEvent(nullLine, // the source Line of this event
                                      testLineEventType, // LineEvent.Type - the event type
                                      (long) 1000 // position - the number processed of sample frames
                                      );
                  out.println("> No any Exception was thrown!");
                  out.println("> testedLineEvent.getType():");
                  try {
                      Line producedLine = testedLineEvent.getLine();
                      out.println("> PASSED: producedLine = " + producedLine);
                  } catch (Throwable thrown) {
                      out.println("## FAILED: unexpected Exception was thrown:");
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                  }
                  out.println("> testedLineEvent.toString():");
                  try {
                      String producedString = testedLineEvent.toString();
                      out.println("> PASSED: producedString = " + producedString);
                  } catch (Throwable thrown) {
                      out.println("## FAILED: unexpected Exception was thrown:");
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                  }
              } catch (IllegalArgumentException illegArgExcept) {
                  out.println("> PASSED: expected IllegalArgumentException was thrown:");
                  illegArgExcept.printStackTrace(out);
              } catch (NullPointerException nullPE) {
                  out.println("> PASSED: expected NullPointerException was thrown:");
                  nullPE.printStackTrace(out);
              } catch (Throwable thrown) {
                  out.println("## FAILED: unexpected Exception was thrown:");
                  thrown.printStackTrace(out);
                  testResult = STATUS_FAILED;
              }

              out.println("\n>> LineEvent constructor for LineEvent.Type = null: ");
              try {
                  testedLineEvent =
                      new LineEvent(testLine, // the source Line of this event
                                      nullLineEventType, // LineEvent.Type - the event type
                                      (long) 1000 // position - the number processed of sample frames
                                      );
                  out.println("> No any Exception was thrown!");
                  out.println("> testedLineEvent.getType():");
                  try {
                      LineEvent.Type producedType = testedLineEvent.getType();
                      out.println("> PASSED: producedType = " + producedType);
                  } catch (Throwable thrown) {
                      out.println("## FAILED: unexpected Exception was thrown:");
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                  }
                  out.println("> testedLineEvent.toString():");
                  try {
                      String producedString = testedLineEvent.toString();
                      out.println("> PASSED: producedString = " + producedString);
                  } catch (Throwable thrown) {
                      out.println("## FAILED: unexpected Exception was thrown:");
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                  }
              } catch (IllegalArgumentException illegArgExcept) {
                  out.println("> PASSED: expected IllegalArgumentException was thrown:");
                  illegArgExcept.printStackTrace(out);
              } catch (NullPointerException nullPE) {
                  out.println("> PASSED: expected NullPointerException was thrown:");
                  nullPE.printStackTrace(out);
              } catch (Throwable thrown) {
                  out.println("## FAILED: unexpected Exception was thrown:");
                  thrown.printStackTrace(out);
                  testResult = STATUS_FAILED;
              }

              if ( testResult == STATUS_FAILED ) {
                  out.println("\n==> test FAILED!");
              } else {
                  out.println("\n==> test PASSED!");
              }
              return testResult;
          }
      } // end of test class

      class TestLine implements Line {

          public void addLineListener(LineListener listener) {
          }

          public void close() {
          }

          public Control getControl(Control.Type control) {
              return null;
          }

          public Control[] getControls() {
              return new Control[0];
          }

          public Line.Info getLineInfo() {
              return null;
          }

          public boolean isOpen() {
              return false;
          }

          public boolean isControlSupported(Control.Type control) {
              return false;
          }

          public void open() {
          }

          public void removeLineListener(LineListener listener) {
          }
      }
      -------------------------------------------------------------------------
       
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              fbomerssunw Florian Bomers (Inactive)
              Reporter:
              bondsunw Bond Bond (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: