United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4795582 SPEC: AudioInputStream.available description is incomplete
JDK-4795582 : SPEC: AudioInputStream.available description is incomplete

Details
Type:
Bug
Submit Date:
2002-12-18
Status:
Resolved
Updated Date:
2003-10-24
Project Name:
JDK
Resolved Date:
2003-10-24
Component:
client-libs
OS:
generic
Sub-Component:
javax.sound
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.2
Fixed Versions:
5.0 (b26)

Related Reports

Sub Tasks

Description

Name: dkR10031			Date: 12/18/2002



The J2SE 1.4 API doc contains the following description of 
javax.sound.sampled.AudioInputStream.available():
"
    Returns the maximum number of bytes that can be read (or skipped over) 
from this audio input stream without blocking. This limit applies only to 
the next invocation of a read or skip method for this audio input stream; 
the limit can vary each time these methods are invoked.
...
Throws:
IOException - if an input or output error occurs"

The specification is ambiguous since it does not specify
AudioInputStream.available() behavior when audio 
input stream is closed: whether IOException should be thrown, or 
0 should be returned by the method. The reference implementation (JDK 
1.4.2-b10) of the method throws IOException in this case.

This bug may affect JCK1.4a test:
  api/javax_sound/sampled/AudioInputStream/index.html#close()[close001]

======================================================================

Name: dkR10031			Date: 12/19/2002


Here is the test demonstrating the behavior of the current RI:
------------------------- source begin ------------------------
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioFormat;

public class MyAIS {
    public static void main(String args[]) {
        ByteArrayInputStream bais = new ByteArrayInputStream(new byte[2000]);
        AudioFormat audioFormat = new AudioFormat(22050.0f, 8, 1, true, true);
        AudioInputStream ais = new AudioInputStream(bais, audioFormat, 10);
        try {
            ais.close();
        } catch (IOException e) {
            System.out.println("close() - IOException is thrown:"
                               + e.getMessage());
        }

        try {
            int length = ais.available();
            System.out.println("Length=" + length);
        } catch (IOException e) {
            System.out.println("IOException is thrown: " + e.getMessage());
        }
    }
}
------------------------- source end -----------------------------
Logs:
------------------------ Solaris-sparc log begin -----------------
bash-2.03$ uname -a
SunOS novo101 5.8 Generic_108528-16 sun4u sparc SUNW,Ultra-1
bash-2.03$ /export/ld25/java/dest/jdk1.4.2-b10/solaris-sparc/bin/java -showversion MyAIS
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b10)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b10, mixed mode)

IOException is thrown: Stream closed
------------------------ Solaris-sparc log end -------------------


======================================================================
###@###.### 2003-10-23
fixed

                                    

Comments
SUGGESTED FIX


###@###.### 2002-12-18
	Add a note that a closed stream throws IOException when available() is called.
                                     
2002-12-18
EVALUATION

###@###.### 2002-12-19
	When a stream is closed, it can throw IOException on access, what the RI does. I'm not sure if returning 0 would be nicer.
                                     
2002-12-19
PUBLIC COMMENTS

AudioInputStream.available description is incomplete
                                     
2004-06-10
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger
tiger-beta

FIXED IN:
tiger-beta

INTEGRATED IN:
tiger-b26
tiger-beta


                                     
2004-06-14



Hardware and Software, Engineered to Work Together