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.
Other
5.0 b26Fixed
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
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger tiger-beta FIXED IN: tiger-beta INTEGRATED IN: tiger-b26 tiger-beta
14-06-2004

PUBLIC COMMENTS AudioInputStream.available description is incomplete
10-06-2004

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.
19-12-2002

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