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

SPEC: Clip.open() throws unexpected Exceptions

XMLWordPrintable

    • tiger
    • generic
    • generic

      ystem.NOT_SPECIFIED:");
                      audioFormatForOpen =
                          new AudioFormat(lineAudioFormat.getEncoding(), // AudioFormat.Encoding
                                          (float)44100.0, // float frameRate: the number of frames per second
                                          AudioSystem.NOT_SPECIFIED, // int sampleSizeInBits
                                          1, // int channels
                                          1, // int frameSize in bytes
                                          (float)44100.0, // float frameRate: the number of frames per second
                                          true // boolean bigEndian
                                          );
                      try {
                          testedClip.open(audioFormatForOpen, dataForOpen, offsetForOpen, bufferSizeForOpen);
                          out.println("> OK - line is opened");
                          testedClip.close();
                      } catch (LineUnavailableException lineUnavailableException) {
                          // line is not available due to resource restrictions
                          out.println("> OK - line is not available due to resource restrictions:");
                          lineUnavailableException.printStackTrace(out);
                      } catch (SecurityException securityException) {
                          // line is not available due to security restrictions
                          out.println("> OK - line is not available due to security restrictions");
                      } catch (Throwable thrown) {
                          out.println("## Clip.open(...) FAILED:");
                          out.println("# unexpected Exception was thrown:");
                          thrown.printStackTrace(out);
                          testResult = STATUS_FAILED;
                      }

                      out.println("\n> testSourceLine.open() for AudioFormat channels = AudioSystem.NOT_SPECIFIED:");
                      audioFormatForOpen =
                          new AudioFormat(lineAudioFormat.getEncoding(), // AudioFormat.Encoding
                                          (float)44100.0, // float frameRate: the number of frames per second
                                          8, // int sampleSizeInBits
                                          AudioSystem.NOT_SPECIFIED, // int channels
                                          1, // int frameSize in bytes
                                          (float)44100.0, // float frameRate: the number of frames per second
                                          true // boolean bigEndian
                                          );
                      try {
                          testedClip.open(audioFormatForOpen, dataForOpen, offsetForOpen, bufferSizeForOpen);
                          out.println("> OK - line is opened");
                          testedClip.close();
                      } catch (LineUnavailableException lineUnavailableException) {
                          // line is not available due to resource restrictions
                          out.println("> OK - line is not available due to resource restrictions:");
                          lineUnavailableException.printStackTrace(out);
                      } catch (SecurityException securityException) {
                          // line is not available due to security restrictions
                          out.println("> OK - line is not available due to security restrictions");
                      } catch (Throwable thrown) {
                          out.println("## Clip.open(...) FAILED:");
                          out.println("# unexpected Exception was thrown:");
                          thrown.printStackTrace(out);
                          testResult = STATUS_FAILED;
                      }

                      out.println("\n> testSourceLine.open() for AudioFormat frameSize = AudioSystem.NOT_SPECIFIED:");
                      audioFormatForOpen =
                          new AudioFormat(lineAudioFormat.getEncoding(), // AudioFormat.Encoding
                                          (float)44100.0, // float frameRate: the number of frames per second
                                          8, // int sampleSizeInBits
                                          1, // int channels
                                          AudioSystem.NOT_SPECIFIED, // int frameSize in bytes
                                          (float)44100.0, // float frameRate: the number of frames per second
                                          true // boolean bigEndian
                                          );
                      try {
                          testedClip.open(audioFormatForOpen, dataForOpen, offsetForOpen, bufferSizeForOpen);
                          out.println("> OK - line is opened");
                          testedClip.close();
                      } catch (LineUnavailableException lineUnavailableException) {
                          // line is not available due to resource restrictions
                          out.println("> OK - line is not available due to resource restrictions:");
                          lineUnavailableException.printStackTrace(out);
                      } catch (SecurityException securityException) {
                          // line is not available due to security restrictions
                          out.println("> OK - line is not available due to security restrictions");
                      } catch (Throwable thrown) {
                          out.println("## Clip.open(...) FAILED:");
                          out.println("# unexpected Exception was thrown:");
                          thrown.printStackTrace(out);
                          testResult = STATUS_FAILED;
                      }

                      out.println("\n> testSourceLine.open() for AudioFormat frameRate = AudioSystem.NOT_SPECIFIED:");
                      audioFormatForOpen =
                          new AudioFormat(lineAudioFormat.getEncoding(), // AudioFormat.Encoding
                                          (float)44100.0, // float frameRate: the number of frames per second
                                          8, // int sampleSizeInBits
                                          1, // int channels
                                          1, // int frameSize in bytes
                                          AudioSystem.NOT_SPECIFIED, // float frameRate: the number of frames per second
                                          true // boolean bigEndian
                                          );
                      try {
                          testedClip.open(audioFormatForOpen, dataForOpen, offsetForOpen, bufferSizeForOpen);
                          out.println("> OK - line is opened");
                          testedClip.close();
                      } catch (LineUnavailableException lineUnavailableException) {
                          // line is not available due to resource restrictions
                          out.println("> OK - line is not available due to resource restrictions:");
                          lineUnavailableException.printStackTrace(out);
                      } catch (SecurityException securityException) {
                          // line is not available due to security restrictions
                          out.println("> OK - line is not available due to security restrictions");
                      } catch (Throwable thrown) {
                          out.println("## Clip.open(...) FAILED:");
                          out.println("# unexpected Exception was thrown:");
                          thrown.printStackTrace(out);
                          testResult = STATUS_FAILED;
                      }

                  } // for (int j=0; j < supportedSourceLineInfo.length; j++)
                  testedMixer.close();

              } // for (int i=0; i < installedMixersInfo.length; i++)

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

      ###@###.### 2003-04-17
      This bug was re-filed from failure of TCK test api/javax_sound/sampled/Mixer/index.html#Mixer[Mixer2002].


      Name: abR10010 Date: 05/02/2002




      The specification for the Clip.open(AudioFormat format, byte[] data, int offset, int bufferSize)
      method of the javax.sound.sampled.Clip class doesn't impose any restrictions on
      the format of the audio data.

      However the test (see below) shows that the Clip.open() method for the Clip instance
      of the one of installed on the system mixers throws unexpected Exceptions
      if some audio format parameters have the AudioSystem.NOT_SPECIFIED values.

      Please note that the own audio format of this Clip instance has
      the AudioSystem.NOT_SPECIFIED value for its FrameRate parameter
      so the open() method throws unexpected IllegalArgumentException with
      this audio format.

      Please note also that if the sampleSizeInBits parameter is equal
      to the AudioSystem.NOT_SPECIFIED value the open() method throws
      permissible LineUnavailableException due to resource restrictions
      but it seems that for the present instance this Exception is not
      correct.

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


      Please, see test log:

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

      % java test

      ==> Test for Clip.open(AudioFormat format, byte[] data, int offset, int bufferSize) method:

      >>> testedMixer[0] = com.sun.media.sound.HeadspaceMixer@c2a132

      >> supportedSourceLineInfo.length = 2

      > testSourceLineInfo[0] = interface SourceDataLine supporting 8 audio formats
      > testSourceLine = com.sun.media.sound.MixerSourceLine@82c01f
      > testSourceLine is not Clip

      > testSourceLineInfo[1] = interface Clip supporting 8 audio formats, and buffers of 0 to 4194304 bytes
      > testSourceLine = com.sun.media.sound.MixerClip@578ceb
      > testSourceLine AudioFormat:
      > Encoding = PCM_SIGNED
      > SampleRate = 44100.0
      > SampleSizeInBits = 16
      > Channels = 2
      > FrameSize = 4
      > FrameRate = -1.0
      > BigEndian = false

      > testSourceLine.open() for own AudioFormat:
      ## Clip.open(...) FAILED:
      # unexpected Exception was thrown:
      java.lang.IllegalArgumentException: Requested value -1.0 smaller than allowable minimum value 0.0.
      at javax.sound.sampled.FloatControl.setValue(FloatControl.java:180)
      at com.sun.media.sound.MixerClip$MixerClipSampleRateControl.update(MixerClip.java:923)
      at com.sun.media.sound.MixerClip$MixerClipSampleRateControl.access$400(MixerClip.java:888)
      at com.sun.media.sound.MixerClip.implOpen(MixerClip.java:517)
      at com.sun.media.sound.MixerClip.open(MixerClip.java:157)
      at test.run(test.java:144)
      at test.main(test.java:13)

      > testSourceLine.open() for AudioFormat SampleRate = AudioSystem.NOT_SPECIFIED:
      > OK - line is opened

      > testSourceLine.open() for AudioFormat sampleSizeInBits = AudioSystem.NOT_SPECIFIED:
      > OK - line is not available due to resource restrictions:
      javax.sound.sampled.LineUnavailableException: Failed to allocate clip data.
      at com.sun.media.sound.MixerClip.implOpen(MixerClip.java:564)
      at com.sun.media.sound.MixerClip.open(MixerClip.java:157)
      at test.run(test.java:206)
      at test.main(test.java:13)

      > testSourceLine.open() for AudioFormat channels = AudioSystem.NOT_SPECIFIED:
      ## Clip.open(...) FAILED:
      # unexpected Exception was thrown:
      java.lang.ArrayIndexOutOfBoundsException
      at com.sun.media.sound.MixerClip.nOpen(Native Method)
      at com.sun.media.sound.MixerClip.implOpen(MixerClip.java:561)
      at com.sun.media.sound.MixerClip.open(MixerClip.java:157)
      at test.run(test.java:234)
      at test.main(test.java:13)

      > testSourceLine.open() for AudioFormat frameSize = AudioSystem.NOT_SPECIFIED:
      ## Clip.open(...) FAILED:
      # unexpected Exception was thrown:
      java.lang.ArrayIndexOutOfBoundsException
      at com.sun.media.sound.MixerClip.nOpen(Native Method)
      at com.sun.media.sound.MixerClip.implOpen(MixerClip.java:561)
      at com.sun.media.sound.MixerClip.open(MixerClip.java:157)
      at test.run(test.java:262)
      at test.main(test.java:13)

      > testSourceLine.open() for AudioFormat frameRate = AudioSystem.NOT_SPECIFIED:
      ## Clip.open(...) FAILED:
      # unexpected Exception was thrown:
      java.lang.IllegalArgumentException: Requested value -1.0 smaller than allowable minimum value 0.0.
      at javax.sound.sampled.FloatControl.setValue(FloatControl.java:180)
      at com.sun.media.sound.MixerClip$MixerClipSampleRateControl.update(MixerClip.java:923)
      at com.sun.media.sound.MixerClip$MixerClipSampleRateControl.access$400(MixerClip.java:888)
      at com.sun.media.sound.MixerClip.implOpen(MixerClip.java:517)
      at com.sun.media.sound.MixerClip.open(MixerClip.java:157)
      at test.run(test.java:290)
      at test.main(test.java:13)

      >>> testedMixer[1] = com.sun.media.sound.SimpleInputDevice@b2fd8f

      >> supportedSourceLineInfo.length = 0

      >>> testedMixer[2] = com.sun.media.sound.SimpleOutputDevice@1df073d

      >> supportedSourceLineInfo.length = 1

      > testSourceLineInfo[0] = interface SourceDataLine supporting 24 audio formats
      > testSourceLine = com.sun.media.sound.SimpleOutputDevice$OutputDeviceDataLine@b66cc
      > testSourceLine is not Clip

      ==> 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 Clip.open(AudioFormat format, byte[] data, int offset, int bufferSize) method:");

              Mixer.Info[] installedMixersInfo = AudioSystem.getMixerInfo();
              
              if ( installedMixersInfo == null ) {
                  out.println("## AudioSystem.getMixerInfo() returned unexpected result:");
                  out.println("# expected: an array of Mixer.Info objects (may be array of length 0);");
                  out.println("# produced: null;");
                  return STATUS_FAILED;
              }

              if ( installedMixersInfo.length == 0 ) {
                  // there are no mixers installed on the system - so this testcase can not be tested
                  return STATUS_PASSED;
              }

              Mixer testedMixer = null;
              for (int i=0; i < installedMixersInfo.length; i++) {
                  try {
                      testedMixer = AudioSystem.getMixer(installedMixersInfo[i]);
                  } catch (SecurityException securityException) {
                      // installed Mixer is unavailable because of security restrictions
                      continue;
                  } catch (Throwable thrown) {
                      out.println("## AudioSystem.getMixer() threw unexpected exception:");
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                      continue;
                  }

                  try {
                      testedMixer.open();
                  } catch (LineUnavailableException lineUnavailableException) {
                      // testedMixer is not available due to resource restrictions
                      continue;
                  } catch (SecurityException securityException) {
                      // testedMixer is not available due to security restrictions
                      continue;
                  } catch (Throwable thrown) {
                      out.println("## Mixer.open() threw unexpected exception:");
                      out.println("# Mixer = " + testedMixer);
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                      continue;
                  }
                  Line.Info supportedSourceLineInfo[] = null;
                  try {
                      supportedSourceLineInfo = testedMixer.getSourceLineInfo();
                  } catch (Throwable thrown) {
                      out.println("## Mixer.getSourceLineInfo() threw unexpected exception:");
                      out.println("# Mixer = " + testedMixer);
                      thrown.printStackTrace(out);
                      testResult = STATUS_FAILED;
                      testedMixer.close();
                      continue;
                  }
                  if ( supportedSourceLineInfo == null ) {
                      out.println("## Mixer.getSourceLineInfo() returned null array");
                      out.println("# Mixer = " + testedMixer);
                      testResult = STATUS_FAILED;
                      testedMixer.close();
                      continue;
                  }
                  out.println("\n>>> testedMixer["+i+"] = " + testedMixer);
                  out.println("\n>> supportedSourceLineInfo.length = " + supportedSourceLineInfo.length);

                  for (int j=0; j < supportedSourceLineInfo.length; j++) {
                      Line.Info testSourceLineInfo = supportedSourceLineInfo[j];
                      
                      Line testSourceLine = null;
                      try {
                          testSourceLine = testedMixer.getLine(testSourceLineInfo);
                      } catch (LineUnavailableException lineUnavailableException) {
                          // line is not available due to resource restrictions
                          continue;
                      } catch (SecurityException securityException) {
                          // line is not available due to security restrictions
                          continue;
                      } catch (Throwable thrown) {
                          out.println("## Mixer.getLine(Line.Info) threw unexpected Exception:");
                          out.println("# Mixer = " + testedMixer);
                          out.println("# Line.Info = " + testSourceLineInfo);
                          thrown.printStackTrace(out);
                          testResult = STATUS_FAILED;
                          continue;
                      }

                      out.println("\n> testSourceLineInfo["+j+"] = " + testSourceLineInfo);
                      out.println("> testSourceLine = " + testSourceLine);
                      if ( ! (testSourceLine instanceof Clip) ) {
                          out.println("> testSourceLine is not Clip");
                          continue;
                      }

                      Clip testedClip = (Clip)testSourceLine;
                      AudioFormat lineAudioFormat = testedClip.getFormat();
                      out.println("> testSourceLine AudioFormat:");
                      out.println("> Encoding = " + lineAudioFormat.getEncoding());
                      out.println("> SampleRate = " + lineAudioFormat.getSampleRate());
                      out.println("> SampleSizeInBits = " + lineAudioFormat.getSampleSizeInBits());
                      out.println("> Channels = " + lineAudioFormat.getChannels());
                      out.println("> FrameSize = " + lineAudioFormat.getFrameSize());
                      out.println("> FrameRate = " + lineAudioFormat.getFrameRate());
                      out.println("> BigEndian = " + lineAudioFormat.isBigEndian());

                      int bufferSizeForOpen = 1;
                      if ( lineAudioFormat.getSampleSizeInBits() != AudioSystem.NOT_SPECIFIED ) {
                          bufferSizeForOpen = lineAudioFormat.getSampleSizeInBits()/8;
                          if ( lineAudioFormat.getSampleSizeInBits()%8 != 0 ) {
                              bufferSizeForOpen++;
                          }
                      }
                      if ( lineAudioFormat.getFrameSize() != AudioSystem.NOT_SPECIFIED ) {
                          bufferSizeForOpen = lineAudioFormat.getFrameSize();
                      }
                      byte[] dataForOpen = new byte[bufferSizeForOpen];
                      for (int k=0; k < bufferSizeForOpen; k++) {
                          dataForOpen[k] = (byte)1;
                      }
                      int offsetForOpen = 0;

                      out.println("\n> testSourceLine.open() for own AudioFormat:");
                      try {
                          testedClip.open(lineAudioFormat, dataForOpen, offsetForOpen, bufferSizeForOpen);
                          out.println("> OK - line is opened");
                          testedClip.close();
                      } catch (LineUnavailableException lineUnavailableException) {
                          // line is not available due to resource restrictions
                          out.println("> OK - line is not available due to resource restrictions:");
                          lineUnavailableException.printStackTrace(out);
                      } catch (SecurityException securityException) {
                          // line is not available due to security restrictions
                          out.println("> OK - line is not available due to security restrictions");
                      } catch (Throwable thrown) {
                          out.println("## Clip.open(...) FAILED:");
                          out.println("# unexpected Exception was thrown:");
                          thrown.printStackTrace(out);
                          testResult = STATUS_FAILED;
                      }

                      bufferSizeForOpen = 1;
                      dataForOpen = new byte[bufferSizeForOpen];
                      for (int k=0; k < bufferSizeForOpen; k++) {
                          dataForOpen[k] = (byte)1;
                      }

                      out.println("\n> testSourceLine.open() for AudioFormat SampleRate = AudioSystem.NOT_SPECIFIED:");
                      AudioFormat audioFormatForOpen =
                          new AudioFormat(lineAudioFormat.getEncoding(), // AudioFormat.Encoding
                                          AudioSystem.NOT_SPECIFIED, // float SampleRate: the number of samples per second
                                          8, // int sampleSizeInBits
                                          1, // int channels
                                          1, // int frameSize in bytes
                                          (float)44100.0, // float frameRate: the number of frames per second
                                          true // boolean bigEndian
                                          );
                      try {
                          testedClip.open(audioFormatForOpen, dataForOpen, offsetForOpen, bufferSizeForOpen);
                          out.println("> OK - line is opened");
                          testedClip.close();
                      } catch (LineUnavailableException lineUnavailableException) {
                          // line is not available due to resource restrictions
                          out.println("> OK - line is not available due to resource restrictions:");
                          lineUnavailableException.printStackTrace(out);
                      } catch (SecurityException securityException) {
                          // line is not available due to security restrictions
                          out.println("> OK - line is not available due to security restrictions");
                      } catch (Throwable thrown) {
                          out.println("## Clip.open(...) FAILED:");
                          out.println("# unexpected Exception was thrown:");
                          thrown.printStackTrace(out);
                          testResult = STATUS_FAILED;
                      }

                      out.println
                          ("\n> testSourceLine.open() for AudioFormat sampleSizeInBits = AudioS

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: