src/share/classes/com/sun/media/sound/AbstractMidiDevice.java

Print this page
rev 672 : 8004261: Improve input validation
Reviewed-by: art, mschoene, amenkov, omajid

*** 54,64 **** // lock to protect receiverList and transmitterList // from simultaneous creation and destruction // reduces possibility of deadlock, compared to // synchronizing to the class instance ! private Object traRecLock = new Object(); // DEVICE ATTRIBUTES private MidiDevice.Info info; --- 54,64 ---- // lock to protect receiverList and transmitterList // from simultaneous creation and destruction // reduces possibility of deadlock, compared to // synchronizing to the class instance ! private final Object traRecLock = new Object(); // DEVICE ATTRIBUTES private MidiDevice.Info info;
*** 472,516 **** Subclasses that use Receivers must use this base class, since it contains magic necessary to manage implicit closing the device. This is necessary for Receivers retrieved via MidiSystem.getReceiver() (which opens the device implicitely). */ ! protected abstract class AbstractReceiver implements Receiver { private boolean open = true; /** Deliver a MidiMessage. This method contains magic related to the closed state of a Receiver. Therefore, subclasses should not override this method. Instead, they should implement implSend(). */ ! public synchronized void send(MidiMessage message, long timeStamp) { ! if (open) { ! implSend(message, timeStamp); ! } else { throw new IllegalStateException("Receiver is not open"); } } ! ! protected abstract void implSend(MidiMessage message, long timeStamp); ! /** Close the Receiver. * Here, the call to the magic method closeInternal() takes place. * Therefore, subclasses that override this method must call * 'super.close()'. */ ! public void close() { open = false; synchronized (AbstractMidiDevice.this.traRecLock) { AbstractMidiDevice.this.getReceiverList().remove(this); } AbstractMidiDevice.this.closeInternal(this); } ! protected boolean isOpen() { return open; } //$$fb is that a good idea? //protected void finalize() { --- 472,516 ---- Subclasses that use Receivers must use this base class, since it contains magic necessary to manage implicit closing the device. This is necessary for Receivers retrieved via MidiSystem.getReceiver() (which opens the device implicitely). */ ! abstract class AbstractReceiver implements Receiver { private boolean open = true; /** Deliver a MidiMessage. This method contains magic related to the closed state of a Receiver. Therefore, subclasses should not override this method. Instead, they should implement implSend(). */ ! @Override ! public final synchronized void send(final MidiMessage message, ! final long timeStamp) { ! if (!open) { throw new IllegalStateException("Receiver is not open"); } + implSend(message, timeStamp); } ! abstract void implSend(MidiMessage message, long timeStamp); /** Close the Receiver. * Here, the call to the magic method closeInternal() takes place. * Therefore, subclasses that override this method must call * 'super.close()'. */ ! @Override ! public final void close() { open = false; synchronized (AbstractMidiDevice.this.traRecLock) { AbstractMidiDevice.this.getReceiverList().remove(this); } AbstractMidiDevice.this.closeInternal(this); } ! final boolean isOpen() { return open; } //$$fb is that a good idea? //protected void finalize() {