JDK-4932838 : REGRESSION: undeclared IAE in MidiSystem.getReceiver()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.1,5.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2003-10-06
  • Updated: 2004-01-15
  • 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
Related Reports
Duplicate :  
Relates :  
Description
Name: vtR10009			Date: 10/06/2003


MidiSystem.getReceiver() method should not throw undeclared
IllegalArgumentException instead of MidiUnavailableException.
The same is true for method MidiSystem.getTransmitter().

Note the test is passed by mantis (jdk1.4.2). So this is 
regression (of bug #4616517 probably).

This bug causes failure of new JCK test:
  api/javax_sound/midi/MidiSystem/index.html#get[get005]
To reproduce the bug run the following test with JDK build 1.5-b22:
------------------------------- test.java --------------------------------
import javax.sound.sampled.*;
import javax.sound.midi.*;

public class test {

    static boolean isSoundAccessDenied = false;
    static {
        SecurityManager securityManager = System.getSecurityManager();
        if (securityManager != null) {
            try {
                securityManager.checkPermission(new AudioPermission("*"));
            } catch (SecurityException e) {
                isSoundAccessDenied = true;
            }
        }
    }

    static final int STATUS_PASSED = 0;
    static final int STATUS_FAILED = 2;
    static final int STATUS_TEMP = 95;
    static java.io.PrintStream log = System.err; 
    
    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) {
        boolean failed = false;
        Receiver recv;
        Transmitter transm;
    
        try {
            recv = MidiSystem.getReceiver();
            transm = MidiSystem.getTransmitter();
            if (recv == null) {
                log.println("No external Midi output port!");
                failed = true;
            }
            if (transm == null) {
                log.println("No external Midi input port!");
                failed = true;
            }
        } catch (MidiUnavailableException midiUnvEx) {
            out.println("MidiUnavailableException was caught!");
            return STATUS_PASSED;
        }
    
        if (failed == true) {
            return STATUS_FAILED;
        } else {
            out.println("Ok.");
            return STATUS_PASSED;
        }
    }
    
}    // end of test class 
---------------------------Logs-------------------------------------------
novo101:tmp$ javac -d . test.java 
novo101:tmp$ $JDK15/bin/java -showversion -cp . test
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b22)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b22, mixed mode)

Exception in thread "main" java.lang.IllegalArgumentException: Requested device 
not installed
        at javax.sound.midi.MidiSystem.getDefaultDevice(MidiSystem.java:926)
        at javax.sound.midi.MidiSystem.getReceiver(MidiSystem.java:223)
        at test.run(test.java:33)
        at test.main(test.java:24)
novo101:tmp$ java -showversion -cp . test
java version "1.4.2-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-rc-b25)
Java HotSpot(TM) Client VM (build 1.4.2-rc-b25, mixed mode)

Ok.
--------------------------------------------------------------------------
======================================================================

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

EVALUATION ###@###.### 2003-10-07 The "problem" here is that we now got the implementation of MidiSystem.getReceiver() right. This method is intended to return a receiver from a MidiDevice that represents a hardware MIDI port. If no MIDI port is available, the method should fail in some way. In 1.4.2, however, if no MIDI port is available, the method returned a Receiver from a Synthesizer or Sequencer, which is not what it should do. The specification of this method says that MidiUnavailableException should be thrown if no Receiver is available due to resource restrictions. This is the case if there is a MidiDevice representing a MIDI port, but it has exceeded its maximum number of Receivers. In this case, it is possible to close one of this device's Receivers, and a subsequent call to MidiDevice.getReceiver() should succeed. This is what is meant by "resource restriction". In your case, however, MidiSystem.getReceiver() fails because there is no MIDI port at all. We felt that this is a condition different from "resource restriction" and should therefore signaled by a different exception (not MidiUnavailableException). Since for an application program it is possible to find out if there are MIDI ports by examining the result of MidiSystem.getMidiDeviceInfo() in combination with MidiSystem.getMidiDevice(), we considered requesting a Receiver from a non-existing device to be an illegal request, somewhat similar to an illegal argument. And actually, the code that throws the IllegalArgumentException existed before. It was never executed prior to 1.5 because Java Sound's software synthesizer is always present and provides Receivers. So we came to the conclusion that throwing the IAE is really the right thing, and addressed this in a spec bug #4912894. So this bug should be closed as duplicate. I suggest to modify the test case to check if there are MIDI ports. If so, MidiSystem.getReceiver() should not throw an IllegalArgumentException. If, however, there are no MIDI ports, the implementation is perhaps not required, but strongly recommended to throw an IAE. To find out if there are MIDI ports, see the attached file. The method is MidiInstalled() test if there is a MIDI port. Note that is is necessary to test the class of the actual device to be neither Sequencer nor Synthesizer. Otherwise, the method would always return true, becuse sequencers and synthesizers are always available. The evaluation has been superceded after discussion over bug 4912894 "SPEC: MidiSystem.getSequencer() etc. should declare InvalidArgumentException.". The outcome is that MidiSystem.getReceiver will not throw IAE under any circumstances. So this bug is valid and will remain open until fixed in J2SE. ###@###.### 2003-10-15
15-10-2003