JDK-4795582 : SPEC: AudioInputStream.available description is incomplete
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-12-18
  • Updated: 2017-05-16
  • Resolved: 2003-10-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
5.0 b26Fixed

Name: dkR10031			Date: 12/18/2002

The J2SE 1.4 API doc contains the following description of 
    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.
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:


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 {
        } 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 -----------------------------
------------------------ 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

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger tiger-beta FIXED IN: tiger-beta INTEGRATED IN: tiger-b26 tiger-beta

PUBLIC COMMENTS AudioInputStream.available description is incomplete

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.

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