Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4679187
Votes 0
Synopsis SPEC: Clip.open() throws unexpected Exceptions
Category java:classes_sound
Reported Against hopper , tiger-beta
Release Fixed 1.5(tiger)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 4850013 , 4915388 , 4934462 , 4951317 , 4964173 , 4995509
Submit Date 03-MAY-2002
Description







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] =   xxxxx@xxxxx  

>>  supportedSourceLineInfo.length = 2

>  testSourceLineInfo[0] = interface SourceDataLine supporting 8 audio formats
>  testSourceLine =   xxxxx@xxxxx  
>  testSourceLine is not Clip

>  testSourceLineInfo[1] = interface Clip supporting 8 audio formats, and buffers of 0 to 4194304 bytes
>  testSourceLine =   xxxxx@xxxxx  
>  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] =   xxxxx@xxxxx  

>>  supportedSourceLineInfo.length = 0

>>>  testedMixer[2] =   xxxxx@xxxxx  

>>  supportedSourceLineInfo.length = 1

>  testSourceLineInfo[0] = interface SourceDataLine supporting 24 audio formats
>  testSourceLine = com.sun.media.sound.SimpleOutputDevice$  xxxxx@xxxxx  
>  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
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 
-------------------------------------------------------------------------
 
======================================================================

  xxxxx@xxxxx   2003-04-17
	This bug was re-filed from failure of TCK test api/javax_sound/sampled/Mixer/index.html#Mixer[Mixer2002].
Posted Date : 2005-07-22 03:26:14.0
Work Around
N/A
Evaluation
  xxxxx@xxxxx   2002-05-15
	Currently, I am not sure if I agree this is a bug or not. Needs more discussion, commit to mantis.


  xxxxx@xxxxx   2002-11-01
	The fix is to state that the Clip.open(AudioFormat, byte[], int, int) method must be called with a fully qualified audio format, otherwise an IllegalArgumentException is thrown. The implementation should be changed so that it only throws IllegalArgumentException if one of the parameters of AudioFormat is AudioSystem.NOT_SPECIFIED.
	Commit to Tiger.


  xxxxx@xxxxx   2003-08-23
	The implementation was already changed so that any open call would throw an IllegalArgumentException if one of the fields in the audio format is not specified. Therefore I changed the bug synopsis to mean that it is a SPEC bug. The javadoc of the 6 open methods in Clip, SourceDataLine and TargetDataLine should document the IllegalArgumentException.


  xxxxx@xxxxx   2003-09-26
	Fix is integrated in the javadoc.
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang