Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4932838
Votes 0
Synopsis REGRESSION: undeclared IAE in MidiSystem.getReceiver()
Category java:classes_sound
Reported Against tiger , hopper
Release Fixed 1.5(tiger-b26)
State 10-Fix Delivered, bug
Priority: 2-High
Related Bugs 4912894 , 4934262
Submit Date 06-OCT-2003
Description


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.
--------------------------------------------------------------------------
======================================================================
Work Around
N/A
Evaluation
  xxxxx@xxxxx   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.
  xxxxx@xxxxx   2003-10-15
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang