JDK-4616517 : Receiver.send() does not work properly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.0,5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2001-12-20
  • Updated: 2003-09-27
  • Resolved: 2003-09-27
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 tigerFixed
Related Reports
Relates :  
Description

Name: vtR10009			Date: 12/20/2001


  API spec for method Receiver.send() reads:
"Sends a MIDI message and time-stamp to this receiver. If time-stamping is not
supported by this receiver, the time-stamp value should be -1.
Parameters:
  message - the MIDI message to send
  time-stamp - the time-stamp for the message, in microseconds.
Throws:
  IllegalStateException - if the receiver is not open."

But this method does not throw IllegalStateException exception as expected
for closed Receiver which is linked with external MIDI output port. 
The same is true for the Receiver that is linked with the default synthesizer.
But this exception is incorrectly thrown for unclosed receiver which is linked
with Midi output port. Exception is thrown with the message: "Synthesizer
is not open". So MIDI output port is linked directly with the default
synthesizer. But API spec does not declare such behaivor.

This bug causes failure of new JCK test:
 api/javax_sound/midi/Receiver/index.html#Receiver
To reproduce the bug run the following tests with JDK 1.4.0-rc-b89:
-------------------------------1 test.java 1--------------------------------
import javax.sound.midi.*;

public class test{
    public static void main(String args[])
    {
        boolean isFailed = false;        
        Receiver rcvr;
        Synthesizer synt = null;
        ShortMessage shMsg = new ShortMessage();

        try {
            synt = MidiSystem.getSynthesizer();
            synt.open();
            rcvr = synt.getReceiver();

            rcvr.close();
            shMsg.setMessage(ShortMessage.NOTE_ON, 0,60, 93);
            rcvr.send( shMsg, -1 );
            System.out.println("IllegalStateException was not thrown "
                    + "for Synthesizer's receiver!");
        } catch(MidiUnavailableException e) {
            System.out.println("Midi unavailable, cannot test.");
            return;
        } catch(InvalidMidiDataException ine) {
            System.out.println("InvalidMidiDataException, cannot test.");
            return;
        } catch(IllegalStateException ilEx) {
            System.out.println("IllegalStateException was thrown. Ok.");
        } finally {
            if (synt != null) synt.close();
        }
        try {
            synt = MidiSystem.getSynthesizer();
            synt.open();
            rcvr = MidiSystem.getReceiver();

            rcvr.close();
            shMsg.setMessage(ShortMessage.NOTE_ON, 0,60, 93);
            rcvr.send( shMsg, -1 );
            System.out.println("IllegalStateException was not thrown "
                    + "for external MIDI output port!");
        } catch(MidiUnavailableException e) {
            System.out.println("Midi unavailable, cannot test.");
            return;
        } catch(InvalidMidiDataException ine) {
            System.out.println("InvalidMidiDataException, cannot test.");
            return;
        } catch(IllegalStateException ilEx) {
            System.out.println("IllegalStateException was thrown. Ok.");
        } finally {
            if (synt != null) synt.close();
        }
    }
}
---------------------------Logs-------------------------------------------
$ java -version
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b89)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b89, mixed mode)
$ javac test.java
$ java test
IllegalStateException was not thrown for Synthesizer's receiver!
IllegalStateException was not thrown for external MIDI output port!
$ 
-------------------------------2 test.java 2--------------------------------
import javax.sound.midi.*;

public class test{
    public static void main(String args[])
    {
        boolean isFailed = false;        
        Receiver rcvr;
        ShortMessage shMsg = new ShortMessage();

        try {
            rcvr = MidiSystem.getReceiver();

            shMsg.setMessage(ShortMessage.NOTE_ON, 0,60, 93);
            rcvr.send( shMsg, -1 );
            rcvr.close();
        } catch(MidiUnavailableException e) {
            System.out.println("Midi unavailable, cannot test.");
            return;
        } catch(InvalidMidiDataException ine) {
            System.out.println("InvalidMidiDataException, cannot test.");
            return;
        } catch(IllegalStateException ilEx) {
            ilEx.printStackTrace(System.out);
            System.out.println("IllegalStateException was thrown incorrectly!");
        } 
    }
}
---------------------------Logs-------------------------------------------
$ javac test.java
$ java test
java.lang.IllegalStateException: Synthesizer is not open.
        at 
com.sun.media.sound.AbstractPlayer$PlayerReceiver.send(AbstractPlayer.java:261)
        at test.main(test.java:14)
IllegalStateException was thrown incorrectly!
$
--------------------------------------------------------------------------
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b22
14-06-2004

EVALUATION ###@###.### 2002-11-01 Committed to Tiger. ###@###.### 2003-08-14 For getTransmitter() and getReceiver() the implementation takes the first device that has Transmitters/Receivers. This is not the intended behaviour, since the first device may be a Synthesizer or a Sequencer. Instead the implementation should test any device if it is implementing Synthesizer or Sequencer. The implementation should take the first device that is implementing neither Synthesizer nor Sequencer. It would be possible to fix this now. However, the implementation heavily interfers with the implementation of #4776511 RFE: setting the default MixerProvider. Since for this RFE, a CCC request is still pending, I'm postponing fixing this bug.
11-06-2004

PUBLIC COMMENTS Receiver.send() does not work properly
10-06-2004