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

AudioFileFormat.toString() throws unexpected NullPointerException

    Details

    • Subcomponent:
    • Resolved In Build:
      mantis
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: abR10010 Date: 04/23/2002




      The specification for the both constructors of the javax.sound.sampled.AudioFileFormat
      class doesn't forbid their parameters of reference type to be set to null value.

      However the test (see below) shows the AudioFileFormat.toString() method throws
      a NullPointerException for the AudioFileFormat instances created by the both
      constructors if the AudioFileFormat.Type parameter is equal to null value.

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

      Please note that the null value for the AudioFormat parameter of constructors
      doesn't cause such problems for the created AudioFileFormat instances.

      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 AudioFileFormat class:

      >> public AudioFileFormat constructor for AudioFileFormat.Type = null:
      > No any Exception was thrown!
      > testedAudioFileFormat.getType():
      > PASSED: producedType = null
      > testedAudioFileFormat.toString():
      ## FAILED: unexpected Exception was thrown:
      java.lang.NullPointerException
      at javax.sound.sampled.AudioFileFormat.toString(AudioFileFormat.java:138)
      at test.run(test.java:56)
      at test.main(test.java:13)

      >> public AudioFileFormat constructor for AudioFormat = null:
      > No any Exception was thrown!
      > testedAudioFileFormat.getFormat():
      > PASSED: producedFormat = null
      > testedAudioFileFormat.toString():
      > PASSED: producedString = WAVE (.wav) file, data format: null, frame length: 1024

      >> protected AudioFileFormat constructor for AudioFileFormat.Type = null:
      > No any Exception was thrown!
      > testedAudioFileFormat.getType():
      > PASSED: producedType = null
      > testedAudioFileFormat.toString():
      ## FAILED: unexpected Exception was thrown:
      java.lang.NullPointerException
      at javax.sound.sampled.AudioFileFormat.toString(AudioFileFormat.java:138)
      at test.run(test.java:133)
      at test.main(test.java:13)

      >> protected AudioFileFormat constructor for AudioFormat = null:
      > No any Exception was thrown!
      > testedAudioFileFormat.getFormat():
      > PASSED: producedFormat = null
      > testedAudioFileFormat.toString():
      > PASSED: producedString = WAVE (.wav) file, byte length: 1024, data format: null, frame length: 1024

      ==> 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 AudioFileFormat class:");
          
              AudioFormat testAudioFormat =
                  new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, // AudioFormat.Encoding
                                  (float) 44100.0, // float SampleRate
                                  (int) 8, // int sampleSizeInBits
                                  (int) 2, // int channels
                                  (int) 2, // int frameSize
                                  (float) 110.0, // float frameRate
                                  true // boolean bigEndian
                                  );
              AudioFormat nullAudioFormat = null;

              AudioFileFormat.Type testAudioFileFormatType = AudioFileFormat.Type.WAVE;
              AudioFileFormat.Type nullAudioFileFormatType = null;

              AudioFileFormat testedAudioFileFormat = null;
              out.println("\n>> public AudioFileFormat constructor for AudioFileFormat.Type = null: ");
              try {
                  testedAudioFileFormat =
                      new AudioFileFormat(nullAudioFileFormatType, // AudioFileFormat.Type
                                          testAudioFormat, // AudioFormat
                                          (int) 1024 // int frameLength
                                          );
                  out.println("> No any Exception was thrown!");
                  out.println("> testedAudioFileFormat.getType():");
                  try {
                      AudioFileFormat.Type producedType = testedAudioFileFormat.getType();
                      out.println("> PASSED: producedType = " + producedType);
                  } catch (Throwable thrown) {
                      out.println("## FAILED: unexpected Exception was thrown:");
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                  }
                  out.println("> testedAudioFileFormat.toString():");
                  try {
                      String producedString = testedAudioFileFormat.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>> public AudioFileFormat constructor for AudioFormat = null: ");
              try {
                  testedAudioFileFormat =
                      new AudioFileFormat(testAudioFileFormatType, // AudioFileFormat.Type
                                          nullAudioFormat, // AudioFormat
                                          (int) 1024 // int frameLength
                                          );
                  out.println("> No any Exception was thrown!");
                  out.println("> testedAudioFileFormat.getFormat():");
                  try {
                      AudioFormat producedFormat = testedAudioFileFormat.getFormat();
                      out.println("> PASSED: producedFormat = " + producedFormat);
                  } catch (Throwable thrown) {
                      out.println("## FAILED: unexpected Exception was thrown:");
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                  }
                  out.println("> testedAudioFileFormat.toString():");
                  try {
                      String producedString = testedAudioFileFormat.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>> protected AudioFileFormat constructor for AudioFileFormat.Type = null: ");
              try {
                  testedAudioFileFormat =
                      new TestAudioFileFormat(nullAudioFileFormatType, // AudioFileFormat.Type
                                              (int) 1024, // byteLength
                                              testAudioFormat, // AudioFormat
                                              (int) 1024 // int frameLength
                                              );
                  out.println("> No any Exception was thrown!");
                  out.println("> testedAudioFileFormat.getType():");
                  try {
                      AudioFileFormat.Type producedType = testedAudioFileFormat.getType();
                      out.println("> PASSED: producedType = " + producedType);
                  } catch (Throwable thrown) {
                      out.println("## FAILED: unexpected Exception was thrown:");
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                  }
                  out.println("> testedAudioFileFormat.toString():");
                  try {
                      String producedString = testedAudioFileFormat.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>> protected AudioFileFormat constructor for AudioFormat = null: ");
              try {
                  testedAudioFileFormat =
                      new TestAudioFileFormat(testAudioFileFormatType, // AudioFileFormat.Type
                                              (int) 1024, // byteLength
                                              nullAudioFormat, // AudioFormat
                                              (int) 1024 // int frameLength
                                              );
                  out.println("> No any Exception was thrown!");
                  out.println("> testedAudioFileFormat.getFormat():");
                  try {
                      AudioFormat producedFormat = testedAudioFileFormat.getFormat();
                      out.println("> PASSED: producedFormat = " + producedFormat);
                  } catch (Throwable thrown) {
                      out.println("## FAILED: unexpected Exception was thrown:");
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                  }
                  out.println("> testedAudioFileFormat.toString():");
                  try {
                      String producedString = testedAudioFileFormat.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 TestAudioFileFormat extends AudioFileFormat {

          TestAudioFileFormat(AudioFileFormat.Type type,
                              int byteLength,
                              AudioFormat format,
                              int frameLength)
          {
              super(type, byteLength, format, frameLength);
          }
      }
      -------------------------------------------------------------------------
       
      ======================================================================

        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: