Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6411624

MidiSystem.getSequencer() doesn't throw MidiUnavaivableException if no audio card installed

XMLWordPrintable

    • b84
    • generic
    • generic

      j2se 5.0
      j2se 6.0
      at least Linux-i586 affected (presumably it's "general" bug that affects all systems)

      when no audio card installed, MidiSystem.getSequencer() returns RealTimeSequencer with Transmitter connected to RealTimeSequencer$SequencerReceiver (i.e. to another RealTimeSequencer) instead throwing MidiUnavailableException (due spec).

      MidiSystem.getReceiver() returns RealTimeSequencer$SequencerReceiver (should return Synthesizer or MIDI OUT port)

      below is the test (exception should be thrown w/o installed sound card):

      import javax.sound.midi.*;
      import java.util.*;

      public class defSequencer {
          
          public defSequencer() {
          }

          public void main(String[] args) {
              Sequencer seq = null;
              try {
                  System.out.println("getting sequencer...");
                  seq = MidiSystem.getSequencer();
                  System.out.println("OK: " + seq);
                  
                  List<Receiver> recvList = seq.getReceivers();
                  System.out.println("Receivers"
                          + " (count=" + recvList.size() + ","
                          + " max=" + seq.getMaxReceivers() + "):");
                  Iterator<Receiver> recvIter = recvList.iterator();
                  while (recvIter.hasNext()) {
                      Receiver recv = recvIter.next();
                      System.out.println(" - " + recv);
                  }
                  
                  List<Transmitter> transList = seq.getTransmitters();
                  System.out.println("Transmitters"
                          + " (count=" + transList.size() + ","
                          + " max=" + seq.getMaxTransmitters());
                  Iterator<Transmitter> transIter = transList.iterator();
                  while (transIter.hasNext()) {
                      Transmitter trans = transIter.next();
                      System.out.println(" - " + trans);
                      Receiver recv = trans.getReceiver();
                      System.out.println(" => " + recv);
                  }
                  
                  System.out.println("opening sequencer...");
                  seq.open();
                  System.out.println("OK.");
                  
                  System.out.println("closing...");
                  seq.close();
                  System.out.println("OK.");
              } catch (Exception ex) {
                  ex.printStackTrace();
              }
          }
      }

            amenkov Alex Menkov
            amenkov Alex Menkov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: