changeset 16025:5445b9413d9d

8167615: Opensource unit/regression tests for JavaSound Reviewed-by: amenkov
author serb
date Mon, 31 Oct 2016 14:50:09 +0300
parents 329b1a617404
children f970d80b7a55
files test/ProblemList.txt test/javax/sound/midi/Devices/ClosedReceiver.java test/javax/sound/midi/Devices/IOLoop.java test/javax/sound/midi/Devices/MidiDeviceGetReceivers.java test/javax/sound/midi/Devices/MidiIO.java test/javax/sound/midi/Devices/MidiOutGetMicrosecondPositionBug.java test/javax/sound/midi/Devices/OpenClose.java test/javax/sound/midi/Devices/ReceiverTransmitterAvailable.java test/javax/sound/midi/Devices/Reopen.java test/javax/sound/midi/File/SMFCp037.java test/javax/sound/midi/File/SMFParserBreak.java test/javax/sound/midi/File/WriteRealTimeMessageNPE.java test/javax/sound/midi/MetaMessage/MetaMessageClone.java test/javax/sound/midi/MidiSystem/6411624/Test6411624.java test/javax/sound/midi/MidiSystem/6411624/bug6411624.java test/javax/sound/midi/MidiSystem/DefaultDevices.java test/javax/sound/midi/MidiSystem/DefaultProperties.java test/javax/sound/midi/MidiSystem/GetSequencer.java test/javax/sound/midi/MidiSystem/MidiFileTypeUniqueness.java test/javax/sound/midi/MidiSystem/ProviderCacheing.java test/javax/sound/midi/MidiSystem/testdata/conf/sound.properties test/javax/sound/midi/Sequence/GetMicrosecondLength.java test/javax/sound/midi/Sequence/MidiSMPTE.java test/javax/sound/midi/Sequence/SMPTEDuration.java test/javax/sound/midi/Sequencer/LoopIAE.java test/javax/sound/midi/Sequencer/Looping.java test/javax/sound/midi/Sequencer/MetaCallback.java test/javax/sound/midi/Sequencer/Recording.java test/javax/sound/midi/Sequencer/SeqRecordDoesNotCopy.java test/javax/sound/midi/Sequencer/SeqRecordsRealTimeEvents.java test/javax/sound/midi/Sequencer/SeqStartRecording.java test/javax/sound/midi/Sequencer/SequencerCacheValues.java test/javax/sound/midi/Sequencer/SequencerSetMuteSolo.java test/javax/sound/midi/Sequencer/SequencerState.java test/javax/sound/midi/Sequencer/SetTickPosition.java test/javax/sound/midi/Sequencer/TickLength.java test/javax/sound/midi/ShortMessage/FastShortMessage.java test/javax/sound/midi/ShortMessage/FastShortMessage2.java test/javax/sound/midi/Soundbanks/ExtraCharInSoundbank.java test/javax/sound/midi/Soundbanks/GetSoundBankIOException.java test/javax/sound/midi/Synthesizer/AsynchronousMidiChannel.java test/javax/sound/midi/Synthesizer/Receiver/bug6186488.java test/javax/sound/midi/Synthesizer/SynthesizerGetLatency.java test/javax/sound/midi/Synthesizer/bug4685396.java test/javax/sound/midi/Track/TrackAddSameTick.java test/javax/sound/midi/Track/bug6416024.java test/javax/sound/midi/Transmitter/bug6415669.java test/javax/sound/sampled/AudioFileFormat/AudioFileFormatToString.java test/javax/sound/sampled/AudioFileFormat/Properties.java test/javax/sound/sampled/AudioFileFormat/TypeEquals.java test/javax/sound/sampled/AudioFormat/AudioFormatBitSize.java test/javax/sound/sampled/AudioFormat/EncodingEquals.java test/javax/sound/sampled/AudioFormat/Properties.java test/javax/sound/sampled/AudioInputStream/AISReadFraction.java test/javax/sound/sampled/AudioInputStream/bug6188860.java test/javax/sound/sampled/AudioSystem/AudioFileTypes/AudioFileTypeUniqueness.java test/javax/sound/sampled/AudioSystem/AudioFileTypes/ShowAudioFileTypes.java test/javax/sound/sampled/AudioSystem/DefaultMixers.java test/javax/sound/sampled/AudioSystem/DefaultProperties.java test/javax/sound/sampled/AudioSystem/ProviderCacheing.java test/javax/sound/sampled/AudioSystem/testdata/conf/sound.properties test/javax/sound/sampled/Clip/ClipCloseLoss.java test/javax/sound/sampled/Clip/ClipFlushCrash.java test/javax/sound/sampled/Clip/Drain/ClipDrain.java test/javax/sound/sampled/Clip/Duration/ClipDuration.java test/javax/sound/sampled/Clip/Endpoint/ClipSetEndPoint.java test/javax/sound/sampled/Clip/Open/ClipOpenBug.java test/javax/sound/sampled/Clip/bug5070081.java test/javax/sound/sampled/Clip/bug6251460.java test/javax/sound/sampled/Controls/CompoundControl/ToString.java test/javax/sound/sampled/Controls/FloatControl/FloatControlBug.java test/javax/sound/sampled/DataLine/DataLineInfoNegBufferSize.java test/javax/sound/sampled/DataLine/LineDefFormat.java test/javax/sound/sampled/DataLine/LongFramePosition.java test/javax/sound/sampled/DirectAudio/TickAtEndOfPlay.java test/javax/sound/sampled/DirectAudio/bug6372428.java test/javax/sound/sampled/FileTypeExtension/FileTypeExtensionTest.java test/javax/sound/sampled/LineEvent/LineInfoNPE.java test/javax/sound/sampled/Lines/16and32KHz/Has16and32KHz.java test/javax/sound/sampled/Lines/BufferSizeCheck.java test/javax/sound/sampled/Lines/ChangingBuffer.java test/javax/sound/sampled/Lines/ClickInPlay/ClickInPlay.java test/javax/sound/sampled/Lines/ClickInPlay/Test4218609.java test/javax/sound/sampled/Lines/ClipOpenException.java test/javax/sound/sampled/Lines/FrameSize/FrameSizeTest.java test/javax/sound/sampled/Lines/GetLine.java test/javax/sound/sampled/Lines/SDLwrite.java test/javax/sound/sampled/Lines/SourceDataLineDefaultBufferSizeCrash.java test/javax/sound/sampled/Lines/StopStart.java test/javax/sound/sampled/LinuxBlock/PlaySine.java test/javax/sound/sampled/LinuxCrash/ClipLinuxCrash.java test/javax/sound/sampled/LinuxCrash/ClipLinuxCrash2.java test/javax/sound/sampled/LinuxCrash/SDLLinuxCrash.java test/javax/sound/sampled/Mixers/BogusMixers.java test/javax/sound/sampled/Mixers/BothEndiansAndSigns.java test/javax/sound/sampled/Mixers/DirectSoundRepeatingBuffer/DirectSoundRepeatingBuffer.java test/javax/sound/sampled/Mixers/DirectSoundRepeatingBuffer/Test4997635.java test/javax/sound/sampled/Mixers/DirectSoundUnderrunSilence/DirectSoundUnderrunSilence.java test/javax/sound/sampled/Mixers/DirectSoundUnderrunSilence/Test5032020.java test/javax/sound/sampled/Mixers/DisabledAssertionCrash.java test/javax/sound/sampled/Mixers/NoSimpleInputDevice.java test/javax/sound/sampled/Mixers/PhantomMixers.java test/javax/sound/sampled/Mixers/PlugHwMonoAnd8bitAvailable.java test/javax/sound/sampled/Mixers/UnexpectedIAE.java test/javax/sound/sampled/Recording/TargetDataLineFlush.java test/javax/sound/sampled/spi/AudioFileReader/AIFFCp037.java test/javax/sound/sampled/spi/AudioFileReader/AIFFLargeHeader.java test/javax/sound/sampled/spi/AudioFileReader/Aiff12bit.java test/javax/sound/sampled/spi/AudioFileReader/AuNotSpecified.java test/javax/sound/sampled/spi/AudioFileReader/AuZeroLength.java test/javax/sound/sampled/spi/AudioFileReader/OpenWaveFile.java test/javax/sound/sampled/spi/AudioFileWriter/AUwithULAW.java test/javax/sound/sampled/spi/AudioFileWriter/AiffSampleRate.java test/javax/sound/sampled/spi/AudioFileWriter/RIFFHeader.java test/javax/sound/sampled/spi/AudioFileWriter/WaveBigEndian.java test/javax/sound/sampled/spi/AudioFileWriter/WriteAuUnspecifiedLength.java test/javax/sound/sampled/spi/FormatConversionProvider/AlawUlaw.java
diffstat 117 files changed, 17031 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/test/ProblemList.txt	Mon Oct 31 12:10:08 2016 +0530
+++ b/test/ProblemList.txt	Mon Oct 31 14:50:09 2016 +0300
@@ -221,6 +221,13 @@
 ############################################################################
 
 # jdk_sound
+javax/sound/sampled/DirectAudio/bug6372428.java        8055097 generic-all
+javax/sound/sampled/Clip/bug5070081.java               8055097 generic-all
+javax/sound/sampled/DataLine/LongFramePosition.java    8055097 generic-all
+
+javax/sound/sampled/Clip/Drain/ClipDrain.java          7062792 generic-all
+
+javax/sound/sampled/Mixers/DisabledAssertionCrash.java 7067310 generic-all
 
 ############################################################################
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Devices/ClosedReceiver.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Receiver;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Synthesizer;
+
+/**
+ * @test
+ * @bug 4616517
+ * @summary Receiver.send() does not work properly
+ */
+public class ClosedReceiver {
+
+    public static void main(String[] args) throws Exception {
+        out("#4616517: Receiver.send() does not work properly");
+        if (!isMidiInstalled()) {
+            out("Soundcard does not exist or sound drivers not installed!");
+            out("This test requires sound drivers for execution.");
+            return;
+        }
+
+        boolean passed = true;
+
+        passed &= testReceiverSend();
+        passed &= testClosedReceivers();
+        if (passed) {
+            out("Test PASSED.");
+        } else {
+            throw new Exception("Test FAILED.");
+        }
+    }
+
+    /**
+     * Execute Receiver.send() and expect that there is no exception.
+     */
+    private static boolean testReceiverSend() {
+        boolean result = true;
+
+        Receiver receiver;
+        ShortMessage shMsg = new ShortMessage();
+
+        try {
+            receiver = MidiSystem.getReceiver();
+            shMsg.setMessage(ShortMessage.NOTE_ON, 0,60, 93);
+            try {
+                receiver.send( shMsg, -1 );
+            } catch(IllegalStateException ilEx) {
+                ilEx.printStackTrace(System.out);
+                out("IllegalStateException was thrown incorrectly!");
+                result = false;
+            }
+            receiver.close();
+        } catch(MidiUnavailableException e) {
+            out("Midi unavailable, cannot test.");
+        } catch(InvalidMidiDataException ine) {
+            out("InvalidMidiDataException, cannot test.");
+        }
+        return result;
+    }
+
+    private static boolean testClosedReceivers() {
+        boolean result = true;
+        Receiver receiver;
+        Synthesizer synt = null;
+
+        // test Synthesizer's Receiver
+        try {
+            synt = MidiSystem.getSynthesizer();
+            synt.open();
+        } catch(MidiUnavailableException e) {
+            out("Midi unavailable, cannot test.");
+            return result;
+        }
+        try {
+            receiver = synt.getReceiver();
+        } catch (MidiUnavailableException e) {
+            out("unable to get Receiver from synthesizer, cannot test.");
+            return result;
+        }
+        result &= testClosedReceiver(receiver);
+        synt.close();
+
+        // test all MidiDevices' Receivers
+
+        MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
+        for (int i = 0; i < devices.length; i++) {
+            try {
+                MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
+                if (device.getMaxReceivers() != 0) {
+                    receiver = device.getReceiver();
+                    result &= testClosedReceiver(receiver);
+                }
+            } catch (Exception e) {
+                out(e);
+                out("cannot test.");
+                return result;
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Execute send() on a closed Receivers and expect IllegalStateException.
+     */
+    private static boolean testClosedReceiver(Receiver receiver) {
+        boolean result = true;
+        out("testing Receiver: " + receiver);
+        ShortMessage shMsg = new ShortMessage();
+        try {
+            shMsg.setMessage(ShortMessage.NOTE_ON, 0,60, 93);
+        } catch(InvalidMidiDataException e) {
+            out(e);
+            out("unable to construct ShortMessage, cannot test.");
+            return result;
+        }
+
+        // begin of test
+        receiver.close();
+        try {
+            receiver.send( shMsg, -1 );
+            out("IllegalStateException was not thrown "
+                + "on Receiver.send()!");
+            result = false;
+        } catch(IllegalStateException e) {
+            out("IllegalStateException was thrown. Ok.");
+        }
+        return result;
+    }
+
+    private static void out(Throwable t) {
+        t.printStackTrace(System.out);
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+
+    /**
+     * Returns true if at least one MIDI (port) device is correctly installed on
+     * the system.
+     */
+    private static boolean isMidiInstalled() {
+        boolean result = false;
+        MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
+        for (int i = 0; i < devices.length; i++) {
+            try {
+                MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
+                result = !(device instanceof Sequencer)
+                        && !(device instanceof Synthesizer);
+            } catch (Exception e1) {
+                System.err.println(e1);
+            }
+            if (result)
+                break;
+        }
+        return result;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Devices/IOLoop.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,404 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayOutputStream;
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiMessage;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Receiver;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.SysexMessage;
+import javax.sound.midi.Transmitter;
+
+/**
+ * @test
+ * @bug 4782924
+ * @bug 4812168
+ * @bug 4356787
+ * @summary MIDI i/o. This is an interactive test! Start it and follow the
+ *          instructions.
+ * @run main/manual IOLoop
+ */
+public class IOLoop {
+    private static final int LONG_SYSEX_LENGTH = 2000;
+
+    private static Receiver receiver;
+    private static Transmitter transmitter;
+    private static MidiMessage receivedMessage;
+    private static ByteArrayOutputStream baos;
+    private static int expectedBytes;
+    private static int receivedBytes;
+    private static Object lock = new Object();
+    private static long lastTimestamp;
+
+    public static void main(String[] args) throws Exception {
+        ShortMessage sMsg = new ShortMessage();
+        SysexMessage syMsg = new SysexMessage();
+        boolean isTestPassed = true;
+        boolean sysExTestPassed = true;
+        boolean isTestExecuted = true;
+
+        out("To run this test successfully, you need to have attached");
+        out("  your MIDI out port with the MIDI in port.");
+
+        MidiDevice inDev = null;
+        MidiDevice outDev = null;
+
+        // setup
+        try {
+            MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
+
+            int devNum = Integer.decode(args[0]).intValue();
+            out("-> opening Transmitter from "+infos[devNum]);
+            inDev = MidiSystem.getMidiDevice(infos[devNum]);
+            inDev.open();
+            transmitter = inDev.getTransmitter();
+            Receiver testReceiver = new TestReceiver();
+            transmitter.setReceiver(testReceiver);
+
+            devNum = Integer.decode(args[1]).intValue();
+            out("-> opening Receiver from "+infos[devNum]);
+            outDev = MidiSystem.getMidiDevice(infos[devNum]);
+            outDev.open();
+            receiver = outDev.getReceiver();
+
+        } catch (Exception e) {
+            System.out.println(e);
+            System.out.println("Cannot test!");
+            return;
+        }
+
+        // test
+        sMsg.setMessage(ShortMessage.NOTE_OFF | 0, 27, 100);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.NOTE_OFF | 0, 0, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.NOTE_OFF | 15, 127, 127);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.NOTE_ON | 4, 27, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.NOTE_ON | 0, 0, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.NOTE_ON | 15, 127, 127);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.POLY_PRESSURE | 11, 98, 99);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.POLY_PRESSURE | 0, 0, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.POLY_PRESSURE | 15, 127, 127);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.CONTROL_CHANGE | 13, 1, 63);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.CONTROL_CHANGE | 0, 0, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.CONTROL_CHANGE | 15, 127, 127);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.PROGRAM_CHANGE | 2, 120, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.PROGRAM_CHANGE | 0, 0, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.PROGRAM_CHANGE | 15, 127, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.CHANNEL_PRESSURE | 6, 30, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.CHANNEL_PRESSURE | 0, 0, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.CHANNEL_PRESSURE | 15, 127, 0);
+        isTestPassed &= testMessage(sMsg);
+
+        sMsg.setMessage(ShortMessage.PITCH_BEND | 6, 56, 4);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.PITCH_BEND | 0, 0, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.PITCH_BEND | 15, 127, 127);
+        isTestPassed &= testMessage(sMsg);
+
+        sMsg.setMessage(ShortMessage.MIDI_TIME_CODE, 0, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.MIDI_TIME_CODE, 127, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.SONG_POSITION_POINTER, 1, 77);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.SONG_POSITION_POINTER, 0, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.SONG_POSITION_POINTER, 127, 127);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.SONG_SELECT, 51, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.SONG_SELECT, 0, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.SONG_SELECT, 127, 0);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.TUNE_REQUEST);
+        isTestPassed &= testMessage(sMsg);
+
+        sMsg.setMessage(ShortMessage.TIMING_CLOCK);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.START);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.CONTINUE);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.STOP);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.ACTIVE_SENSING);
+        isTestPassed &= testMessage(sMsg);
+        sMsg.setMessage(ShortMessage.SYSTEM_RESET);
+        isTestPassed &= testMessage(sMsg);
+
+        syMsg.setMessage(new byte[]{(byte) 0xF0, (byte) 0xF7}, 2);
+        isTestPassed &= testMessage(syMsg);
+        syMsg.setMessage(new byte[]{(byte) 0xF0, 0x01, (byte) 0xF7}, 3);
+        isTestPassed &= testMessage(syMsg);
+        syMsg.setMessage(new byte[]{(byte) 0xF0, 0x02, 0x03, (byte) 0xF7}, 4);
+        isTestPassed &= testMessage(syMsg);
+        syMsg.setMessage(new byte[]{(byte) 0xF0, 0x04, 0x05, 0x06, (byte) 0xF7}, 5);
+        isTestPassed &= testMessage(syMsg);
+
+        if (isTestPassed) {
+            byte[] sysexArray = new byte[LONG_SYSEX_LENGTH];
+            sysexArray[0] = (byte) 0xF0;
+            for (int i = 1; i < sysexArray.length; i++) {
+                sysexArray[i] = (byte) (i % 0x80);
+            }
+//          syMsg.setMessage(new byte[]{(byte) 0xF7, (byte) ShortMessage.START}, 2);
+//          sMsg.setMessage(ShortMessage.START);
+//          isTestPassed &= testMessage(syMsg, sMsg, DEFAULT_SLEEP_INTERVALL);
+            for (int trial = sysexArray.length; trial > 4; trial -= 1234) {
+                sleep(500);
+                sysexArray[trial - 1] = (byte) 0xF7;
+                syMsg.setMessage(sysexArray, trial);
+                sysExTestPassed &= testMessage(syMsg);
+                break;
+            }
+        }
+
+        // cleanup
+        receiver.close();
+        transmitter.close();
+        inDev.close();
+        outDev.close();
+
+        if (isTestExecuted) {
+            if (isTestPassed && sysExTestPassed) {
+
+                out("Test PASSED.");
+            } else {
+                if (isTestPassed
+                    && !sysExTestPassed
+                    && (System.getProperty("os.name").startsWith("Windows"))) {
+                    out("Some Windows MIDI i/o drivers have a problem with larger ");
+                    out("sys ex messages. The failing sys ex cases are OK, therefore.");
+                    out("Test PASSED.");
+                } else {
+                    throw new Exception("Test FAILED.");
+                }
+            }
+        } else {
+            out("Test NOT FAILED");
+        }
+    }
+
+    private static boolean testMessage(MidiMessage message) {
+        receivedMessage = null;
+        baos = new ByteArrayOutputStream();
+        expectedBytes = message.getLength();
+        receivedBytes = 0;
+        System.out.print("Sending message " + getMessageString(message.getMessage())+"...");
+        receiver.send(message, -1);
+        /* sending 3 bytes can roughly be done in 1 millisecond,
+         * so this estimate waits at max 3 times longer than the message takes,
+         * plus a little offset to allow the MIDI subsystem some processing time
+         */
+        int offset = 300; // standard offset 100 millis
+        if (message instanceof SysexMessage) {
+            // add a little processing time to sysex messages
+            offset += 1000;
+        }
+        if (receivedBytes < expectedBytes) {
+            sleep(expectedBytes + offset);
+        }
+        boolean equal;
+        byte[] data = baos.toByteArray();
+        if (data.length > 0) {
+            equal = messagesEqual(message.getMessage(), data);
+        } else {
+            equal = messagesEqual(message, receivedMessage);
+            if (receivedMessage != null) {
+                data = receivedMessage.getMessage();
+            } else {
+                data = null;
+            }
+        }
+        if (!equal) {
+            if ((message.getStatus() & 0xF0) == ShortMessage.PITCH_BEND) {
+                out("NOT failed (may expose a bug in ALSA)");
+                equal = true;
+                sleep(100);
+            }
+            if ((message.getStatus() == 0xF6) && (message.getLength() == 1)) {
+                out("NOT failed (may expose an issue on Solaris)");
+                equal = true;
+                sleep(100);
+            }
+            else if ((message.getStatus()) == 0xF0 && message.getLength() < 4) {
+                out("NOT failed (not a correct sys ex message)");
+                equal = true;
+                sleep(200);
+            } else {
+                out("FAILED:");
+                out("  received as " + getMessageString(data));
+            }
+        } else {
+            System.out.println("OK");
+        }
+        return equal;
+    }
+
+    private static void sleep(int milliseconds) {
+        synchronized(lock) {
+            try {
+                lock.wait(milliseconds);
+            } catch (InterruptedException e) {
+            }
+        }
+    }
+
+    private static String getMessageString(byte[] data) {
+        String s;
+        if (data == null) {
+            s = "<null>";
+        } else if (data.length == 0) {
+            s = "0-sized array";
+        } else {
+            int status = data[0] & 0xFF;
+            if (data.length <= 3) {
+                if (status < 240) {
+                    s = "command 0x" + Integer.toHexString(status & 0xF0) + " channel " + (status & 0x0F);
+                } else {
+                    s = "status 0x" + Integer.toHexString(status);
+                }
+                if (data.length > 1) {
+                    s += " data 0x" + Integer.toHexString(data[1] & 0xFF);
+                    if (data.length > 2) {
+                        s += " 0x" + Integer.toHexString(data[2] & 0xFF);
+                    }
+                }
+            } else {
+                s = "status " + Integer.toHexString(status)+" and length "+data.length+" bytes";
+            }
+        }
+        return s;
+    }
+
+    private static boolean messagesEqual(MidiMessage m1, MidiMessage m2) {
+        if (m1 == null || m2 == null) {
+            return false;
+        }
+        if (m1.getLength() != m2.getLength()) {
+            return false;
+        }
+        byte[] array1 = m1.getMessage();
+        byte[] array2 = m2.getMessage();
+        return messagesEqual(array1, array2);
+    }
+
+    private static boolean messagesEqual(byte[] a1, byte[] a2) {
+        if (a1.length != a2.length) return false;
+        for (int i = 0; i < a1.length; i++) {
+            if (a1[i] != a2[i]) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private static void out(String s) {
+        System.out.println(s);
+        System.out.flush();
+    }
+
+    private static String canIn(MidiDevice dev) {
+        if (dev.getMaxTransmitters() != 0) {
+            return "IN ";
+        }
+        return "   ";
+    }
+
+    private static String canOut(MidiDevice dev) {
+        if (dev.getMaxReceivers() != 0) {
+            return "OUT ";
+        }
+        return "   ";
+    }
+
+
+    private static void checkTimestamp(long timestamp) {
+        // out("checking timestamp...");
+        if (timestamp < 1) {
+            out("timestamp 0 or negative!");
+        }
+        if (timestamp < lastTimestamp) {
+            out("timestamp not progressive!");
+        }
+        lastTimestamp = timestamp;
+    }
+
+    private static class TestReceiver implements Receiver {
+        public void send(MidiMessage message, long timestamp) {
+            //System.out.print(""+message.getLength()+"..");
+            checkTimestamp(timestamp);
+            try {
+                receivedMessage = message;
+                if (message.getStatus() == 0xF0
+                    || (message.getLength() > 3 && message.getStatus() != 0xF7)) {
+                    // sys ex message
+                    byte[] data = message.getMessage();
+                    baos.write(data);
+                    receivedBytes += data.length;
+                }
+                else if (message.getStatus() == 0xF7) {
+                    // sys ex cont'd message
+                    byte[] data = message.getMessage();
+                    // ignore the prepended 0xF7
+                    baos.write(data, 1, data.length-1);
+                    receivedBytes += (data.length - 1);
+                } else {
+                    receivedBytes += message.getLength();
+                }
+                if (receivedBytes >= expectedBytes) {
+                    synchronized(lock) {
+                        lock.notify();
+                    }
+                }
+                System.out.print(""+receivedBytes+"..");
+
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+
+        public void close() {
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Devices/MidiDeviceGetReceivers.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.List;
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Receiver;
+import javax.sound.midi.Transmitter;
+
+/**
+ * @test
+ * @bug 4931387
+ * @summary Add methods to MidiDevice to get list of Transmitters and Receivers
+ */
+public class MidiDeviceGetReceivers {
+
+    private static boolean executed = false;
+    private static boolean failed = false;
+
+    public static void main(String[] args) throws Exception {
+        out("unit test 4931387: Add methods to MidiDevice to get list of Transmitters and Receivers");
+        doAllTests();
+        if (executed) {
+            if (failed) throw new Exception("Test FAILED!");
+            out("Test PASSED.");
+        } else {
+            out("Test NOT failed.");
+        }
+    }
+
+    private static void doAllTests() {
+        MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
+        for (int i = 0; i < infos.length; i++) {
+            MidiDevice device = null;
+            try {
+                device = MidiSystem.getMidiDevice(infos[i]);
+                doTest(device);
+            } catch (MidiUnavailableException e) {
+                out("Exception occured when retrieving device "+infos[i]+": "+e);
+            }
+        }
+        if (infos.length == 0) {
+            out("No MIDI devices exist or sound drivers not installed!");
+        }
+    }
+
+    private static boolean containsReceiver(MidiDevice dev, Receiver rec) {
+        List<Receiver> recvs = dev.getReceivers();
+        return recvs.contains(rec);
+    }
+
+    private static boolean containsTransmitter(MidiDevice dev, Transmitter tra) {
+        List<Transmitter> tras = dev.getTransmitters();
+        return tras.contains(tra);
+    }
+
+    private static void doTest(MidiDevice device) {
+        boolean thisFailed = false;
+        out1("Testing: " + device+"...");
+        try {
+            device.open();
+        } catch (Exception e) {
+            out2("device.open threw exception: "+e);
+            out2("cannot test this device.");
+            return;
+        }
+        if (device.getMaxReceivers() != 0) {
+            // device offers receivers
+            try {
+                List<Receiver> origList = device.getReceivers();
+                Receiver rec = device.getReceiver();
+                if (!containsReceiver(device, rec)) {
+                    out2("Getting a receiver did not add it to device list!");
+                    thisFailed = true;
+                }
+                if (origList.contains(rec)) {
+                    out2("Original unmodifiable list was modified by adding a receiver!");
+                    thisFailed = true;
+                }
+                rec.close();
+                if (containsReceiver(device, rec)) {
+                    out2("Closing a receiver did not remove it from device list!");
+                    thisFailed = true;
+                }
+                // add a new receiver so that the device.close will really test
+                // that the receiver is removed
+                rec = device.getReceiver();
+                if (!containsReceiver(device, rec)) {
+                    out2("Getting a receiver again did not add it to device list!");
+                    thisFailed = true;
+                }
+            } catch (MidiUnavailableException e) {
+                out2("Exception on getting Receiver: " + e);
+            }
+        }
+        if (device.getMaxTransmitters() != 0) {
+            // device offers transmitters
+            try {
+                List<Transmitter> origList = device.getTransmitters();
+                Transmitter tra = device.getTransmitter();
+                if (!containsTransmitter(device, tra)) {
+                    out2("Getting a transmitter did not add it to device list!");
+                    thisFailed = true;
+                }
+                if (origList.contains(tra)) {
+                    out2("Original unmodifiable list was modified by adding a transmitter!");
+                    thisFailed = true;
+                }
+                tra.close();
+                if (containsTransmitter(device, tra)) {
+                    out2("Closing a transmitter did not remove it from device list!");
+                    thisFailed = true;
+                }
+                tra = device.getTransmitter();
+                if (!containsTransmitter(device, tra)) {
+                    out2("Getting a transmitter again did not add it to device list!");
+                    thisFailed = true;
+                }
+            } catch (MidiUnavailableException e) {
+                out("Exception on getting Transmitter: " + e);
+            }
+        }
+        try {
+            device.close();
+            if (device.getTransmitters().size() > 0) {
+                out2(" Device still has transmitters after close() was called!");
+                thisFailed = true;
+            }
+            if (device.getReceivers().size() > 0) {
+                out2(" Device still has receivers after close() was called!");
+                thisFailed = true;
+            }
+        } catch (Exception e) {
+            out2("device.close threw exception: "+e);
+        }
+        if (!thisFailed) {
+            out("OK");
+        } else {
+            failed = true;
+        }
+        executed = true;
+    }
+
+    static boolean lfMissing = false;
+
+    private static void out(String message) {
+        lfMissing = true;
+        System.out.println(message);
+    }
+
+    /* don't print LF at end */
+    private static void out1(String message) {
+        System.out.print(message);
+        lfMissing = true;
+    }
+
+    /* print at a new line, indented */
+    private static void out2(String message) {
+        if (lfMissing) {
+            System.out.println();
+            lfMissing = false;
+        }
+        System.out.println("  "+message);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Devices/MidiIO.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+
+/**
+ * @test
+ * @bug 4356787
+ * @summary MIDI device I/O is not working
+ */
+public class MidiIO {
+
+    public static void main(String[] args) throws Exception {
+        out("4356787: MIDI device I/O is not working (windows)");
+
+        if (System.getProperty("os.name").startsWith("Windows")) {
+            boolean forInput=true;
+            boolean forOutput=true;
+            int outOnlyCount=0;
+            int inOnlyCount=0;
+            out("  available MIDI devices:");
+            MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo();
+            for (int i = 0; i < aInfos.length; i++) {
+                try {
+                    MidiDevice      device = MidiSystem.getMidiDevice(aInfos[i]);
+                    boolean         bAllowsInput = (device.getMaxTransmitters() != 0);
+                    boolean         bAllowsOutput = (device.getMaxReceivers() != 0);
+                    if (bAllowsInput && !bAllowsOutput) {
+                        inOnlyCount++;
+                    }
+                    if (!bAllowsInput && bAllowsOutput) {
+                        outOnlyCount++;
+                    }
+                    if ((bAllowsInput && forInput) || (bAllowsOutput && forOutput)) {
+                        out(""+i+"  "
+                                +(bAllowsInput?"IN ":"   ")
+                                +(bAllowsOutput?"OUT ":"    ")
+                                +aInfos[i].getName()+", "
+                                +aInfos[i].getVendor()+", "
+                                +aInfos[i].getVersion()+", "
+                                +aInfos[i].getDescription());
+                    }
+                }
+                catch (MidiUnavailableException e) {
+                    // device is obviously not available...
+                }
+            }
+            if (aInfos.length == 0) {
+                out("No devices available. Test should be run on systems with MIDI drivers installed.");
+            } else {
+                if (outOnlyCount>1) {
+                    if (inOnlyCount==0) {
+                        //throw new Exception("No input devices! test fails.");
+                        out("System provides out devices, but no input devices. This means either");
+                        out("a bug in Java Sound, or the drivers are not set up correctly.");
+                    }
+                    out("Test passed.");
+                } else {
+                    out("no MIDI I/O installed. Test should be run on systems with MIDI drivers installed.");
+                }
+            }
+        } else {
+            out("  -- not on Windows. Test doesn't apply.");
+        }
+    }
+
+    static void out(String s) {
+        System.out.println(s); System.out.flush();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Devices/MidiOutGetMicrosecondPositionBug.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.Synthesizer;
+
+/**
+ * @test
+ * @bug 4903786
+ * @summary MIDI OUT does not implement getMicrosecondPosition() consistently
+ */
+public class MidiOutGetMicrosecondPositionBug {
+    static int successfulTests = 0;
+
+    private static void testDevice(MidiDevice device) throws Exception {
+        boolean timestampsAvailable = false;
+        boolean timestampPrecisionOk = false;
+        try {
+            // expected behaviour if not opened?
+            device.open();
+            /* First, we're testing if timestamps are provided at all.
+               Returning -1 (unsupported), while allowed by the API
+               specification, is not sufficient to pass this test. */
+            long timestamp = device.getMicrosecondPosition();
+            timestampsAvailable = (timestamp != -1);
+
+            /* Then, we're testing the precision. Note that the system time
+               is measured in milliseconds, while the device time is measured
+               in microseconds. */
+
+            long systemTime1 = System.currentTimeMillis();
+            long deviceTime1 = device.getMicrosecondPosition();
+            // rest for 5 seconds
+            Thread.sleep(5000);
+            long systemTime2 = System.currentTimeMillis();
+            long deviceTime2 = device.getMicrosecondPosition();
+
+            // now both period measurements are calculated in milliseconds.
+            long systemDuration = systemTime2 - systemTime1;
+            long deviceDuration = (deviceTime2 - deviceTime1) / 1000;
+            long delta = Math.abs(systemDuration - deviceDuration);
+            // a deviation of 0.5 seconds (= 500 ms) is allowed.
+            timestampPrecisionOk = (delta <= 500);
+        } catch (Throwable t) {
+            System.out.println("  - Caught exception. Not failed.");
+            System.out.println("  - " + t.toString());
+            return;
+        } finally {
+            device.close();
+        }
+        if (! timestampsAvailable) {
+            throw new Exception("timestamps are not supported");
+        }
+        if (! timestampPrecisionOk) {
+            throw new Exception("device timer not precise enough");
+        }
+        successfulTests++;
+    }
+
+    private static void doAll() throws Exception {
+        MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
+        for (int i=0; i < infos.length; i++) {
+            MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
+            if ((! (device instanceof Sequencer)) &&
+                (! (device instanceof Synthesizer)) &&
+                (device.getMaxReceivers() > 0 || device.getMaxReceivers() == -1)) {
+
+                System.out.println("--------------");
+                System.out.println("Testing MIDI device: " + infos[i]);
+                testDevice(device);
+            }
+            if (infos.length==0) {
+                System.out.println("No MIDI devices available!");
+            }
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        if (!isMidiInstalled()) {
+            return;
+        }
+        doAll();
+        if (successfulTests==0) {
+            System.out.println("Could not execute any of the tests. Test NOT failed.");
+        } else {
+            System.out.println("Test PASSED.");
+        }
+    }
+
+    /**
+     * Returns true if at least one MIDI (port) device is correctly installed on
+     * the system.
+     */
+    public static boolean isMidiInstalled() {
+        boolean result = false;
+        MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
+        for (int i = 0; i < devices.length; i++) {
+            try {
+                MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
+                result = ! (device instanceof Sequencer) && ! (device instanceof Synthesizer);
+            } catch (Exception e1) {
+                System.err.println(e1);
+            }
+            if (result)
+                break;
+        }
+        if (!result) {
+            System.err.println("Soundcard does not exist or sound drivers not installed!");
+            System.err.println("This test requires sound drivers for execution.");
+        }
+        return result;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Devices/OpenClose.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,611 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Receiver;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.Synthesizer;
+import javax.sound.midi.Transmitter;
+
+/**
+ * @test
+ * @bug 4616517
+ * @summary Receiver.send() does not work properly. Tests open/close behaviour
+ *          of MidiDevices. For this test, it is essential that the MidiDevice
+ *          picked from the list of devices (MidiSystem.getMidiDeviceInfo()) is
+ *          the same as the one used by
+ *          MidiSystem.getReceiver()/getTransmitter(). To achieve this, default
+ *          provider properties for Receivers/Transmitters are used.
+ */
+public class OpenClose {
+
+    private static boolean isTestExecuted;
+    private static boolean isTestPassed;
+
+    public static void main(String[] args) throws Exception {
+        boolean failed = false;
+        out("#4616517: Receiver.send() does not work properly");
+        if (!isMidiInstalled()) {
+            out("Soundcard does not exist or sound drivers not installed!");
+            out("This test requires sound drivers for execution.");
+            return;
+        }
+        MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
+        MidiDevice outDevice = null;
+        MidiDevice inDevice = null;
+        for (int i = 0; i < infos.length; i++) {
+            MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
+            if (! (device instanceof Synthesizer) &&
+                ! (device instanceof Sequencer)) {
+                if (device.getMaxReceivers() != 0) {
+                    outDevice = device;
+                }
+                if (device.getMaxTransmitters() != 0) {
+                    inDevice = device;
+                }
+            }
+        }
+        if (outDevice != null) {
+            // set the default provider properties
+            System.setProperty(Receiver.class.getName(),
+                               "#" + outDevice.getDeviceInfo().getName());
+        }
+        if (inDevice != null) {
+            System.setProperty(Transmitter.class.getName(),
+                               "#" + inDevice.getDeviceInfo().getName());
+        }
+        out("Using MIDI OUT Device: " + outDevice);
+        out("Using MIDI IN Device: " + inDevice);
+
+        isTestExecuted = false;
+        if (outDevice != null) {
+            isTestExecuted = true;
+            TestHelper testHelper = new ReceiverTestHelper(outDevice);
+            try {
+                doTest("Receiver", testHelper);
+                failed |= testHelper.hasFailed();
+            } catch (Exception e) {
+                out("Exception occured, cannot test!");
+                isTestExecuted = false;
+            }
+        }
+
+        if (inDevice != null) {
+            isTestExecuted = true;
+            TestHelper testHelper = new TransmitterTestHelper(inDevice);
+            try {
+                doTest("Transmitter", testHelper);
+                failed |= testHelper.hasFailed();
+            } catch (Exception e) {
+                out("Exception occured, cannot test!");
+                isTestExecuted = false;
+            }
+        }
+
+        isTestPassed = ! failed;
+
+        if (isTestExecuted) {
+            if (isTestPassed) {
+                out("Test PASSED.");
+            } else {
+                throw new Exception("Test FAILED.");
+            }
+        } else {
+            out("Test NOT FAILED");
+        }
+    }
+
+    private static void doTest(String type,
+                               TestHelper testHelper) throws Exception {
+        /* Case 1:
+           - MidiDevice.open()
+           - MidiDevice.close()
+        */
+        out("checking " + type + " case 1...");
+        testHelper.checkClosed();
+
+        testHelper.openDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeDevice();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 2a:
+           - MidiSystem.get[Receiver|Transmitter]()
+           - [Receiver|Transmitter].close()
+        */
+        out("checking " + type + " case 2a...");
+        testHelper.checkClosed();
+
+        testHelper.fetchObjectMidiSystem();
+        testHelper.checkOpen();
+
+        testHelper.closeObjectMidiSystem();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 2b:
+           - MidiDevice.get[Receiver|Transmitter]()
+           - [Receiver|Transmitter].close()
+        */
+        out("checking " + type + " case 2b...");
+        testHelper.checkClosed();
+
+        testHelper.fetchObjectDevice();
+        testHelper.checkClosed();
+
+        testHelper.closeObjectDevice();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 3a:
+           - MidiSystem.get[Receiver|Transmitter]()
+           - MidiDevice.open()
+           - MidiDevice.close()
+           - [Receiver|Transmitter].close()
+        */
+        out("checking " + type + " case 3a...");
+        testHelper.checkClosed();
+
+        testHelper.fetchObjectMidiSystem();
+        testHelper.checkOpen();
+
+        testHelper.openDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeDevice();
+        testHelper.checkClosed();
+
+        testHelper.closeObjectMidiSystem();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 3b:
+           - MidiDevice.get[Receiver|Transmitter]()
+           - MidiDevice.open()
+           - MidiDevice.close()
+           - [Receiver|Transmitter].close()
+        */
+        out("checking " + type + " case 3b...");
+        testHelper.checkClosed();
+
+        testHelper.fetchObjectDevice();
+        testHelper.checkClosed();
+
+        testHelper.openDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeDevice();
+        testHelper.checkClosed();
+
+        testHelper.closeObjectDevice();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 4a:
+           - MidiSystem.get[Receiver|Transmitter]()
+           - MidiDevice.open()
+           - [Receiver|Transmitter].close()
+           - MidiDevice.close()
+        */
+        out("checking " + type + " case 4a...");
+        testHelper.checkClosed();
+
+        testHelper.fetchObjectMidiSystem();
+        testHelper.checkOpen();
+
+        testHelper.openDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeObjectMidiSystem();
+        testHelper.checkOpen();
+
+        testHelper.closeDevice();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 4b:
+           - MidiDevice.get[Receiver|Transmitter]()
+           - MidiDevice.open()
+           - [Receiver|Transmitter].close()
+           - MidiDevice.close()
+        */
+        out("checking " + type + " case 4b...");
+        testHelper.checkClosed();
+
+        testHelper.fetchObjectDevice();
+        testHelper.checkClosed();
+
+        testHelper.openDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeObjectDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeDevice();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 5a:
+           - MidiDevice.open()
+           - MidiSystem.get[Receiver|Transmitter]()
+           - MidiDevice.close()
+           - [Receiver|Transmitter].close()
+        */
+        out("checking " + type + " case 5a...");
+        testHelper.checkClosed();
+
+        testHelper.openDevice();
+        testHelper.checkOpen();
+
+        testHelper.fetchObjectMidiSystem();
+        testHelper.checkOpen();
+
+        testHelper.closeDevice();
+        testHelper.checkClosed();
+
+        testHelper.closeObjectMidiSystem();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 5b:
+           - MidiDevice.open()
+           - MidiDevice.get[Receiver|Transmitter]()
+           - MidiDevice.close()
+           - [Receiver|Transmitter].close()
+        */
+        out("checking " + type + " case 5b...");
+        testHelper.checkClosed();
+
+        testHelper.openDevice();
+        testHelper.checkOpen();
+
+        testHelper.fetchObjectDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeDevice();
+        testHelper.checkClosed();
+
+        testHelper.closeObjectDevice();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 6a:
+           - MidiDevice.open()
+           - MidiSystem.get[Receiver|Transmitter]()
+           - [Receiver|Transmitter].close()
+           - MidiDevice.close()
+        */
+        out("checking " + type + " case 6a...");
+        testHelper.checkClosed();
+
+        testHelper.openDevice();
+        testHelper.checkOpen();
+
+        testHelper.fetchObjectMidiSystem();
+        testHelper.checkOpen();
+
+        testHelper.closeObjectMidiSystem();
+        testHelper.checkOpen();
+
+        testHelper.closeDevice();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 6b:
+           - MidiDevice.open()
+           - MidiDevice.get[Receiver|Transmitter]()
+           - [Receiver|Transmitter].close()
+           - MidiDevice.close()
+        */
+        out("checking " + type + " case 6b...");
+        testHelper.checkClosed();
+
+        testHelper.openDevice();
+        testHelper.checkOpen();
+
+        testHelper.fetchObjectDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeObjectDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeDevice();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 7:
+           - MidiSystem.get[Receiver|Transmitter]() // 1
+           - MidiDevice.get[Receiver|Transmitter]() // 2
+           - [Receiver|Transmitter].close() // 2
+           - [Receiver|Transmitter].close() // 1
+        */
+        out("checking " + type + " case 7...");
+        testHelper.checkClosed();
+
+        testHelper.fetchObjectMidiSystem();
+        testHelper.checkOpen();
+
+        testHelper.fetchObjectDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeObjectDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeObjectMidiSystem();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 8:
+           - MidiSystem.get[Receiver|Transmitter]() // 1
+           - MidiDevice.get[Receiver|Transmitter]() // 2
+           - [Receiver|Transmitter].close() // 1
+           - [Receiver|Transmitter].close() // 2
+        */
+        out("checking " + type + " case 8...");
+        testHelper.checkClosed();
+
+        testHelper.fetchObjectMidiSystem();
+        testHelper.checkOpen();
+
+        testHelper.fetchObjectDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeObjectMidiSystem();
+        testHelper.checkClosed();
+
+        testHelper.closeObjectDevice();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 9:
+           - MidiDevice.get[Receiver|Transmitter]() // 2
+           - MidiSystem.get[Receiver|Transmitter]() // 1
+           - [Receiver|Transmitter].close() // 2
+           - [Receiver|Transmitter].close() // 1
+        */
+        out("checking " + type + " case 9...");
+        testHelper.checkClosed();
+
+        testHelper.fetchObjectDevice();
+        testHelper.checkClosed();
+
+        testHelper.fetchObjectMidiSystem();
+        testHelper.checkOpen();
+
+        testHelper.closeObjectDevice();
+        testHelper.checkOpen();
+
+        testHelper.closeObjectMidiSystem();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case 10:
+           - MidiDevice.get[Receiver|Transmitter]() // 2
+           - MidiSystem.get[Receiver|Transmitter]() // 1
+           - [Receiver|Transmitter].close() // 1
+           - [Receiver|Transmitter].close() // 2
+        */
+        out("checking " + type + " case 10...");
+        testHelper.checkClosed();
+
+        testHelper.fetchObjectDevice();
+        testHelper.checkClosed();
+
+        testHelper.fetchObjectMidiSystem();
+        testHelper.checkOpen();
+
+        testHelper.closeObjectMidiSystem();
+        testHelper.checkClosed();
+
+        testHelper.closeObjectDevice();
+        testHelper.checkClosed();
+
+        out("...OK");
+
+        /* Case N - 1:
+           - 10 x MidiSystem.get[Receiver|Transmitter]()
+           - 10 x [Receiver|Transmitter].close()
+        */
+        out("checking " + type + " case N - 1...");
+        TestHelper[] testHelpers = new TestHelper[10];
+        for (int i = 0; i < 10; i++) {
+            testHelpers[i] = (TestHelper) testHelper.clone();
+        }
+        testHelper.checkClosed();
+
+        for (int i = 0; i < 10; i++) {
+            testHelpers[i].fetchObjectMidiSystem();
+            testHelper.checkOpen();
+        }
+
+
+        for (int i = 0; i < 9; i++) {
+            testHelpers[i].closeObjectMidiSystem();
+            testHelper.checkOpen();
+        }
+
+        testHelpers[9].closeObjectMidiSystem();
+        testHelper.checkClosed();
+
+        out("...OK");
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+
+    private static abstract class TestHelper implements Cloneable {
+        private MidiDevice device;
+        private boolean failed;
+
+        protected TestHelper(MidiDevice device) {
+            this.device = device;
+            failed = false;
+        }
+
+        protected MidiDevice getDevice() {
+            return device;
+        }
+
+        public boolean hasFailed() {
+            return failed;
+        }
+
+        public void openDevice() throws MidiUnavailableException {
+            getDevice().open();
+        }
+
+        public void closeDevice() {
+            getDevice().close();
+        }
+
+        public void checkOpen(){
+            checkOpen(getDevice(), true);
+        }
+
+        public void checkClosed(){
+            checkOpen(getDevice(), false);
+        }
+
+        private void checkOpen(MidiDevice device, boolean desiredState) {
+            if (device.isOpen() != desiredState) {
+                out("device should be " +
+                                    getStateString(desiredState) + ", but isn't!");
+                failed = true;
+            }
+        }
+
+
+        private String getStateString(boolean state) {
+            return state ? "open" : "closed";
+        }
+
+
+        public abstract void fetchObjectMidiSystem() throws MidiUnavailableException;
+        public abstract void fetchObjectDevice() throws MidiUnavailableException;
+        public abstract void closeObjectMidiSystem();
+        public abstract void closeObjectDevice();
+
+        public Object clone() {
+            try {
+                return super.clone();
+            } catch (CloneNotSupportedException e) {
+                return null;
+            }
+        }
+    }
+
+    private static class ReceiverTestHelper extends TestHelper {
+        private Receiver receiverMidiSystem;
+        private Receiver receiverDevice;
+
+        public ReceiverTestHelper(MidiDevice device) {
+            super(device);
+        }
+
+        public void fetchObjectMidiSystem() throws MidiUnavailableException {
+            receiverMidiSystem = MidiSystem.getReceiver();
+        }
+
+
+        public void fetchObjectDevice() throws MidiUnavailableException {
+            receiverDevice = getDevice().getReceiver();
+        }
+
+
+        public void closeObjectMidiSystem() {
+            receiverMidiSystem.close();
+        }
+
+
+        public void closeObjectDevice() {
+            receiverDevice.close();
+        }
+    }
+
+    private static class TransmitterTestHelper extends TestHelper {
+        private Transmitter transmitterMidiSystem;
+        private Transmitter transmitterDevice;
+
+        public TransmitterTestHelper(MidiDevice device) {
+            super(device);
+        }
+
+        public void fetchObjectMidiSystem() throws MidiUnavailableException {
+            transmitterMidiSystem = MidiSystem.getTransmitter();
+        }
+
+
+        public void fetchObjectDevice() throws MidiUnavailableException {
+            transmitterDevice = getDevice().getTransmitter();
+        }
+
+
+        public void closeObjectMidiSystem() {
+            transmitterMidiSystem.close();
+        }
+
+
+        public void closeObjectDevice() {
+            transmitterDevice.close();
+        }
+    }
+
+    /**
+     * Returns true if at least one MIDI (port) device is correctly installed on
+     * the system.
+     */
+    public static boolean isMidiInstalled() {
+        boolean result = false;
+        MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
+        for (int i = 0; i < devices.length; i++) {
+            try {
+                MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
+                result = ! (device instanceof Sequencer) && ! (device instanceof Synthesizer);
+            } catch (Exception e1) {
+                System.err.println(e1);
+            }
+            if (result)
+                break;
+        }
+        return result;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Devices/ReceiverTransmitterAvailable.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Receiver;
+import javax.sound.midi.Transmitter;
+
+/**
+ * @test
+ * @bug 4616517
+ * @summary Receiver.send() does not work properly
+ */
+public class ReceiverTransmitterAvailable {
+
+    private static boolean isTestExecuted;
+    private static boolean isTestPassed;
+
+    public static void main(String[] args) throws Exception {
+        out("#4616517: Receiver.send() does not work properly");
+        doAllTests();
+        if (isTestExecuted) {
+            if (isTestPassed) {
+                out("Test PASSED.");
+            } else {
+                throw new Exception("Test FAILED.");
+            }
+        } else {
+            out("Test NOT FAILED");
+        }
+    }
+
+    private static void doAllTests() {
+        boolean problemOccured = false;
+        boolean succeeded = true;
+        MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
+        for (int i = 0; i < infos.length; i++) {
+            MidiDevice device = null;
+            try {
+                device = MidiSystem.getMidiDevice(infos[i]);
+                succeeded &= doTest(device);
+            } catch (MidiUnavailableException e) {
+                out("exception occured; cannot test");
+                problemOccured = true;
+            }
+        }
+        if (infos.length == 0) {
+            out("Soundcard does not exist or sound drivers not installed!");
+            out("This test requires sound drivers for execution.");
+        }
+        isTestExecuted = !problemOccured;
+        isTestPassed = succeeded;
+    }
+
+    private static boolean doTest(MidiDevice device) {
+        boolean succeeded = true;
+        out("Testing: " + device);
+        boolean expectingReceivers = (device.getMaxReceivers() != 0);
+        boolean expectingTransmitters = (device.getMaxTransmitters() != 0);
+        try {
+            Receiver rec = device.getReceiver();
+            rec.close();
+            if (! expectingReceivers) {
+                out("no exception on getting Receiver");
+                succeeded = false;
+            }
+        } catch (MidiUnavailableException e) {
+            if (expectingReceivers) {
+                out("Exception on getting Receiver: " + e);
+                succeeded = false;
+            }
+        }
+        try {
+            Transmitter trans = device.getTransmitter();
+            trans.close();
+            if (! expectingTransmitters) {
+                out("no exception on getting Transmitter");
+                succeeded = false;
+            }
+        } catch (MidiUnavailableException e) {
+            if (expectingTransmitters) {
+                out("Exception on getting Transmitter: " + e);
+                succeeded = false;
+            }
+        }
+        return succeeded;
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Devices/Reopen.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.Synthesizer;
+
+/**
+ * @test
+ * @bug 4914667
+ * @summary Closing and reopening MIDI IN device on Linux throws
+ *          MidiUnavailableException
+ */
+public class Reopen {
+
+    private static boolean isTestExecuted;
+    private static boolean isTestPassed;
+
+    /*
+     * run manually:
+     * java Reopen 100 in      for 100 iterations on the MIDI IN device
+     * java Reopen 16 out      for 16 iterations on the MIDI OUT device
+     */
+    public static void main(String[] args) throws Exception {
+        if (args.length == 0) {
+            doAllTests();
+        } else if (args.length == 2) {
+            int numIterations = Integer.parseInt(args[0]);
+            if (args[1].equals("in")) {
+                doTest(numIterations, true);
+            } else {
+                doTest(numIterations, false);
+            }
+        } else {
+            out("usage: java Reopen <iterations> in|out");
+        }
+    }
+
+    private static void doAllTests() throws Exception {
+        out("#4914667: Closing and reopening MIDI IN device on Linux throws MidiUnavailableException");
+        boolean success = true;
+        try {
+            success &= doTest(20, true); // MIDI IN
+            success &= doTest(20, false); // MIDI OUT
+            isTestExecuted = true;
+        } catch (Exception e) {
+            out(e);
+            isTestExecuted = false;
+        }
+        isTestPassed = success;
+        if (isTestExecuted) {
+            if (isTestPassed) {
+                out("Test PASSED.");
+            } else {
+                throw new Exception("Test FAILED.");
+            }
+        } else {
+            out("Test NOT FAILED");
+        }
+    }
+
+    private static boolean doTest(int numIterations, boolean input) throws Exception {
+        MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
+        MidiDevice outDevice = null;
+        MidiDevice inDevice = null;
+        for (int i = 0; i < infos.length; i++) {
+            MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
+            if (! (device instanceof Sequencer) &&
+                ! (device instanceof Synthesizer)) {
+                if (device.getMaxReceivers() != 0) {
+                    outDevice = device;
+                }
+                if (device.getMaxTransmitters() != 0) {
+                    inDevice = device;
+                }
+            }
+        }
+        MidiDevice testDevice = null;
+        if (input) {
+            testDevice = inDevice;
+        } else {
+            testDevice = outDevice;
+        }
+        if (testDevice == null) {
+            out("Cannot test: device not available.");
+            return true;
+        }
+        out("Using Device: " + testDevice);
+
+        for (int i = 0; i < numIterations; i++) {
+            out("@@@ ITERATION: " + i);
+            testDevice.open();
+            // This sleep ensures that the thread of MidiInDevice is started.
+            sleep(50);
+            testDevice.close();
+        }
+        return true;
+    }
+
+    private static void sleep(int milliseconds) {
+        try {
+            Thread.sleep(milliseconds);
+        } catch (InterruptedException e) {
+        }
+    }
+
+    private static void out(Throwable t) {
+        t.printStackTrace(System.out);
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/File/SMFCp037.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+
+import javax.sound.midi.MidiSystem;
+
+/**
+ * @test
+ * @bug 4303933
+ * @summary MidiSystem fails to load MIDI file on systems with EBCDIC simulation
+ */
+public class SMFCp037 {
+
+    public static void main(String args[]) throws Exception {
+        // Test to read MIDI files with Cp037 character set - close enough
+        // for EBCDIC simulation
+        System.setProperty("file.encoding", "Cp037");
+        // try to read this file with Cp037 encoding
+        MidiSystem.getSequence(new ByteArrayInputStream(SHORT_SMF));
+        System.out.println("  test passed.");
+    }
+
+public static byte[] SHORT_SMF = {
+        77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 2, 0, 120, 77, 84, 114, 107, 0, 0,
+        0, 27, 0, -1, 3, 19, 77, 73, 68, 73, 32, 116, 101, 115, 116, 32, 45, 32,
+        116, 114, 97, 99, 107, 32, 48, 0, -1, 47, 0, 77, 84, 114, 107, 0, 0, 0, -44,
+        0, -1, 3, 19, 77, 73, 68, 73, 32, 116, 101, 115, 116, 32, 45, 32, 116, 114,
+        97, 99, 107, 32, 49, 0, -64, 30, 0, -112, 68, 126, 0, -32, 6, 67, 0, 14,
+        71, 0, 20, 74, 0, 26, 77, 0, 32, 80, 0, 42, 85, 6, 50, 89, 6, 56, 92, 5,
+        66, 97, 6, 74, 101, 6, 80, 104, 11, 84, 106, 20, 76, 102, 6, 70, 99, 5, 60,
+        94, 6, 52, 90, 5, 44, 86, 4, 34, 81, 5, 26, 77, 5, 20, 74, 6, 10, 69, 5,
+        2, 65, 7, 0, 64, 42, -112, 66, 123, 11, 68, 0, 72, 63, 126, 4, 66, 0, 43,
+        -32, 0, 63, 6, 0, 60, 7, 0, 56, 6, 0, 53, 5, 0, 49, 5, 0, 43, 4, 0, 37, 3,
+        0, 30, 3, 0, 25, 3, 0, 19, 3, 0, 13, 4, 0, 8, 4, 0, 2, 4, 0, 0, 70, 0, 3,
+        5, 0, 9, 3, 0, 14, 7, 0, 16, 25, 0, 21, 5, 0, 25, 7, 0, 28, 5, 0, 32, 5,
+        0, 36, 5, 0, 41, 6, 0, 46, 5, 0, 50, 5, 0, 53, 4, 0, 58, 7, 0, 61, 7, 0,
+        64, 117, -112, 63, 0, 0, -1, 47, 0
+    };
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/File/SMFParserBreak.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequence;
+
+/**
+ * @test
+ * @bug 4910986
+ * @summary MIDI file parser breaks up on http connection
+ */
+public class SMFParserBreak {
+
+    public static void main(String[] args) throws Exception {
+
+        InputStream is = new ByteArrayInputStream(midifile);
+        // create a buffered input stream that seems
+        // to be on an unfortunate boundary for the
+        // 1.4.2 SMF parser implementation
+        is = new ChunkInputStream(is, 32);
+        Sequence sequence = MidiSystem.getSequence(is);
+
+        long duration = sequence.getMicrosecondLength() / 10000;
+        System.out.println("Duration: "+duration+" deciseconds ");
+
+        // the test is passed if no exception thrown
+        System.out.println("Test passed");
+    }
+
+    // A MIDI file
+    static byte[] midifile = {
+        77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 3, -30, 120, 77, 84, 114, 107, 0,
+        0, 0, 123, 0, -112, 30, 100, -113, 49, -128, 50, 100, -114, 69, -112, 31,
+        100, -114, 33, -128, 51, 100, -114, 55, -112, 32, 100, -114, 120, -128, 52,
+        100, -114, 40, -112, 33, 100, -114, 26, -128, 53, 100, -114, 26, -112, 34,
+        100, -114, 76, -128, 54, 100, -114, 12, -112, 35, 100, -114, 91, -128, 55,
+        100, -114, 69, -112, 36, 100, -114, 33, -128, 56, 100, -114, 55, -112, 37,
+        100, -114, 84, -128, 57, 100, -114, 40, -112, 38, 100, -114, 26, -128, 58,
+        100, -114, 26, -112, 39, 100, -113, 24, -128, 59, 100, -113, 60, -112, 40,
+        100, -113, 110, -128, 60, 100, -113, 96, -112, 41, 100, -113, 39, -128, 61,
+        100, 0, -1, 47, 0, 77, 84, 114, 107, 0, 0, 0, 4, 0, -1, 47, 0, 77, 84, 114,
+        107, 0, 0, 0, 4, 0, -1, 47, 0
+    };
+}
+
+/* an input stream that always returns data in chunks */
+class ChunkInputStream extends FilterInputStream {
+    int chunkSize;
+    int p = 0; // position
+
+    public ChunkInputStream(InputStream is, int chunkSize) {
+        super(is);
+        this.chunkSize = chunkSize;
+    }
+
+    // override to increase counter
+    public int read() throws IOException {
+        int ret = super.read();
+        if (ret >= 0) {
+            p++;
+        }
+        return ret;
+    }
+
+    // override to make sure that read(byte[], int, int) is used
+    public int read(byte[] b) throws IOException {
+        return read(b, 0, b.length);
+    }
+
+    // override to split the data in chunks
+    public int read(byte[] b, int off, int len) throws IOException {
+        // if we would pass a chunk boundary,
+        // only return up to the chunk boundary
+        if ( (p / chunkSize) < ( (p+len) / chunkSize)) {
+            // p+len is in the next chunk
+            len -= ((p+len) % chunkSize);
+        }
+        int ret = super.read(b, off, len);
+        if (ret >= 0) {
+            p += ret;
+        }
+        return ret;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/File/WriteRealTimeMessageNPE.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 5048381
+ * @summary NPE when writing a sequence with a realtime MIDI message
+ */
+public class WriteRealTimeMessageNPE {
+
+    public static void main(String args[]) throws Exception {
+        System.out.println("5048381: NullPointerException when saving a MIDI sequence");
+        boolean npeThrown = false;
+        boolean noEx = false;
+
+        Sequence seq = new Sequence(Sequence.PPQ, 384, 1);
+        Track t = seq.getTracks()[0];
+        ShortMessage msg = new ShortMessage();
+        msg.setMessage(0xF8, 0, 0);
+        t.add(new MidiEvent(msg, 0));
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        try {
+            MidiSystem.write(seq, 0, out);
+            noEx = true;
+        } catch (NullPointerException npe) {
+            npeThrown = true;
+            System.out.println("## Failed: Threw unexpected NPE: "+npe);
+            throw new Exception("Test FAILED!");
+        } catch (Exception e) {
+            System.out.println("Threw unexpected Exception: "+e);
+            System.out.println("But at least did not throw NPE...");
+        }
+        if (noEx) {
+            InputStream is = new ByteArrayInputStream(out.toByteArray());
+            seq = MidiSystem.getSequence(is);
+            System.out.println("Sequence has "+seq.getTracks().length+" tracks.");
+            if (seq.getTracks().length > 0) {
+                System.out.println("Track 0 has "+seq.getTracks()[0].size()+" events.");
+            }
+        }
+        System.out.println("Test passed.");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/MetaMessage/MetaMessageClone.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import  javax.sound.midi.MetaMessage;
+
+/**
+ * @test
+ * @bug 4511796
+ * @summary Check that MetaMessage.clone() works correctly
+ */
+public class MetaMessageClone {
+
+    private static void printMsg(MetaMessage msg, byte[] data) {
+        System.out.println(""+msg.getLength()+" total bytes, type="+msg.getType()+", dataLength="+data.length);
+    }
+
+    private static void checkClone(MetaMessage msg) throws Exception {
+        System.out.print("Original: ");
+        byte[] msgData=msg.getData();
+        printMsg(msg, msgData);
+        MetaMessage msg2=(MetaMessage) msg.clone();
+        byte[] msg2Data=msg2.getData();
+        System.out.print("Clone:    ");
+        printMsg(msg2, msg2Data);
+
+        if (msg2.getLength()!=msg.getLength()
+            || msg.getType()!=msg2.getType()
+            || msgData.length!=msg2Data.length) {
+                throw new Exception("cloned MetaMessage is not equal.");
+        }
+        int max=Math.min(msgData.length, 10);
+        for (int i=0; i<max; i++) {
+            if (msgData[i]!=msg2Data[i]) {
+                throw new Exception("Cloned MetaMessage data is not equal.");
+            }
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        // let's create some MetaMessages and check them
+        MetaMessage msg=new MetaMessage();
+        String text="a textmarker";
+        msg.setMessage(1, text.getBytes(), text.length());
+        checkClone(msg);
+        msg.setMessage(0x2E, new byte[0], 0);
+        checkClone(msg);
+        byte[] data=new byte[17000];
+        for (int i=0; i<30; data[i]=(byte) (i++ & 0xFF));
+        msg.setMessage(0x02, data, 80); checkClone(msg);
+        msg.setMessage(0x02, data, 160); checkClone(msg);
+        msg.setMessage(0x02, data, 400); checkClone(msg);
+        msg.setMessage(0x02, data, 1000); checkClone(msg);
+        msg.setMessage(0x02, data, 10000); checkClone(msg);
+        msg.setMessage(0x02, data, 17000); checkClone(msg);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/MidiSystem/6411624/Test6411624.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,384 @@
+/*
+ * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Button;
+import java.awt.Dialog;
+import java.awt.Frame;
+import java.awt.Panel;
+import java.awt.TextArea;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/**
+ * @test
+ * @bug 6411624
+ * @summary Tests that MidiSystem.getReceiver() & MidiSystem.getTransmitter
+ *          doesn't return sequencer
+ * @build bug6411624
+ * @run main/manual Test6411624
+ */
+public class Test6411624 {
+
+   private static void init() throws Exception {
+        //*** Create instructions for the user here ***
+
+        String[] instructions =
+        {
+         "This test should only be run on solaris or linux system",
+         "WITHOUT audio card installed (to test on SunRay set",
+         "incorrect $AUDIODEV value).",
+         "If you system does not meet this conditions, press PASS.",
+         "To run the test follow these instructions:",
+         "1. Open a terminal window.",
+         "2. Type \"cd " + System.getProperty("test.classes") + "\".",
+         "3. Type \"" + System.getProperty("java.home") + "/bin/java bug6411624\".",
+         "4. Follow the instructions shown in the terminal window.",
+         "If you see \"All tests sucessfully passed\", press PASS else press FAIL."
+       };
+
+      Sysout.createDialog( );
+      Sysout.printInstructions( instructions );
+
+    }
+
+ /*****************************************************
+     Standard Test Machinery Section
+      DO NOT modify anything in this section -- it's a
+      standard chunk of code which has all of the
+      synchronisation necessary for the test harness.
+      By keeping it the same in all tests, it is easier
+      to read and understand someone else's test, as
+      well as insuring that all tests behave correctly
+      with the test harness.
+     There is a section following this for test-defined
+      classes
+   ******************************************************/
+   private static boolean theTestPassed = false;
+   private static boolean testGeneratedInterrupt = false;
+   private static String failureMessage = "";
+
+   private static Thread mainThread = null;
+
+   private static int sleepTime = 300000;
+
+   public static void main( String args[] ) throws Exception
+    {
+      mainThread = Thread.currentThread();
+      try
+       {
+         init();
+       }
+      catch( TestPassedException e )
+       {
+         //The test passed, so just return from main and harness will
+         // interepret this return as a pass
+         return;
+       }
+      //At this point, neither test passed nor test failed has been
+      // called -- either would have thrown an exception and ended the
+      // test, so we know we have multiple threads.
+
+      //Test involves other threads, so sleep and wait for them to
+      // called pass() or fail()
+      try
+       {
+         Thread.sleep( sleepTime );
+         //Timed out, so fail the test
+         throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
+       }
+      catch (InterruptedException e)
+       {
+         if( ! testGeneratedInterrupt ) throw e;
+
+         //reset flag in case hit this code more than once for some reason (just safety)
+         testGeneratedInterrupt = false;
+         if ( theTestPassed == false )
+          {
+            throw new RuntimeException( failureMessage );
+          }
+       }
+
+    }//main
+
+   public static synchronized void setTimeoutTo( int seconds )
+    {
+      sleepTime = seconds * 1000;
+    }
+
+   public static synchronized void pass()
+    {
+      Sysout.println( "The test passed." );
+      Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
+      //first check if this is executing in main thread
+      if ( mainThread == Thread.currentThread() )
+       {
+         //Still in the main thread, so set the flag just for kicks,
+         // and throw a test passed exception which will be caught
+         // and end the test.
+         theTestPassed = true;
+         throw new TestPassedException();
+       }
+      //pass was called from a different thread, so set the flag and interrupt
+      // the main thead.
+      theTestPassed = true;
+      testGeneratedInterrupt = true;
+      mainThread.interrupt();
+    }//pass()
+
+   public static synchronized void fail()
+    {
+      //test writer didn't specify why test failed, so give generic
+      fail( "it just plain failed! :-)" );
+    }
+
+   public static synchronized void fail( String whyFailed )
+    {
+      Sysout.println( "The test failed: " + whyFailed );
+      Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
+      //check if this called from main thread
+      if ( mainThread == Thread.currentThread() )
+       {
+         //If main thread, fail now 'cause not sleeping
+         throw new RuntimeException( whyFailed );
+       }
+      theTestPassed = false;
+      testGeneratedInterrupt = true;
+      failureMessage = whyFailed;
+      mainThread.interrupt();
+    }//fail()
+
+ }// class Orient
+
+//This exception is used to exit from any level of call nesting
+// when it's determined that the test has passed, and immediately
+// end the test.
+class TestPassedException extends RuntimeException
+ {
+ }
+
+//*********** End Standard Test Machinery Section **********
+
+
+//************ Begin classes defined for the test ****************
+
+// make listeners in a class defined here, and instantiate them in init()
+
+/* Example of a class which may be written as part of a test
+class NewClass implements anInterface
+ {
+   static int newVar = 0;
+
+   public void eventDispatched(AWTEvent e)
+    {
+      //Counting events to see if we get enough
+      eventCount++;
+
+      if( eventCount == 20 )
+       {
+         //got enough events, so pass
+
+         Orient.pass();
+       }
+      else if( tries == 20 )
+       {
+         //tried too many times without getting enough events so fail
+
+         Orient.fail();
+       }
+
+    }// eventDispatched()
+
+ }// NewClass class
+
+*/
+
+
+//************** End classes defined for the test *******************
+
+
+
+
+/****************************************************
+ Standard Test Machinery
+ DO NOT modify anything below -- it's a standard
+  chunk of code whose purpose is to make user
+  interaction uniform, and thereby make it simpler
+  to read and understand someone else's test.
+ ****************************************************/
+
+/**
+ This is part of the standard test machinery.
+ It creates a dialog (with the instructions), and is the interface
+  for sending text messages to the user.
+ To print the instructions, send an array of strings to Sysout.createDialog
+  WithInstructions method.  Put one line of instructions per array entry.
+ To display a message for the tester to see, simply call Sysout.println
+  with the string to be displayed.
+ This mimics System.out.println but works within the test harness as well
+  as standalone.
+ */
+
+class Sysout
+ {
+   private static TestDialog dialog;
+
+   public static void createDialogWithInstructions( String[] instructions )
+    {
+      dialog = new TestDialog( new Frame(), "Instructions" );
+      dialog.printInstructions( instructions );
+      dialog.show();
+      println( "Any messages for the tester will display here." );
+    }
+
+   public static void createDialog( )
+    {
+      dialog = new TestDialog( new Frame(), "Instructions" );
+      String[] defInstr = { "Instructions will appear here. ", "" } ;
+      dialog.printInstructions( defInstr );
+      dialog.show();
+      println( "Any messages for the tester will display here." );
+    }
+
+
+   public static void printInstructions( String[] instructions )
+    {
+      dialog.printInstructions( instructions );
+    }
+
+
+   public static void println( String messageIn )
+    {
+      dialog.displayMessage( messageIn );
+    }
+
+ }// Sysout  class
+
+/**
+  This is part of the standard test machinery.  It provides a place for the
+   test instructions to be displayed, and a place for interactive messages
+   to the user to be displayed.
+  To have the test instructions displayed, see Sysout.
+  To have a message to the user be displayed, see Sysout.
+  Do not call anything in this dialog directly.
+  */
+class TestDialog extends Dialog implements ActionListener
+ {
+
+   TextArea instructionsText;
+   TextArea messageText;
+   int maxStringLength = 80;
+   Panel  buttonP = new Panel();
+   Button passB = new Button( "pass" );
+   Button failB = new Button( "fail" );
+
+   //DO NOT call this directly, go through Sysout
+   public TestDialog( Frame frame, String name )
+    {
+      super( frame, name );
+      int scrollBoth = TextArea.SCROLLBARS_BOTH;
+      instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
+      add( "North", instructionsText );
+
+      messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
+      add("Center", messageText);
+
+      passB = new Button( "pass" );
+      passB.setActionCommand( "pass" );
+      passB.addActionListener( this );
+      buttonP.add( "East", passB );
+
+      failB = new Button( "fail" );
+      failB.setActionCommand( "fail" );
+      failB.addActionListener( this );
+      buttonP.add( "West", failB );
+
+      add( "South", buttonP );
+      pack();
+
+      show();
+    }// TestDialog()
+
+   //DO NOT call this directly, go through Sysout
+   public void printInstructions( String[] instructions )
+    {
+      //Clear out any current instructions
+      instructionsText.setText( "" );
+
+      //Go down array of instruction strings
+
+      String printStr, remainingStr;
+      for( int i=0; i < instructions.length; i++ )
+       {
+         //chop up each into pieces maxSringLength long
+         remainingStr = instructions[ i ];
+         while( remainingStr.length() > 0 )
+          {
+            //if longer than max then chop off first max chars to print
+            if( remainingStr.length() >= maxStringLength )
+             {
+               //Try to chop on a word boundary
+               int posOfSpace = remainingStr.
+                  lastIndexOf( ' ', maxStringLength - 1 );
+
+               if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+
+               printStr = remainingStr.substring( 0, posOfSpace + 1 );
+               remainingStr = remainingStr.substring( posOfSpace + 1 );
+             }
+            //else just print
+            else
+             {
+               printStr = remainingStr;
+               remainingStr = "";
+             }
+
+            instructionsText.append( printStr + "\n" );
+
+          }// while
+
+       }// for
+
+    }//printInstructions()
+
+   //DO NOT call this directly, go through Sysout
+   public void displayMessage( String messageIn )
+    {
+      messageText.append( messageIn + "\n" );
+    }
+
+   //catch presses of the passed and failed buttons.
+   //simply call the standard pass() or fail() static methods of
+   //DialogOrient
+   public void actionPerformed( ActionEvent e )
+    {
+      if( e.getActionCommand() == "pass" )
+       {
+         Test6411624.pass();
+       }
+      else
+       {
+         Test6411624.fail();
+       }
+    }
+
+ }// TestDialog  class
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/MidiSystem/6411624/bug6411624.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Receiver;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.Synthesizer;
+import javax.sound.midi.Transmitter;
+
+/**
+ * This test should be run on specific environment (solaris or linux w/o
+ * audio card installed).
+ */
+public class bug6411624 {
+
+    public static void main(String args[]) throws Exception {
+        log("This test should only be run on solaris or linux system");
+        log("without audio card installed (to test on SunRay set");
+        log("incorrect $AUDIODEV value).");
+        readln();
+
+        boolean testRecv = false;
+        boolean testTrans = false;
+        boolean testSeq = true;
+
+        // print add info (midi device list)
+        try {
+            MidiDevice.Info[] midis = MidiSystem.getMidiDeviceInfo();
+            log("MidiDevices (total " + midis.length + "):");
+            for (int i=0; i<midis.length; i++) {
+                log("" + i + ": " + midis[i].toString());
+//                MidiDevice dev = MidiSystem.getMidiDevice(midis[i]);
+//                log("    device: " + dev);
+            }
+        } catch (Exception ex) {
+            log("!!!EXCEPTION:");
+            ex.printStackTrace();
+        }
+
+        log("");
+        log("getting default receiver...");
+        try {
+            Receiver rec = MidiSystem.getReceiver();
+            log(" - OK: " + rec);
+            testRecv = checkDevice(rec);
+            rec.close();
+        } catch (MidiUnavailableException e) {
+            log("MidiUnavailableException has been thrown - OK");
+            testRecv = true;
+        }
+
+
+        log("");
+        log("getting default transmitter...");
+        try {
+            Transmitter trans = MidiSystem.getTransmitter();
+            log(" - OK: " + trans);
+            testTrans = checkDevice(trans);
+            trans.close();
+        } catch (MidiUnavailableException e) {
+            log("MidiUnavailableException has been thrown - OK");
+            testTrans = true;
+        }
+
+
+        // print default synthesizer
+        log("");
+        log("getting default synth...");
+        try {
+            Synthesizer synth = MidiSystem.getSynthesizer();
+            log(" - OK: " + synth);
+            synth.close();
+        } catch (MidiUnavailableException e) {
+            log("MidiUnavailableException has been thrown - OK:");
+            e.printStackTrace();
+        }
+
+
+        log("");
+        log("getting default sequencer (connected)...");
+        try {
+            Sequencer seq = MidiSystem.getSequencer();
+            log("OK: " + seq);
+
+            // check that returned sequencer doesn't connected to another sequencer
+            log("  receivers:");
+            log("    max=" + seq.getMaxReceivers());
+            List<Receiver> recvList = seq.getReceivers();
+            log("    count=" + recvList.size());
+            Iterator<Receiver> recvIter = recvList.iterator();
+            int i = 0;
+            while (recvIter.hasNext()) {
+                Receiver recv = recvIter.next();
+                log("    " + (++i) + ": " + recv);
+            }
+
+            log("  transmitters:");
+            log("    max=" + seq.getMaxTransmitters());
+            List<Transmitter> transList = seq.getTransmitters();
+            log("    count=" + transList.size());
+            Iterator<Transmitter> transIter = transList.iterator();
+            i = 0;
+            while (transIter.hasNext()) {
+                Transmitter trans = transIter.next();
+                log("    " + (++i) + ": " + trans);
+                Receiver recv = trans.getReceiver();
+                log("      recv: " + recv);
+                if (!checkDevice(recv))
+                    testSeq = false;
+            }
+
+            log("opening sequencer...");
+            seq.open();
+            log("OK.");
+
+            log("closing...");
+            seq.close();
+            log("OK.");
+        } catch (MidiUnavailableException e) {
+            log("MidiUnavailableException has been thrown - OK:");
+            e.printStackTrace();
+        }
+
+
+        // debug testing - non-connected sequencer
+        log("");
+        log("getting default sequencer (non-connected)...");
+        try {
+            Sequencer seq = MidiSystem.getSequencer(false);
+            log("OK: " + seq);
+
+            log("  receivers:");
+            log("    max=" + seq.getMaxReceivers());
+            List<Receiver> recvList = seq.getReceivers();
+            log("    count=" + recvList.size());
+            Iterator<Receiver> recvIter = recvList.iterator();
+            int i = 0;
+            while (recvIter.hasNext()) {
+                Receiver recv = recvIter.next();
+                log("    " + (++i) + ": " + recv);
+            }
+
+            log("  transmitters:");
+            log("    max=" + seq.getMaxTransmitters());
+            List<Transmitter> transList = seq.getTransmitters();
+            log("    count=" + transList.size());
+            Iterator<Transmitter> transIter = transList.iterator();
+            i = 0;
+            while (transIter.hasNext()) {
+                Transmitter trans = transIter.next();
+                log("    " + (++i) + ": " + trans);
+                Receiver recv = trans.getReceiver();
+                log("      recv: " + recv);
+            }
+            seq.close();
+        } catch (MidiUnavailableException e) {
+            log("MidiUnavailableException has been thrown (shouln't?):");
+            e.printStackTrace();
+        }
+
+        log("");
+        log("Test result:");
+        // print results
+        if (testRecv && testTrans && testSeq) {
+            log("  All tests sucessfully passed.");
+        } else {
+            log("  Some tests failed:");
+            log("    receiver test:    " + (testRecv ? "OK" : "FAILED"));
+            log("    transmitter test: " + (testTrans ? "OK" : "FAILED"));
+            log("    sequencer test:   " + (testSeq ? "OK" : "FAILED"));
+        }
+        log("\n\n\n");
+    }
+
+    // check that device is not sequencer
+    static boolean checkDevice(Object dev) {
+        String className = dev.getClass().toString().toLowerCase();
+        boolean result = (className.indexOf("sequencer") < 0);
+        if (!result)
+            log("ERROR: inapropriate device");
+        return result;
+    }
+
+    // helper routines
+    static long startTime = currentTimeMillis();
+    static long currentTimeMillis() {
+        //return System.nanoTime() / 1000000L;
+        return System.currentTimeMillis();
+    }
+    static void log(String s) {
+        long time = currentTimeMillis() - startTime;
+        long ms = time % 1000;
+        time /= 1000;
+        long sec = time % 60;
+        time /= 60;
+        long min = time % 60;
+        time /= 60;
+        System.out.println(""
+                + (time < 10 ? "0" : "") + time
+                + ":" + (min < 10 ? "0" : "") + min
+                + ":" + (sec < 10 ? "0" : "") + sec
+                + "." + (ms < 10 ? "00" : (ms < 100 ? "0" : "")) + ms
+                + " (" + Thread.currentThread().getName() + ") " + s);
+    }
+    static void delay(int millis) {
+        try {
+            Thread.sleep(millis);
+        } catch (InterruptedException e) {}
+    }
+    static void readln() {
+        log("");
+        log("Press ENTER to continue...");
+        try {
+            while (System.in.read() != 10) ;
+        } catch (IOException e) { }
+        log("");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/MidiSystem/DefaultDevices.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.List;
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Receiver;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.Synthesizer;
+import javax.sound.midi.Transmitter;
+import javax.sound.midi.spi.MidiDeviceProvider;
+
+import com.sun.media.sound.JDK13Services;
+
+/**
+ * @test
+ * @bug 4776511
+ * @bug 4934509
+ * @bug 4938236
+ * @modules java.desktop/com.sun.media.sound
+ * @run main/timeout=600 DefaultDevices
+ * @summary RFE: Setting the default MixerProvider
+ */
+/** Test the retrieving of MidiDevices with default device properties.
+ * This is a part of the test for 4776511.
+ * The test also functions as a unit test for 4934509: SPEC: Document
+ * explicitely MidiSystem.getReceiver's behavior
+ * and a regession test for 4938236: Crash when opening synthesizer implicitly
+ * The test has been updated to reflect a fix for 6411624: MidiSystem.getSequencer()
+ * doesn't throw MidiUnavaivableException if no audio card installed (see also
+ * 6422786: regression test javax/sound/midi/MidiSystem/DefaultDevices.java fails)
+ */
+public class DefaultDevices {
+
+    private static final String ERROR_PROVIDER_CLASS_NAME = "abc";
+    private static final String ERROR_INSTANCE_NAME = "def";
+
+    private static final Class RECEIVER_CLASS = javax.sound.midi.Receiver.class;
+    private static final Class TRANSMITTER_CLASS = javax.sound.midi.Transmitter.class;
+    private static final Class SEQUENCER_CLASS = javax.sound.midi.Sequencer.class;
+    private static final Class SYNTHESIZER_CLASS = javax.sound.midi.Synthesizer.class;
+
+    public static void main(String[] args) throws Exception {
+        boolean allOk = true;
+        MidiDevice.Info[] infos;
+
+        out("\nTesting MidiDevices retrieved via MidiSystem");
+        infos = MidiSystem.getMidiDeviceInfo();
+        allOk &= testDevices(infos, null);
+
+        out("\nTesting MidiDevices retrieved from MidiDeviceProviders");
+        List providers = JDK13Services.getProviders(MidiDeviceProvider.class);
+        for (int i = 0; i < providers.size(); i++) {
+            MidiDeviceProvider provider = (MidiDeviceProvider)providers.get(i);
+            infos = provider.getDeviceInfo();
+            allOk &= testDevices(infos, provider.getClass().getName());
+        }
+
+        if (!allOk) {
+            throw new Exception("Test failed");
+        } else {
+            out("Test passed");
+        }
+    }
+
+    private static boolean testDevices(MidiDevice.Info[] infos,
+            String providerClassName) {
+        boolean allOk = true;
+
+        for (int i = 0; i < infos.length; i++) {
+            MidiDevice device = null;
+            try {
+                device = MidiSystem.getMidiDevice(infos[i]);
+            } catch (MidiUnavailableException e) {
+                out("Exception thrown; Test NOT failed.");
+                e.printStackTrace(System.out);
+                out("");
+            }
+            out("\nTesting device: " + device);
+            if (device instanceof Sequencer) {
+                allOk &= testDevice(device, SEQUENCER_CLASS, providerClassName, true, true);
+                // incorrect cases
+                allOk &= testDevice(device, SYNTHESIZER_CLASS, providerClassName, false, false);
+                allOk &= testDevice(device, RECEIVER_CLASS, providerClassName, false, false);
+                allOk &= testDevice(device, TRANSMITTER_CLASS, providerClassName, false, false);
+            }
+            if (device instanceof Synthesizer) {
+                allOk &= testDevice(device, SYNTHESIZER_CLASS, providerClassName, true, true);
+                allOk &= testDevice(device, RECEIVER_CLASS, providerClassName, false, true);
+                // incorrect cases
+                allOk &= testDevice(device, TRANSMITTER_CLASS, providerClassName, false, false);
+                allOk &= testDevice(device, SEQUENCER_CLASS, providerClassName, false, false);
+            }
+            if (device instanceof Receiver) {
+                allOk &= testDevice(device, RECEIVER_CLASS, providerClassName, true, true);
+                // incorrect cases
+                allOk &= testDevice(device, TRANSMITTER_CLASS, providerClassName, false, false);
+                allOk &= testDevice(device, SYNTHESIZER_CLASS, providerClassName, false, false);
+                allOk &= testDevice(device, SEQUENCER_CLASS, providerClassName, false, false);
+            }
+            if (device instanceof Transmitter) {
+                allOk &= testDevice(device, TRANSMITTER_CLASS, providerClassName, true, true);
+                // incorrect cases
+                allOk &= testDevice(device, RECEIVER_CLASS, providerClassName, false, false);
+                allOk &= testDevice(device, SYNTHESIZER_CLASS, providerClassName, false, false);
+                allOk &= testDevice(device, SEQUENCER_CLASS, providerClassName, false, false);
+            }
+        }
+        return allOk;
+    }
+
+    private static boolean testDevice(MidiDevice device, Class type,
+            String providerClassName, boolean testWrong, boolean expectedResult) {
+        boolean allOk = true;
+        String instanceName = device.getDeviceInfo().getName();
+
+        // no error
+        allOk &= testDevice(device, type, providerClassName,
+                            instanceName, expectedResult);
+
+        if (testWrong) {
+            // erroneous provider class name, correct instance name
+            allOk &= testDevice(device, type, ERROR_PROVIDER_CLASS_NAME,
+                                instanceName, expectedResult);
+
+            // correct provider class name, erroneous instance name
+            // we presume that provider provides only one class of requested type
+            allOk &= testDevice(device, type, providerClassName,
+                                ERROR_INSTANCE_NAME, expectedResult);
+        }
+
+        return allOk;
+    }
+
+    private static boolean testDevice(MidiDevice device, Class type,
+            String providerClassName, String instanceName,
+            boolean expectedResult) {
+        boolean allOk = true;
+
+        try {
+            String propertyName = type.getName();
+            String propertyValue = (providerClassName != null) ? providerClassName: "" ;
+            propertyValue += "#" + instanceName;
+            out("property: " + propertyName + "="+ propertyValue);
+            System.setProperty(propertyName, propertyValue);
+            Object reference = null;
+            Object result = null;
+            if (type == SEQUENCER_CLASS) {
+                reference = device;
+                result = MidiSystem.getSequencer();
+            } else if (type == SYNTHESIZER_CLASS) {
+                reference = device;
+                result = MidiSystem.getSynthesizer();
+            } else if (type == RECEIVER_CLASS) {
+                reference = device.getReceiver();
+                result = MidiSystem.getReceiver();
+            } else if (type == TRANSMITTER_CLASS) {
+                reference = device.getTransmitter();
+                result = MidiSystem.getTransmitter();
+            }
+            out("result: " + result);
+            boolean rightDevice = (reference.getClass() == result.getClass());
+            if (rightDevice != expectedResult) {
+                out("\nERROR: type " + type + " failed:"
+                        + " class should" + (expectedResult ? "" : " NOT") + " be '"
+                        + reference.getClass()
+                        + "' but is '" + result.getClass() + "'!\n");
+                allOk = false;
+            }
+            if (expectedResult
+                    && reference instanceof MidiDevice
+                    && result instanceof MidiDevice) {
+                MidiDevice referenceDevice = (MidiDevice)reference;
+                MidiDevice resultDevice = (MidiDevice)result;
+                if (!referenceDevice.getDeviceInfo().getName().equals(
+                                    resultDevice.getDeviceInfo().getName())) {
+                    out("\nERROR: type " + type + " failed: name should be '"
+                            + referenceDevice.getDeviceInfo().getName()
+                            + "' but is '"
+                            + resultDevice.getDeviceInfo().getName() + "'!\n");
+                    allOk = false;
+                }
+            }
+            if (result instanceof Receiver) {
+                ((Receiver)result).close();
+            } else if (result instanceof Transmitter) {
+                ((Transmitter)result).close();
+            } else if (result instanceof Synthesizer) {
+                ((Synthesizer)result).close();
+            } else if (result instanceof Sequencer) {
+                ((Sequencer)result).close();
+            }
+        } catch (Exception e) {
+            out("Exception thrown; Test NOT failed.");
+            e.printStackTrace(System.out);
+            out("");
+        }
+        return allOk;
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/MidiSystem/DefaultProperties.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+
+import com.sun.media.sound.JDK13Services;
+
+/**
+ * @test
+ * @bug 4776511
+ * @summary RFE: Setting the default MixerProvider. Test the retrieving and
+ *          parsing of properties. This is a part of the test for 4776511.
+ * @run main/othervm DefaultProperties
+ * @modules java.desktop/com.sun.media.sound
+ */
+public class DefaultProperties {
+
+    private static final Class[] lineTypeClasses = {
+        javax.sound.midi.Receiver.class,
+        javax.sound.midi.Transmitter.class,
+        javax.sound.midi.Sequencer.class,
+        javax.sound.midi.Synthesizer.class,
+    };
+
+    public static void main(String[] args) throws Exception {
+        boolean allOk = true;
+        File file = new File(System.getProperty("test.src", "."), "testdata");
+        System.setProperty("java.home", file.getCanonicalPath());
+
+        for (int i = 0; i < lineTypeClasses.length; i++) {
+            Class cls = lineTypeClasses[i];
+            String propertyName = cls.getName();
+            String result;
+            String provClassName;
+            String instanceName;
+
+            // properties file, both provider class name and instance name
+            provClassName = "xyz";
+            instanceName = "123";
+            result = JDK13Services.getDefaultProviderClassName(cls);
+            if (! provClassName.equals(result)) {
+                out("type " + cls + " failed: provider class should be '" +
+                    provClassName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+            result = JDK13Services.getDefaultInstanceName(cls);
+            if (! instanceName.equals(result)) {
+                out("type " + cls + " failed: instance name should be '" +
+                    instanceName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+
+            // system property, provider class name only, no trailing hash
+            provClassName = "abc";
+            System.setProperty(propertyName, provClassName);
+            result = JDK13Services.getDefaultProviderClassName(cls);
+            if (! provClassName.equals(result)) {
+                out("type " + cls + " failed: provider class should be '" +
+                    provClassName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+            result = JDK13Services.getDefaultInstanceName(cls);
+            if (result != null) {
+                out("type " + cls + " failed: instance name should be " +
+                    "null but is '" + result + "'!");
+                allOk = false;
+            }
+
+            // system property, provider class name only, trailing hash
+            provClassName = "def";
+            System.setProperty(propertyName, provClassName + "#");
+            result = JDK13Services.getDefaultProviderClassName(cls);
+            if (! provClassName.equals(result)) {
+                out("type " + cls + " failed: provider class should be '" +
+                    provClassName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+            result = JDK13Services.getDefaultInstanceName(cls);
+            if (result != null) {
+                out("type " + cls + " failed: instance name should be " +
+                    "null but is '" + result + "'!");
+                allOk = false;
+            }
+
+            // system property, instance name only
+            instanceName = "ghi";
+            System.setProperty(propertyName, "#" + instanceName);
+            result = JDK13Services.getDefaultProviderClassName(cls);
+            if (result != null) {
+                out("type " + cls + " failed: provider class should be " +
+                    "null but is '" + result + "'!");
+                allOk = false;
+            }
+            result = JDK13Services.getDefaultInstanceName(cls);
+            if (! instanceName.equals(result)) {
+                out("type " + cls + " failed: instance name should be '" +
+                    instanceName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+
+            // system property, both provider class and instance name
+            provClassName = "jkl";
+            instanceName = "mno";
+            System.setProperty(propertyName, provClassName + "#" + instanceName);
+            result = JDK13Services.getDefaultProviderClassName(cls);
+            if (! provClassName.equals(result)) {
+                out("type " + cls + "failed: provider class should be '" +
+                    provClassName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+            result = JDK13Services.getDefaultInstanceName(cls);
+            if (! instanceName.equals(result)) {
+                out("type " + cls + "failed: instance name should be '" +
+                    instanceName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+
+            // system property, empty
+            System.setProperty(propertyName, "");
+            result = JDK13Services.getDefaultProviderClassName(cls);
+            if (result != null) {
+                out("type " + cls + " failed: provider class should be " +
+                    "null but is '" + result + "'!");
+                allOk = false;
+            }
+            result = JDK13Services.getDefaultInstanceName(cls);
+            if (result != null) {
+                out("type " + cls + "failed: instance name should be " +
+                    "null but is '" + result + "'!");
+                allOk = false;
+            }
+        }
+        if (! allOk) {
+            throw new Exception("Test failed");
+        } else {
+            out("Test passed");
+        }
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/MidiSystem/GetSequencer.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.List;
+
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.Transmitter;
+
+/**
+ * @test
+ * @bug 4931400
+ * @summary Clarify default connections in default sequencer
+ */
+public class GetSequencer {
+
+    static boolean failed = false;
+
+    public static void main(String args[]) throws Exception {
+        doTest(1);
+        doTest(2);
+        doTest(3);
+
+        if (failed) throw new Exception("Test FAILED!");
+        out("test OK");
+    }
+
+    public static void doTest(int mode) {
+        Sequencer seq = null;
+        boolean connected = false;
+
+        try {
+            switch (mode) {
+            case 1:
+                seq = MidiSystem.getSequencer();
+                connected = true;
+                break;
+            case 2:
+                seq = MidiSystem.getSequencer(false);
+                connected = false;
+                break;
+            case 3:
+                seq = MidiSystem.getSequencer(true);
+                connected = true;
+                break;
+            }
+            out("Testing Sequencer "+seq);
+            if (connected) {
+                out("  opened in connected mode.");
+            } else {
+                out("  opened in non-connected mode.");
+            }
+            System.out.println("  opening...");
+            seq.open();
+        } catch (MidiUnavailableException mue) {
+            System.err.println("MidiUnavailableException was thrown: " + mue);
+            System.err.println("  could not test this sequencer.");
+            return;
+        }
+
+        try {
+            List<Transmitter> transmitters = seq.getTransmitters();
+            int size = transmitters.size();
+            out("  transmitters.size()="+size);
+            if (size != 1 && connected) {
+                out("  should have 1 connection! Failed.");
+                failed = true;
+            }
+            if (size != 0 && !connected) {
+                out("  should have 0 connections! Failed.");
+                failed = true;
+            }
+            out("  closing...");
+            seq.close();
+            transmitters = seq.getTransmitters();
+            size = transmitters.size();
+            out("  transmitters.size()="+size);
+            if (size != 0) {
+                out("  should have 0 connections! Failed.");
+                failed = true;
+            }
+
+            out("  opening again...");
+            seq.open();
+            transmitters = seq.getTransmitters();
+            size = transmitters.size();
+            out("  transmitters.size()="+size);
+            if (size != 1 && connected) {
+                out("  should have 1 connection! Failed.");
+                failed = true;
+            }
+            if (size != 0 && !connected) {
+                out("  should have 0 connections! Failed.");
+                failed = true;
+            }
+        } catch (Exception e) {
+            System.err.println("  unexpectedException was thrown: " + e);
+            System.err.println("  causes this test to FAIL.");
+            failed = true;
+        }
+        seq.close();
+    }
+
+    static void out(String s) {
+        System.out.println(s);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/MidiSystem/MidiFileTypeUniqueness.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiSystem;
+
+/**
+ * @test
+ * @bug 4883060
+ * @summary  AudioSystem.getAudioFileTypes returns duplicates
+ */
+public class MidiFileTypeUniqueness {
+
+    public static void main(String[] args) throws Exception {
+        boolean foundDuplicates = false;
+        int[]   aTypes = MidiSystem.getMidiFileTypes();
+        for (int i = 0; i < aTypes.length; i++)
+        {
+            for (int j = 0; j < aTypes.length; j++)
+            {
+                if (aTypes[i] == aTypes[j] && i != j) {
+                    foundDuplicates = true;
+                }
+            }
+        }
+        if (foundDuplicates) {
+            throw new Exception("Test failed");
+        } else {
+            System.out.println("Test passed");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/MidiSystem/ProviderCacheing.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.List;
+
+import com.sun.media.sound.JDK13Services;
+
+/**
+ * @test
+ * @bug 4776511
+ * @summary RFE: Setting the default MixerProvider. Test the cacheing of
+ *          providers. This is a part of the test for 4776511.
+ * @modules java.desktop/com.sun.media.sound
+ */
+public class ProviderCacheing {
+
+    private static final Class[] providerClasses = {
+        javax.sound.midi.spi.MidiDeviceProvider.class,
+        javax.sound.midi.spi.MidiFileReader.class,
+        javax.sound.midi.spi.MidiFileWriter.class,
+        javax.sound.midi.spi.SoundbankReader.class,
+    };
+
+    public static void main(String[] args) throws Exception {
+        boolean allCached = true;
+        for (int i = 0; i < providerClasses.length; i++) {
+            List list0 = JDK13Services.getProviders(providerClasses[i]);
+            List list1 = JDK13Services.getProviders(providerClasses[i]);
+            if (list0 == list1) {
+                out("Providers should not be cached for " + providerClasses[i]);
+                allCached = false;
+            }
+        }
+
+        if (! allCached) {
+            throw new Exception("Test failed");
+        } else {
+            out("Test passed");
+        }
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/MidiSystem/testdata/conf/sound.properties	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,27 @@
+#
+# Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+javax.sound.midi.Receiver=xyz#123
+javax.sound.midi.Transmitter=xyz#123
+javax.sound.midi.Sequencer=xyz#123
+javax.sound.midi.Synthesizer=xyz#123
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequence/GetMicrosecondLength.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MetaMessage;
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 4929955
+ * @summary Sequence.getMicrosecondLength() returns wrong value
+ */
+public class GetMicrosecondLength {
+
+    public static boolean failed = false;
+    //private static Sequencer seq = null;
+
+    public static void main(String[] args) throws Exception {
+        /*
+          try {
+          seq = MidiSystem.getSequencer();
+          } catch (Exception e) {
+          e.printStackTrace();
+          }
+        */
+        for (int sec = 1; sec < 10; sec += 4) {
+            for (int tempo=0; tempo < 1000; tempo+=120) {
+                for (int resolution=1; resolution < 480; ) {
+                    testSequence(sec, tempo, resolution);
+                    if (resolution == 1) {
+                        resolution = 120;
+                    } else {
+                        resolution += 120;
+                    }
+                }
+            }
+        }
+        if (failed) throw new Exception("Test FAILED!");
+        out("Test Passed.");
+    }
+
+    /**
+     * Create a new Sequence for testing.
+     */
+    private static void testSequence(int lengthInSeconds, int tempoInBPM, int resolution) {
+        Sequence sequence = null;
+        long lengthInMicroseconds = lengthInSeconds * 1000000;
+        boolean createTempoEvent = true;
+        if (tempoInBPM == 0) {
+            tempoInBPM = 120;
+            createTempoEvent = false;
+            System.out.print("Creating sequence: "+lengthInSeconds+"sec, "
+                             +"resolution="+resolution+" ticks/beat...");
+        } else {
+            System.out.print("Creating sequence: "+lengthInSeconds+"sec, "
+                             +tempoInBPM+" beats/min, "
+                             +"resolution="+resolution+" ticks/beat...");
+        }
+        //long lengthInTicks = (lengthInMicroseconds * resolution) / tempoInBPM;
+        long lengthInTicks = (lengthInMicroseconds * tempoInBPM * resolution) / 60000000l;
+        //out("expected length in ticks: " + lengthInTicks);
+        try {
+            sequence = new Sequence(Sequence.PPQ, resolution);
+            Track track = sequence.createTrack();
+            if (createTempoEvent) {
+                int tempoInMPQ = (int) (60000000l / tempoInBPM);
+                MetaMessage tm = new MetaMessage();
+                byte[] msg = new byte[3];
+                msg[0] = (byte) (tempoInMPQ >> 16);
+                msg[1] = (byte) ((tempoInMPQ >> 8) & 0xFF);
+                msg[2] = (byte) (tempoInMPQ & 0xFF);
+
+                tm.setMessage(0x51 /* Meta Tempo */, msg, msg.length);
+                track.add(new MidiEvent(tm, 0));
+                //out("regtest: tempoInMPQ="+tempoInMPQ);
+                //out("Added tempo event: new size="+track.size());
+            }
+            ShortMessage mm = new ShortMessage();
+            mm.setMessage(0xF6, 0, 0);
+            MidiEvent me = new MidiEvent(mm, lengthInTicks);
+            track.add(me);
+            //out("Added realtime event: new size="+track.size());
+        } catch (InvalidMidiDataException e) {
+            out(e);
+        }
+        boolean thisFailed = false;
+        long actualLengthInTicks = sequence.getTickLength();
+        // allow +/- 5%
+        if (Math.abs(actualLengthInTicks - lengthInTicks) > lengthInTicks / 20) {
+            out("FAILED:");
+            out("  expected length in ticks: " + lengthInTicks);
+            out("  actual length in ticks  : " + actualLengthInTicks);
+            thisFailed = true;
+        }
+        long actualLengthInUs = sequence.getMicrosecondLength();
+        // allow +/- 5%
+        if (Math.abs(actualLengthInUs - lengthInMicroseconds) > lengthInMicroseconds / 20) {
+            if (!thisFailed) {
+                out("FAILED:");
+            }
+            out("  expected length in microsecs: " + lengthInMicroseconds);
+            out("  actual length in microsecs  : " + actualLengthInUs);
+            thisFailed = true;
+        }
+        if (!thisFailed) {
+            out("OK");
+        }
+        /*if (seq != null) {
+          try {
+          seq.setSequence(sequence);
+          out("Sequencer tempo="+seq.getTempoInBPM());
+          } catch (Exception e) {
+          e.printStackTrace();
+          }
+          }
+        */
+        failed |= thisFailed;
+    }
+
+
+    private static void out(Throwable t) {
+        t.printStackTrace(System.out);
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequence/MidiSMPTE.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequence;
+
+/**
+ * @test
+ * @bug 4291250
+ * @summary Midi files with SMPTE time do not play properly
+ */
+public class MidiSMPTE {
+
+    public static void main(String[] args) throws Exception {
+        Sequence s = null;
+        //File midiFile = new File("outsmpte.mid");
+        //InputStream is = new FileInputStream(midiFile);
+        //is = new BufferedInputStream(is);
+        InputStream is = new ByteArrayInputStream(smptemidifile);
+        s = MidiSystem.getSequence(is);
+        long duration = s.getMicrosecondLength() / 1000000;
+        System.out.println("Duration: "+duration+" seconds ");
+        if (duration > 14) {
+            throw new Exception("SMPTE time reader is broken! Test FAILED");
+        }
+        System.out.println("Test passed");
+    }
+
+    public static void printFile(String filename) throws Exception {
+        File file = new File(filename);
+        FileInputStream fis = new FileInputStream(file);
+        byte[] data = new byte[(int) file.length()];
+        fis.read(data);
+        String s = "";
+        for (int i=0; i<data.length; i++) {
+            s+=String.valueOf(data[i])+", ";
+            if (s.length()>72) {
+                System.out.println(s);
+                s="";
+            }
+        }
+        System.out.println(s);
+    }
+
+    // A MIDI file with SMPTE timing
+    static byte[] smptemidifile = {
+            77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 3, -30, 120, 77, 84, 114, 107, 0,
+            0, 0, 123, 0, -112, 30, 100, -113, 49, -128, 50, 100, -114, 69, -112, 31,
+            100, -114, 33, -128, 51, 100, -114, 55, -112, 32, 100, -114, 120, -128, 52,
+            100, -114, 40, -112, 33, 100, -114, 26, -128, 53, 100, -114, 26, -112, 34,
+            100, -114, 76, -128, 54, 100, -114, 12, -112, 35, 100, -114, 91, -128, 55,
+            100, -114, 69, -112, 36, 100, -114, 33, -128, 56, 100, -114, 55, -112, 37,
+            100, -114, 84, -128, 57, 100, -114, 40, -112, 38, 100, -114, 26, -128, 58,
+            100, -114, 26, -112, 39, 100, -113, 24, -128, 59, 100, -113, 60, -112, 40,
+            100, -113, 110, -128, 60, 100, -113, 96, -112, 41, 100, -113, 39, -128, 61,
+            100, 0, -1, 47, 0, 77, 84, 114, 107, 0, 0, 0, 4, 0, -1, 47, 0, 77, 84, 114,
+            107, 0, 0, 0, 4, 0, -1, 47, 0
+    };
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequence/SMPTEDuration.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 4702328
+ * @summary Wrong time in sequence for SMPTE based types
+ */
+public class SMPTEDuration {
+
+    public static void main(String args[]) throws Exception {
+         int[][] dataMes =  { {ShortMessage.NOTE_ON, 10, 0x24, 0x50} ,
+                 { ShortMessage.NOTE_OFF, 10, 0x24, 0x44 },
+                 { ShortMessage.NOTE_ON, 10, 0x24, 0x50 },
+                 { ShortMessage.NOTE_ON, 10, 0x26, 0x50 },
+                 { ShortMessage.NOTE_OFF, 10, 0x26, 0x53 } };
+         long[] ticks = { 0, 68, 240, 240, 286};
+         int res = 240;
+         ShortMessage msg;
+         Sequence midiData = null;
+         Track track;
+         boolean failed = false;
+
+
+         try {
+             midiData = new Sequence(Sequence.SMPTE_24 , res);
+         } catch (InvalidMidiDataException invMidiEx) {
+             invMidiEx.printStackTrace(System.out);
+             System.out.println("Unexpected InvalidMidiDataException: "
+                     + invMidiEx.getMessage());
+             failed = true;
+         }
+         track = midiData.createTrack();
+         for (int i = 0; i < dataMes.length; i++) {
+             msg = new ShortMessage();
+             try {
+                 msg.setMessage(dataMes[i][0], dataMes[i][1], dataMes[i][2],
+                         dataMes[i][3]);
+             } catch (InvalidMidiDataException invMidiEx) {
+                 invMidiEx.printStackTrace(System.out);
+                 System.out.println("Unexpected InvalidMidiDataException: "
+                         + invMidiEx.getMessage());
+                 failed = true;
+             }
+             track.add(new MidiEvent(msg, ticks[i]));
+         }
+         //   lengthInMs = (tickLength*1000000)/(divType*Res)
+         long micros = (long) ((midiData.getTickLength() * 1000000) / (res * Sequence.SMPTE_24));
+         if (midiData.getMicrosecondLength() != micros) {
+             failed = true;
+             System.out.println("getMicrosecondLength() returns wrong length: "
+                     + midiData.getMicrosecondLength());
+             System.out.println("getMicrosecondLength() must return length: "
+                     + micros);
+         }
+         if (midiData.getTickLength() != 286) {
+             failed = true;
+             System.out.println("getTickLength() returns wrong length: "
+                     + midiData.getTickLength());
+         }
+
+         if( failed == true ) {
+             throw new Exception("test failed");
+         } else {
+             System.out.println("Passed.");
+         }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequencer/LoopIAE.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 5025549
+ * @summary Verify that setLoopEndPoint throws IAE
+ */
+public class LoopIAE {
+
+    static ShortMessage MidiMsg3(int a, int b, int c) {
+        try {
+            ShortMessage msg = new ShortMessage();
+            msg.setMessage((byte)a,(byte)b,(byte)c);
+            return msg;
+        } catch(InvalidMidiDataException ex) {
+            throw new RuntimeException();
+        }
+    }
+
+    static boolean failed = false;
+
+    public static void main(String[] argv) throws Exception {
+        if (!hasSequencer()) {
+            return;
+        }
+        Sequencer sequencer = MidiSystem.getSequencer();
+        Sequence sequence = new Sequence(Sequence.PPQ, 240);
+        Track track = sequence.createTrack();
+
+        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+0,45,100),0));
+        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+0,45,0),0 + 240));
+        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,100),10*20));
+        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,0),10*20 + 10));
+
+        try {
+            sequencer.open();
+            sequencer.setSequence(sequence);
+            sequencer.setTempoInBPM(100);
+
+            System.out.println("Setting loop end point to 1");
+            sequencer.setLoopEndPoint(1);
+            System.out.println("  -> effectively: "+sequencer.getLoopEndPoint());
+            System.out.println("Setting loop start point to 2 -- should throw IAE");
+            sequencer.setLoopStartPoint(2);
+            System.out.println("  -> effectively: "+sequencer.getLoopStartPoint());
+            System.out.println("No IllegalArgumentException was thrown!");
+            failed = true;
+        } catch (IllegalArgumentException iae) {
+            System.out.println("IAE was thrown correctly.");
+        } catch (MidiUnavailableException mue) {
+            System.out.println("MidiUnavailableException was thrown: " + mue);
+            System.out.println("Cannot execute test.");
+        } catch (InvalidMidiDataException imEx) {
+            System.out.println("InvalidMidiDataException was thrown.");
+            imEx.printStackTrace();
+            System.out.println("Cannot execute test.");
+        } finally {
+            if (sequencer != null && sequencer.isOpen()) {
+                sequencer.close();
+            }
+        }
+        if (failed) {
+            throw new Exception("Test FAILED!");
+        }
+        System.out.println("test passed.");
+    }
+
+    static boolean hasSequencer() {
+        try {
+            Sequencer seq = MidiSystem.getSequencer();
+            if (seq != null) {
+                if (seq.isOpen()) {
+                    seq.close();
+                }
+                return true;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        System.out.println("No sequencer available! Cannot execute test.");
+        return false;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequencer/Looping.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,315 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MetaEventListener;
+import javax.sound.midi.MetaMessage;
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 4204105
+ * @summary RFE: add loop() method(s) to Sequencer
+ * @key intermittent
+ */
+public class Looping {
+
+    public static void main(String[] args) throws Exception {
+        out("4204105: RFE: add loop() method(s) to Sequencer");
+        boolean passed = testAll();
+        if (passed) {
+            out("Test PASSED.");
+        } else {
+            throw new Exception("Test FAILED.");
+        }
+    }
+
+    /**
+     * Execute the test on all available Sequencers.
+     *
+     * @return true if the test passed for all Sequencers, false otherwise
+     */
+    private static boolean testAll() throws Exception {
+        boolean result = true;
+        MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
+        for (int i = 0; i < devices.length; i++) {
+            MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
+            if (device instanceof Sequencer) {
+                result &= testSequencer((Sequencer) device);
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Execute the test on the passed Sequencer.
+     *
+     * @return true if the test is passed this Sequencer, false otherwise
+     */
+    private static boolean testSequencer(Sequencer seq) throws Exception{
+        boolean result = true;
+        out("testing: " + seq);
+
+        result &= testGetSet(seq);
+
+        seq.setSequence(createSequence());
+
+        result &= testGetSet(seq);
+
+        result &= testPlay(seq);
+
+        return result;
+    }
+
+    private static boolean testGetSet(Sequencer seq) {
+        boolean result = true;
+        Sequence sequence = seq.getSequence();
+        boolean isSequenceLoaded = (sequence != null);
+
+        out("TestGetSet");
+
+        try {
+            if (seq.getLoopStartPoint() != 0) {
+                out("start point", isSequenceLoaded,
+                    "isn't 0!");
+                result = false;
+            }
+        } catch (IllegalArgumentException iae) {
+            if (!isSequenceLoaded) {
+                out("Caught permissable IllegalArgumentException:");
+            } else {
+                out("Threw unacceptable IllegalArgumentException! FAILED");
+                result = false;
+            }
+            out(iae.toString());
+        }
+
+        if (seq.getLoopEndPoint() != -1) {
+            out("end point", isSequenceLoaded,
+                "isn't -1!");
+            result = false;
+        }
+
+        try {
+            seq.setLoopStartPoint(25);
+            if (seq.getLoopStartPoint() != 25) {
+                out("setLoopStartPoint()", isSequenceLoaded,
+                    "doesn't set the start point correctly!");
+                result = false;
+            }
+        } catch (IllegalArgumentException iae) {
+            if (!isSequenceLoaded) {
+                out("Caught permissable IllegalArgumentException:");
+            } else {
+                out("Threw unacceptable IllegalArgumentException! FAILED");
+                result = false;
+            }
+            out(iae.toString());
+        }
+
+        try {
+            seq.setLoopEndPoint(26);
+            if (seq.getLoopEndPoint() != 26) {
+                out("setLoopEndPoint()", isSequenceLoaded,
+                    "doesn't set the end point correctly!");
+                result = false;
+            }
+        } catch (IllegalArgumentException iae) {
+            if (!isSequenceLoaded) {
+                out("Caught permissable IllegalArgumentException:");
+            } else {
+                out("Threw unacceptable IllegalArgumentException! FAILED");
+                result = false;
+            }
+            out(iae.toString());
+        }
+
+        try {
+            seq.setLoopStartPoint(0);
+            if (seq.getLoopStartPoint() != 0) {
+                out("setLoopStartPoint()", isSequenceLoaded,
+                    "doesn't set the start point correctly!");
+                result = false;
+            }
+        } catch (IllegalArgumentException iae) {
+            if (!isSequenceLoaded) {
+                out("Caught permissable IllegalArgumentException:");
+            } else {
+                out("Threw unacceptable IllegalArgumentException! FAILED");
+                result = false;
+            }
+            out(iae.toString());
+        }
+
+        if (isSequenceLoaded) {
+            seq.setLoopEndPoint(sequence.getTickLength());
+            if (seq.getLoopEndPoint() != sequence.getTickLength()) {
+                out("setLoopEndPoint()", isSequenceLoaded,
+                    "doesn't set the end point correctly!");
+                result = false;
+            }
+        } else {
+            // fails
+            seq.setLoopEndPoint(-1);
+            if (seq.getLoopEndPoint() != -1) {
+                out("setLoopEndPoint()", isSequenceLoaded,
+                    "doesn't set the end point correctly!");
+                result = false;
+            }
+        }
+
+        if (seq.getLoopCount() != 0) {
+            out("loop count", isSequenceLoaded,
+                "isn't 0!");
+            result = false;
+        }
+
+        seq.setLoopCount(1001);
+        if (seq.getLoopCount() != 1001) {
+            out("setLoopCount()", isSequenceLoaded,
+                "doesn't set the loop count correctly!");
+            result = false;
+        }
+
+        seq.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
+        if (seq.getLoopCount() != Sequencer.LOOP_CONTINUOUSLY) {
+            out("setLoopCount(Sequencer.LOOP_CONTINUOUSLY)", isSequenceLoaded,
+                "doesn't set the loop count correctly!");
+            result = false;
+        }
+
+        try {
+            seq.setLoopCount(-55);
+            out("setLoopCount()", isSequenceLoaded,
+                "doesn't throw IllegalArgumentException on illegal value!");
+            result = false;
+        } catch (IllegalArgumentException e) {
+            // EXCEPTION IS EXPECTED
+            out("Caught permissable IAE");
+        }
+
+        seq.setLoopCount(0);
+        if (seq.getLoopCount() != 0) {
+            out("setLoopCount()", isSequenceLoaded,
+                "doesn't set the loop count correctly!");
+            result = false;
+        }
+
+        return result;
+    }
+
+    private static boolean testPlay(Sequencer seq) {
+        boolean result = true;
+        long stopTime;
+
+        out("TestPlay");
+
+        TestMetaEventListener listener = new TestMetaEventListener();
+        seq.addMetaEventListener(listener);
+        long startTime = System.currentTimeMillis();
+        try {
+            seq.open();
+            out("Playing sequence, length="+(seq.getMicrosecondLength()/1000)+"millis");
+            seq.start();
+            while (true) {
+                stopTime = listener.getStopTime();
+                if (stopTime != 0) {
+                    break;
+                }
+                try {
+                    Thread.sleep(100);
+                } catch (InterruptedException e) {
+                }
+            }
+            long measuredDuration = stopTime - startTime;
+            out("play duration (us): " + measuredDuration);
+        } catch (Exception e) {
+            out("test not executed; exception:");
+            e.printStackTrace();
+        }
+        seq.close();
+        return result;
+    }
+
+    /**
+     * Create a new Sequence for testing.
+     *
+     * @return a dummy Sequence, or null, if a problem occured while creating
+     *         the Sequence
+     */
+    private static Sequence createSequence() {
+        Sequence sequence = null;
+        int lengthInSeconds = 2;
+        long lengthInMicroseconds = lengthInSeconds * 1000000;
+        int resolution = 480;
+        long lengthInTicks = (lengthInMicroseconds * 120 * resolution) / 60000000l;
+        out("length in ticks: " + lengthInTicks);
+        try {
+            sequence = new Sequence(Sequence.PPQ, resolution, 1);
+            Track track = sequence.createTrack();
+            ShortMessage mm = new ShortMessage();
+            mm.setMessage(0xF6, 0, 0);
+            MidiEvent me = new MidiEvent(mm, lengthInTicks);
+            track.add(me);
+        } catch (InvalidMidiDataException e) {
+            // DO NOTHING
+        }
+        out("sequence length (ticks): " + sequence.getTickLength());
+        out("sequence length (us): " + sequence.getMicrosecondLength());
+        return sequence;
+    }
+
+
+    private static void out(String m1, boolean isSequenceLoaded, String m2) {
+        out(m1 + (isSequenceLoaded ? " with Sequence " : " without Sequence ") + m2);
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+
+    private static class TestMetaEventListener implements MetaEventListener {
+        private long stopTime;
+
+
+        public void meta(MetaMessage m) {
+            System.out.print("  Got MetaMessage: ");
+            if (m.getType() == 47) {
+                stopTime = System.currentTimeMillis();
+                System.out.println(" End Of Track -- OK");
+            } else {
+                System.out.println(" unknown. Ignored.");
+            }
+        }
+
+        public long getStopTime() {
+            return stopTime;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequencer/MetaCallback.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.Instrument;
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MetaEventListener;
+import javax.sound.midi.MetaMessage;
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 4347135
+ * @summary MIDI MetaMessage callback inconsistent
+ * @run main/othervm MetaCallback
+ */
+public class MetaCallback implements MetaEventListener {
+
+    static ShortMessage MidiMsg3(int a, int b, int c) {
+        try {
+            ShortMessage msg = new ShortMessage();
+            msg.setMessage((byte)a,(byte)b,(byte)c);
+            return msg;
+        } catch(InvalidMidiDataException ex) {
+            throw new RuntimeException();
+        }
+    }
+
+    //Synthesizer synth;
+    Instrument[] instruments;
+    Sequencer sequencer;
+    Sequence sequence;
+    Track track;
+
+    public static int TOTAL_COUNT = 100;
+
+    int metaCount = 0;
+    boolean finished = false;
+
+    MetaCallback() throws Exception {
+
+        sequencer=MidiSystem.getSequencer();
+        sequence=new Sequence(Sequence.PPQ,240);
+        track=sequence.createTrack();
+        sequencer.addMetaEventListener(this);
+
+        byte[] data = new byte[1];
+
+        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+0,45,100),0));
+        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+0,45,0),0 + 240));
+        int c;
+        for(c=0; c < TOTAL_COUNT; c++) {
+            data[0]=(byte)(c+1);
+            MetaMessage meta = new MetaMessage();
+            meta.setMessage(1, data, 1); // type, data, length
+            track.add(new MidiEvent(meta,c*20));
+        }
+        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,100),c*20));
+        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,0),c*20 + 10));
+
+        sequencer.setSlaveSyncMode(Sequencer.SyncMode.INTERNAL_CLOCK);
+        sequencer.setMasterSyncMode(Sequencer.SyncMode.INTERNAL_CLOCK);
+        sequencer.open();
+        sequencer.setSequence(sequence);
+        sequencer.setTempoInBPM(100);
+        System.out.println("Starting playback...");
+        this.start();
+        while (!finished && sequencer.getTickPosition() < sequencer.getTickLength()) {
+            System.out.println("Tick "+sequencer.getTickPosition()+"...");
+            Thread.sleep(1000);
+        }
+        System.out.println("Stopping playback...");
+        this.stop();
+        if (metaCount != TOTAL_COUNT) {
+            throw new Exception("Expected "+TOTAL_COUNT+" callbacks, but got "+metaCount+"!");
+        }
+    }
+    void start() {sequencer.start();}
+    void stop() {sequencer.stop();}
+
+    public void meta(MetaMessage msg) {
+        System.out.println(""+metaCount+": got "+msg);
+        if (msg.getType() == 0x2F) {
+            finished = true;
+        } else if (msg.getData().length > 0 && msg.getType() == 1) {
+            metaCount++;
+        }
+    }
+
+    public static void main(String[] argv) throws Exception {
+        if (hasSequencer()) {
+            new MetaCallback();
+            System.out.println("Test passed");
+        }
+    }
+
+    static boolean hasSequencer() {
+        try {
+            Sequencer seq = MidiSystem.getSequencer();
+            if (seq != null) {
+                seq.open();
+                seq.close();
+                return true;
+            }
+        } catch (Exception e) {}
+        System.out.println("No sequencer available! Cannot execute test.");
+        return false;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequencer/Recording.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,213 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MetaMessage;
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Receiver;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 4932841
+ * @key intermittent
+ * @summary Sequencer's recording feature does not work
+ */
+public class Recording {
+
+    public static boolean failed = false;
+    public static boolean passed = false;
+    private static Sequencer seq = null;
+
+    public static void main(String[] args) throws Exception {
+        try {
+            seq = MidiSystem.getSequencer();
+
+            // create an arbitrary sequence which lasts 10 seconds
+            Sequence sequence = createSequence(10, 120, 240);
+
+            seq.setSequence(sequence);
+            out("Set Sequence to Sequencer. Tempo="+seq.getTempoInBPM());
+
+            Track track = sequence.createTrack();
+            int oldSize = track.size();
+            seq.recordEnable(track, -1);
+
+            seq.open();
+
+            // if getReceiver throws Exception, failed!
+            failed = true;
+            Receiver rec = seq.getReceiver();
+
+            // start recording and add various events
+            seq.startRecording();
+
+            // is exception from here on, not failed
+            failed = false;
+
+            if (!seq.isRecording()) {
+                failed = true;
+                throw new Exception("Sequencer did not start recording!");
+            }
+            if (!seq.isRunning()) {
+                failed = true;
+                throw new Exception("Sequencer started recording, but is not running!");
+            }
+
+            // first: add an event to the middle of the sequence
+            ShortMessage msg = new ShortMessage();
+            msg.setMessage(0xC0, 80, 00);
+            rec.send(msg, 5l * 1000l * 1000l);
+
+            Thread.sleep(1000);
+
+            // then add a real-time event
+            msg = new ShortMessage();
+            msg.setMessage(0xC0, 81, 00);
+            long secondEventTick = seq.getTickPosition();
+            rec.send(msg, -1);
+
+            seq.stopRecording();
+            if (seq.isRecording()) {
+                failed = true;
+                throw new Exception("Stopped recording, but Sequencer is still recording!");
+            }
+            if (!seq.isRunning()) {
+                failed = true;
+                throw new Exception("Stopped recording, but Sequencer but is not running anymore!");
+            }
+
+            seq.stop();
+            if (seq.isRunning()) {
+                failed = true;
+                throw new Exception("Stopped Sequencer, but it is still running!");
+            }
+
+            // now examine the contents of the recorded track:
+            // 1) number of events: should be 2 more
+            int newSize = track.size();
+            int addedEventCount = newSize - oldSize;
+
+            out("Added "+addedEventCount+" events to recording track.");
+            if (addedEventCount != 2) {
+                failed = true;
+                throw new Exception("Did not add 2 events!");
+            }
+
+            // 2) the first event should be at roughly "secondEventTick"
+            MidiEvent ev = track.get(0);
+            msg = (ShortMessage) ev.getMessage();
+            out("The first recorded event is at tick position: "+ev.getTick());
+            if (Math.abs(ev.getTick() - secondEventTick) > 1000) {
+                out(" -> but expected something like: "+secondEventTick+"! FAILED.");
+                failed = true;
+            }
+
+            ev = track.get(1);
+            msg = (ShortMessage) ev.getMessage();
+            out("The 2nd recorded event is at tick position: "+ev.getTick());
+            out(" -> sequence's tick length is "+seq.getTickLength());
+            if (Math.abs(ev.getTick() - (sequence.getTickLength() / 2)) > 1000) {
+                out(" -> but expected something like: "+(seq.getTickLength()/2)+"! FAILED.");
+                failed = true;
+            }
+
+            passed = true;
+        } catch (Exception e) {
+            out(e.toString());
+            if (!failed) out("Test not failed.");
+        }
+        if (seq != null) {
+            seq.close();
+        }
+
+        if (failed) {
+            throw new Exception("Test FAILED!");
+        }
+        else if (passed) {
+            out("Test Passed.");
+        }
+    }
+
+    /**
+     * Create a new Sequence for testing.
+     */
+    private static Sequence createSequence(int lengthInSeconds, int tempoInBPM,
+                                           int resolution) {
+        Sequence sequence = null;
+        long lengthInMicroseconds = lengthInSeconds * 1000000;
+        boolean createTempoEvent = true;
+        if (tempoInBPM == 0) {
+            tempoInBPM = 120;
+            createTempoEvent = false;
+            System.out.print("Creating sequence: "+lengthInSeconds+"sec, "
+                             +"resolution="+resolution+" ticks/beat...");
+        } else {
+            System.out.print("Creating sequence: "+lengthInSeconds+"sec, "
+                             +tempoInBPM+" beats/min, "
+                             +"resolution="+resolution+" ticks/beat...");
+        }
+        //long lengthInTicks = (lengthInMicroseconds * resolution) / tempoInBPM;
+        long lengthInTicks = (lengthInMicroseconds * tempoInBPM * resolution) / 60000000l;
+        //out("expected length in ticks: " + lengthInTicks);
+        try {
+            sequence = new Sequence(Sequence.PPQ, resolution);
+            Track track = sequence.createTrack();
+            if (createTempoEvent) {
+                int tempoInMPQ = (int) (60000000l / tempoInBPM);
+                MetaMessage tm = new MetaMessage();
+                byte[] msg = new byte[3];
+                msg[0] = (byte) (tempoInMPQ >> 16);
+                msg[1] = (byte) ((tempoInMPQ >> 8) & 0xFF);
+                msg[2] = (byte) (tempoInMPQ & 0xFF);
+
+                tm.setMessage(0x51 /* Meta Tempo */, msg, msg.length);
+                track.add(new MidiEvent(tm, 0));
+                //out("regtest: tempoInMPQ="+tempoInMPQ);
+                //out("Added tempo event: new size="+track.size());
+            }
+            ShortMessage mm = new ShortMessage();
+            mm.setMessage(0xF6, 0, 0);
+            MidiEvent me = new MidiEvent(mm, lengthInTicks);
+            track.add(me);
+            //out("Added realtime event: new size="+track.size());
+        } catch (InvalidMidiDataException e) {
+            out(e);
+        }
+        out("OK");
+
+        return sequence;
+    }
+
+    private static void out(Throwable t) {
+        t.printStackTrace(System.out);
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequencer/SeqRecordDoesNotCopy.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.MidiMessage;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Receiver;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 5048381
+ * @summary Sequencer doesn't create distinct messages when recording events.
+ * @key headful
+ */
+public class SeqRecordDoesNotCopy {
+    public static void main(String argv[]) throws Exception {
+        Sequencer s = MidiSystem.getSequencer();
+        s.open();
+        try {
+            Sequence seq = new Sequence(Sequence.PPQ, 384, 2);
+            s.setSequence(seq);
+            Track t = seq.getTracks()[0];
+            ShortMessage msg = new ShortMessage();
+            msg.setMessage(0x90, 0x40, 0x7F);
+            t.add(new MidiEvent(msg, 11000));
+            msg.setMessage(0x90, 0x40, 0x00);
+            t.add(new MidiEvent(msg, 12000));
+            t = seq.getTracks()[1];
+            s.recordEnable(t, -1);
+            System.out.println("Started recording...");
+            s.startRecording();
+            Receiver r = s.getReceiver();
+            Thread.sleep(100);
+            // send a normal message
+            System.out.println("Recording a normal NOTE ON message...");
+            msg.setMessage(0x90, 0x40, 0x6F);
+            r.send(msg, -1);
+            Thread.sleep(100);
+            // send a normal message
+            System.out.println("Recording a normal NOTE OFF message...");
+            msg.setMessage(0x90, 0x40, 0x00);
+            r.send(msg, -1);
+            Thread.sleep(100);
+            s.stop();
+            // now see if the messages were recorded
+            System.out.println("Recorded messages:");
+            int sameMessage = 0;
+            for (int i = 0; i < t.size(); i++) {
+                System.out.print(" "+(i+1)+". ");
+                printEvent(t.get(i));
+                if (t.get(i).getMessage() == msg) {
+                    System.out.println("## Failed: Same Message reference!");
+                    sameMessage++;
+                }
+            }
+            if (sameMessage > 0) {
+                System.out.println("## Failed: The same instance was recorded!");
+                throw new Exception("Test FAILED!");
+            }
+            System.out.println("Did not detect any duplicate messages.");
+            System.out.println("Test passed.");
+        } catch (Exception e) {
+            System.out.println("Unexpected Exception: "+e);
+            //e.printStackTrace();
+            throw new Exception("Test FAILED!");
+        } finally {
+            s.close();
+        }
+    }
+    public static void printEvent(MidiEvent event)
+    {
+        MidiMessage message = event.getMessage();
+        long tick = event.getTick();
+        byte[] data = message.getMessage();
+
+        StringBuffer sb = new StringBuffer((data.length * 3) - 1);
+
+        for (int i = 0; i < data.length; i++)
+        {
+                sb.append(toHexByteString(data[i]));
+                if (i < data.length - 1) sb.append(' ');
+        }
+        System.out.printf("%5d: %s%n", tick, sb);
+    }
+
+    private static String toHexByteString(int n)
+    {
+        if (n < 0) n &= 0xFF;
+        String s = Integer.toHexString(n).toUpperCase();
+        if (s.length() == 1) s = '0' + s;
+        return s;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequencer/SeqRecordsRealTimeEvents.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.MidiMessage;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Receiver;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 5048381
+ * @summary Sequencer records real time messages into the sequence
+ * @key headful
+ */
+public class SeqRecordsRealTimeEvents {
+    public static void main(String argv[]) throws Exception {
+        Sequencer s = MidiSystem.getSequencer();
+        s.open();
+        try {
+            Sequence seq = new Sequence(Sequence.PPQ, 384, 2);
+            s.setSequence(seq);
+            Track t = seq.getTracks()[0];
+            ShortMessage msg = new ShortMessage();
+            msg.setMessage(0x90, 0x40, 0x7F);
+            t.add(new MidiEvent(msg, 11000));
+            msg = new ShortMessage();
+            msg.setMessage(0x90, 0x40, 0x00);
+            t.add(new MidiEvent(msg, 12000));
+            t = seq.getTracks()[1];
+            s.recordEnable(t, -1);
+            System.out.println("Started recording...");
+            s.startRecording();
+            Receiver r = s.getReceiver();
+            Thread.sleep(100);
+            int oldTrackSize = t.size();
+            // send a realtime message to the track
+            System.out.println("Recording real time message...");
+            msg = new ShortMessage();
+            msg.setMessage(0xF8, 0, 0);
+            r.send(msg, -1);
+            Thread.sleep(100);
+            // send a normal message
+            msg = new ShortMessage();
+            System.out.println("Recording a normal NOTE ON message...");
+            msg.setMessage(0x90, 0x40, 0x6F);
+            r.send(msg, -1);
+            Thread.sleep(100);
+            s.stop();
+            // now see if the messages were recorded
+            int newMessages = t.size() - oldTrackSize;
+            System.out.println("Recorded messages:");
+            for (int i = 0; i < t.size(); i++) {
+                System.out.print(" "+(i+1)+". ");
+                printEvent(t.get(i));
+            }
+            if (newMessages == 0) {
+                System.out.println("## Failed: No messages were recorded!");
+                throw new Exception("Test FAILED!");
+            } else if (newMessages == 1) {
+                System.out.println("Only one message was recorded. Correct!");
+            } else if (newMessages > 1) {
+                System.out.println("## Failed: 2 or more messages were recorded!");
+                throw new Exception("Test FAILED!");
+            }
+            System.out.println("Test passed.");
+        } catch (Exception e) {
+            System.out.println("Unexpected Exception: "+e);
+            //e.printStackTrace();
+            throw new Exception("Test FAILED!");
+        } finally {
+            s.close();
+        }
+    }
+    public static void printEvent(MidiEvent event)
+    {
+        MidiMessage message = event.getMessage();
+        long tick = event.getTick();
+        byte[] data = message.getMessage();
+
+        StringBuffer sb = new StringBuffer((data.length * 3) - 1);
+
+        for (int i = 0; i < data.length; i++)
+        {
+                sb.append(toHexByteString(data[i]));
+                if (i < data.length - 1) sb.append(' ');
+        }
+        System.out.printf("%5d: %s%n", tick, sb);
+    }
+
+    private static String toHexByteString(int n)
+    {
+        if (n < 0) n &= 0xFF;
+        String s = Integer.toHexString(n).toUpperCase();
+        if (s.length() == 1) s = '0' + s;
+        return s;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequencer/SeqStartRecording.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequencer;
+
+/**
+ * @test
+ * @bug 5001943
+ * @summary Sequencer.startRecording throws unexpected NPE
+ * @key headful
+ */
+public class SeqStartRecording {
+    public static void main(String argv[]) throws Exception {
+        Sequencer seq = MidiSystem.getSequencer();
+        seq.open();
+        try {
+            seq.startRecording();
+            System.out.println("Test passed.");
+        } catch (NullPointerException npe) {
+            System.out.println("Caught NPE: "+npe);
+            npe.printStackTrace();
+            throw new Exception("Test FAILED!");
+        } catch (Exception e) {
+            System.out.println("Unexpected Exception: "+e);
+            e.printStackTrace();
+            System.out.println("Test NOT failed.");
+        } finally {
+            seq.close();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequencer/SequencerCacheValues.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Sequencer;
+
+/**
+ * @test
+ * @bug 4716740
+ * @summary default sequencer does not set the tempo factor
+ */
+public class SequencerCacheValues {
+
+    static boolean failed = false;
+
+    public static void main(String args[]) throws Exception {
+        Sequencer seq = null;
+        int totalNumberOfSequencers = 0;
+
+        MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
+        for (int device=0; device<infos.length; device++) {
+            //seq = MidiSystem.getSequencer();
+            MidiDevice dev = MidiSystem.getMidiDevice(infos[device]);
+            if (dev instanceof Sequencer) {
+                seq = (Sequencer) dev;
+                totalNumberOfSequencers++;
+                System.out.println("Opening sequencer "+infos[device]);
+                try {
+                    seq.open();
+                    try {
+                        doTest(seq);
+                    } finally {
+                        if (seq != null) {
+                            seq.close();
+                            seq = null;
+                        }
+                    }
+                } catch (MidiUnavailableException mue) {
+                    System.err.println("MidiUnavailableException was thrown: " + mue);
+                    System.err.println("could not test this sequencer.");
+                }
+            }
+        }
+        if (totalNumberOfSequencers == 0) {
+            System.out.println("No sequencers installed!");
+            failed = true;
+        }
+        if (failed) {
+            throw new Exception("FAILED");
+        } else {
+            System.out.println("test OK");
+        }
+    }
+
+    public static boolean equalsFloat(float f1, float f2) {
+        return (f1-f2<0.0001) && (f2-f1<0.0001);
+    }
+
+    public static void doTest(Sequencer seq) throws Exception {
+        seq.setTempoInMPQ(3.0f);
+        System.out.println("Setting tempo in MPQ to "+3.0f);
+        if (!equalsFloat(seq.getTempoInMPQ(), 3.0f)) {
+            System.err.println("getTempoInMPQ() returns wrong value : "
+                + seq.getTempoInMPQ());
+            failed = true;
+        }
+
+        System.out.println("Setting tempo factor to "+2.0f);
+        seq.setTempoFactor(2.0f);
+        if (!equalsFloat(seq.getTempoFactor(), 2.0f)) {
+            System.err.println("getTempoFactor() returns: " + seq.getTempoFactor());
+            failed = true;
+        }
+
+        float bpmTempo = 120.0f;
+        System.out.println("Setting tempo to "+120.0f+"bpm");
+        seq.setTempoInBPM(bpmTempo);
+        if (!equalsFloat(seq.getTempoInMPQ(), (60000000.0f/seq.getTempoInBPM()))) {
+            System.err.println("getTempoInMPQ() returns: " + seq.getTempoInMPQ());
+            System.err.println("getTempoInBPM() returns: " + seq.getTempoInBPM());
+            failed = true;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequencer/SequencerSetMuteSolo.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Sequencer;
+
+/**
+ * @test
+ * @bug 4713900
+ * @summary default Sequencer allows to set Mute for invalid track
+ */
+public class SequencerSetMuteSolo {
+
+    public static void main(String args[]) throws Exception {
+        if (!hasSequencer()) {
+            return;
+        }
+
+        //printMidiFile(args[0]);
+
+        boolean failed = false;
+        Sequencer seq = null;
+        Sequence midiData = getSequence();
+        int numTracks = midiData.getTracks().length;
+        int totalNumberOfSequencers = 0;
+        int totalNumberOfTestedSequencers = 0;
+
+        MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
+        for (int device=0; device<infos.length; device++) {
+            //seq = MidiSystem.getSequencer();
+            MidiDevice dev = MidiSystem.getMidiDevice(infos[device]);
+            if (dev instanceof Sequencer) {
+                seq = (Sequencer) dev;
+                totalNumberOfSequencers++;
+                System.out.println("Opening sequencer "+infos[device]);
+                try {
+                    seq.open();
+                    try {
+                        seq.setSequence(midiData);
+                        System.err.println("Number of tracks: " + numTracks);
+                        System.err.println("TrackMute["+numTracks+"] state was: " + seq.getTrackMute(numTracks));
+                        System.err.println("  setting to muted.");
+                        seq.setTrackMute(numTracks, true);
+                        System.err.println("  TrackMute["+numTracks+"] is now: " + seq.getTrackMute(numTracks));
+                        if (seq.getTrackMute(numTracks)) {
+                            failed = true;
+                        }
+                        System.err.println("TrackSolo["+numTracks+"] state was: " + seq.getTrackSolo(numTracks));
+                        System.err.println("  setting to solo.");
+                        seq.setTrackSolo(numTracks, true);
+                        System.err.println("  TrackSolo["+numTracks+"] is now: " + seq.getTrackSolo(numTracks));
+                        if (seq.getTrackSolo(numTracks)) {
+                            failed = true;
+                        }
+                        totalNumberOfTestedSequencers++;
+                    } finally {
+                        if (seq != null) {
+                            seq.close();
+                            seq = null;
+                        }
+                    }
+                } catch (MidiUnavailableException mue) {
+                    System.err.println("MidiUnavailableException was thrown: " + mue);
+                    System.err.println("could not test this sequencer.");
+                    return;
+                }
+            }
+        }
+        if (totalNumberOfSequencers == 0) {
+            System.out.println("No sequencers installed!");
+            failed = true;
+        }
+        if (totalNumberOfTestedSequencers == 0) {
+            System.out.println("Could not test any sequencers!");
+            failed = true;
+        }
+        if( failed ) {
+            throw new Exception("FAILED");
+        } else {
+            System.out.println("test OK");
+        }
+    }
+
+    public static String getString(byte b) {
+        //String res = Integer.toHexString(b & 0xFF).toUpperCase();
+        //while (res.length()<2) res="0"+res;
+        //return res;
+        return String.valueOf(b);
+    }
+
+
+    public static void printMidiFile(String filename) throws Exception {
+        File file = new File(filename);
+        FileInputStream fis = new FileInputStream(file);
+        byte[] data = new byte[(int) file.length()];
+        fis.read(data);
+        String s = "";
+        for (int i=0; i<data.length; i++) {
+                s+=getString(data[i])+", ";
+                if (s.length()>72) {
+                        System.out.println(s);
+                        s="";
+                }
+        }
+        System.out.println(s);
+    }
+
+    public static Sequence getSequence() throws Exception {
+        ByteArrayInputStream bais = new ByteArrayInputStream(pitchbend);
+        Sequence seq = MidiSystem.getSequence(bais);
+        return seq;
+    }
+
+    public static byte[] pitchbend = {
+        77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 2, 0, 120, 77, 84, 114, 107, 0, 0,
+        0, 27, 0, -1, 3, 19, 77, 73, 68, 73, 32, 116, 101, 115, 116, 32, 45, 32,
+        116, 114, 97, 99, 107, 32, 48, 0, -1, 47, 0, 77, 84, 114, 107, 0, 0, 0, -44,
+        0, -1, 3, 19, 77, 73, 68, 73, 32, 116, 101, 115, 116, 32, 45, 32, 116, 114,
+        97, 99, 107, 32, 49, 0, -64, 30, 0, -112, 68, 126, 0, -32, 6, 67, 0, 14,
+        71, 0, 20, 74, 0, 26, 77, 0, 32, 80, 0, 42, 85, 6, 50, 89, 6, 56, 92, 5,
+        66, 97, 6, 74, 101, 6, 80, 104, 11, 84, 106, 20, 76, 102, 6, 70, 99, 5, 60,
+        94, 6, 52, 90, 5, 44, 86, 4, 34, 81, 5, 26, 77, 5, 20, 74, 6, 10, 69, 5,
+        2, 65, 7, 0, 64, 42, -112, 66, 123, 11, 68, 0, 72, 63, 126, 4, 66, 0, 43,
+        -32, 0, 63, 6, 0, 60, 7, 0, 56, 6, 0, 53, 5, 0, 49, 5, 0, 43, 4, 0, 37, 3,
+        0, 30, 3, 0, 25, 3, 0, 19, 3, 0, 13, 4, 0, 8, 4, 0, 2, 4, 0, 0, 70, 0, 3,
+        5, 0, 9, 3, 0, 14, 7, 0, 16, 25, 0, 21, 5, 0, 25, 7, 0, 28, 5, 0, 32, 5,
+        0, 36, 5, 0, 41, 6, 0, 46, 5, 0, 50, 5, 0, 53, 4, 0, 58, 7, 0, 61, 7, 0,
+        64, 117, -112, 63, 0, 0, -1, 47, 0
+    };
+
+    static boolean hasSequencer() {
+        try {
+            Sequencer seq = MidiSystem.getSequencer();
+            if (seq != null) {
+                seq.open();
+                seq.close();
+                return true;
+            }
+        } catch (Exception e) {}
+        System.out.println("No sequencer available! Cannot execute test.");
+        return false;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequencer/SequencerState.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,272 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Sequencer;
+
+/**
+ * @test
+ * @bug 4913027
+ * @summary several Sequencer methods should specify behaviour on closed Sequencer
+ */
+public class SequencerState {
+
+    private static boolean hasSequencer() {
+        try {
+            Sequencer seq = MidiSystem.getSequencer();
+            if (seq != null) {
+                seq.open();
+                seq.close();
+                return true;
+            }
+        } catch (Exception e) {}
+        System.out.println("No sequencer available! Cannot execute test.");
+        return false;
+    }
+
+
+    public static void main(String[] args) throws Exception {
+        out("4913027: several Sequencer methods should should specify behaviour on closed Sequencer");
+        if (hasSequencer()) {
+            boolean passed = testAll();
+            if (passed) {
+                out("Test PASSED.");
+            } else {
+                throw new Exception("Test FAILED.");
+            }
+        }
+    }
+
+    /**
+     * Execute the test on all available Sequencers.
+     *
+     * @return true if the test passed for all Sequencers, false otherwise
+     */
+    private static boolean testAll() throws Exception {
+        boolean result = true;
+        MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
+        for (int i = 0; i < devices.length; i++) {
+            MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
+            if (device instanceof Sequencer) {
+                result &= testSequencer((Sequencer) device);
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Execute the test on the passed Sequencer.
+     *
+     * @return true if the test is passed this Sequencer, false otherwise
+     */
+    private static boolean testSequencer(Sequencer seq) throws Exception {
+        boolean result = true;
+
+        out("testing: " + seq);
+        /* test calls in closed state.
+         */
+        if (seq.isOpen()) {
+            out("Sequencer is already open, cannot test!");
+            return result;
+        }
+
+        try {
+            seq.start();
+            out("closed state: start() does not throw IllegalStateException!");
+            result = false;
+        } catch (IllegalStateException e) {
+        }
+
+        try {
+            seq.stop();
+            out("closed state: stop() does not throw IllegalStateException!");
+            result = false;
+        } catch (IllegalStateException e) {
+        }
+
+        try {
+            seq.startRecording();
+            out("closed state: startRecording() does not throw IllegalStateException!");
+            result = false;
+        } catch (IllegalStateException e) {
+        }
+
+        try {
+            seq.stopRecording();
+            out("closed state: stopRecording() does not throw IllegalStateException!");
+            result = false;
+        } catch (IllegalStateException e) {
+        }
+
+        Sequence sequence = createSequence();
+        if (sequence == null) {
+            out("created Sequence is null, cannot test!");
+            return result;
+        }
+        try {
+            seq.setSequence(sequence);
+        } catch (IllegalStateException e) {
+            out("closed state: setSequence(Sequence) throws IllegalStateException!");
+            result = false;
+        }
+
+        InputStream inputStream = createSequenceInputStream();
+        if (inputStream == null) {
+            out("created InputStream is null, cannot test!");
+            return result;
+        }
+        try {
+            seq.setSequence(inputStream);
+        } catch (IllegalStateException e) {
+            out("closed state: setSequence(InputStream) throws IllegalStateException!");
+            result = false;
+        }
+
+        try {
+            seq.getSequence();
+        } catch (IllegalStateException e) {
+            out("closed state: getSequence() throws IllegalStateException!");
+            result = false;
+        }
+
+        /* test calls in open state.
+         */
+        seq.open();
+        if (! seq.isOpen()) {
+            out("Sequencer is not open, cannot test!");
+            return result;
+        }
+
+        try {
+            seq.start();
+        } catch (IllegalStateException e) {
+            out("open state: start() throws IllegalStateException!");
+            result = false;
+        }
+
+        try {
+            seq.stop();
+        } catch (IllegalStateException e) {
+            out("open state: stop() throws IllegalStateException!");
+            result = false;
+        }
+
+        try {
+            seq.startRecording();
+        } catch (IllegalStateException e) {
+            out("open state: startRecording() throws IllegalStateException!");
+            result = false;
+        }
+
+        try {
+            seq.stopRecording();
+        } catch (IllegalStateException e) {
+            out("open state: stopRecording() throws IllegalStateException!");
+            result = false;
+        }
+
+        sequence = createSequence();
+        if (sequence == null) {
+            out("created Sequence is null, cannot test!");
+            return result;
+        }
+        try {
+            seq.setSequence(sequence);
+        } catch (IllegalStateException e) {
+            out("open state: setSequence(Sequence) throws IllegalStateException!");
+            result = false;
+        }
+
+        inputStream = createSequenceInputStream();
+        if (inputStream == null) {
+            out("created InputStream is null, cannot test!");
+            return result;
+        }
+        try {
+            seq.setSequence(inputStream);
+        } catch (IllegalStateException e) {
+            out("open state: setSequence(InputStream) throws IllegalStateException!");
+            result = false;
+        }
+
+        try {
+            seq.getSequence();
+        } catch (IllegalStateException e) {
+            out("open state: getSequence() throws IllegalStateException!");
+            result = false;
+        }
+
+        seq.close();
+        return result;
+    }
+
+    /**
+     * Create a new Sequence for testing.
+     *
+     * @return a dummy Sequence, or null, if a problem occured while creating
+     *         the Sequence
+     */
+    private static Sequence createSequence() {
+        Sequence sequence = null;
+        try {
+            sequence = new Sequence(Sequence.PPQ, 480, 1);
+        } catch (InvalidMidiDataException e) {
+            // DO NOTHING
+        }
+        return sequence;
+    }
+
+    /**
+     * Create a new InputStream containing a Sequence for testing.
+     *
+     * @return an InputStream containing a dummy Sequence, or null, if a problem
+     *         occured while creating the InputStream
+     */
+    private static InputStream createSequenceInputStream() {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        Sequence sequence = createSequence();
+        if (sequence == null) {
+            return null;
+        }
+        try {
+            MidiSystem.write(sequence, 0, baos);
+            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+            return bais;
+        } catch (IOException e) {
+            return null;
+        }
+    }
+
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequencer/SetTickPosition.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 4493775
+ * @summary Sequncer method, setTickPosition(long) doesnot set the Tick position
+ */
+public class SetTickPosition {
+        private static boolean testPassed = true;
+
+        public void runTest()
+        {
+            Sequencer theSequencer = null;
+            try
+            {
+                System.out.print("Getting Sequencer...");
+                theSequencer = MidiSystem.getSequencer();
+                System.out.println("got "+theSequencer);
+
+                if(!(theSequencer.isOpen()))
+                {
+                    System.out.println("Opening Sequencer...");
+                    theSequencer.open();
+
+                    if(!(theSequencer.isOpen()))
+                    {
+                        System.out.println("Unable to open the Sequencer. Test NOT FAILED.");
+                        return;
+                    }
+                }
+
+                System.out.println("theSequencer is open!\n");
+
+                System.out.println("Creating New Sequence...");
+                Sequence theSequence = new Sequence(Sequence.PPQ, 120);
+
+                System.out.println("Adding Track To Sequence...");
+                Track theTrack = theSequence.createTrack();
+
+                int theChannel = 0;
+
+                int theNote = 60;
+                int theVelocity = 100;
+                ShortMessage theShortMessage = new ShortMessage();
+
+                for (int tick=0; tick<2000; tick+=120) {
+                    //System.out.println("Adding NOTE_ON To Track At Tick: " + tick + "...\n");
+                    theShortMessage.setMessage(ShortMessage.NOTE_ON, theChannel, theNote, theVelocity);
+                    MidiEvent theMidiEvent = new MidiEvent(theShortMessage, tick);
+                    theTrack.add(theMidiEvent);
+
+                    //System.out.println("Adding NOTE_OFF To Track At Tick: " + (tick+60) + "...\n");
+                    theShortMessage.setMessage(ShortMessage.NOTE_OFF, theChannel, theNote, theVelocity);
+                    theMidiEvent = new MidiEvent(theShortMessage, tick+60);
+                    theTrack.add(theMidiEvent);
+                }
+                theSequencer.setSequence(theSequence);
+
+                float theTempoInBPM = 120;
+                theSequencer.setTempoInBPM(theTempoInBPM);
+                long theTickLengthOfSequence = theSequencer.getTickLength();
+                System.out.println("Length Of Sequence In Ticks: " + theTickLengthOfSequence);
+                System.out.println("Sequence resolution: " + theSequencer.getSequence().getResolution());
+
+                theSequencer.start();
+                for(long theTickPosition = 0; theTickPosition < theTickLengthOfSequence; theTickPosition += (theTickLengthOfSequence / 10))
+                {
+                    System.out.println("Now Setting Tick Position To: " + theTickPosition);
+                    theSequencer.setTickPosition(theTickPosition);
+
+                    long theCurrentTickPosition = theSequencer.getTickPosition();
+                    long theCurrentMsPosition = (long) (theSequencer.getMicrosecondPosition()/1000);
+                    System.out.println("IsRunning()=" + theSequencer.isRunning());
+                    System.out.println("Now Current Tick Position Is: " + theCurrentTickPosition);
+                    //System.out.println("Now Current micro Position Is: " + theCurrentMsPosition);
+                    System.out.println("");
+
+                    try {
+                        Thread.sleep(800);
+                    } catch (InterruptedException ie) {}
+
+                    // last time, set tick pos to 0
+                    if (theTickPosition>0 && theTickPosition<(theTickLengthOfSequence / 10)) {
+                        theTickPosition=(theTickLengthOfSequence / 10);
+                    }
+
+                    // 30 = 1/4 * 120, the resolution of the sequence
+                    if(Math.abs(theCurrentTickPosition - theTickPosition) > 30) {
+                        System.out.println("theCurrentTickPosition != theTickPosition!");
+                        testPassed = false;
+                    }
+                }
+
+            }
+            catch (Exception ex) { ex.printStackTrace(); }
+            if (theSequencer != null) {
+                theSequencer.close();
+            }
+            if (testPassed) {
+                System.out.println("Test Passed.");
+            }
+        }
+
+    public static void main(String[] args) throws Exception {
+        SetTickPosition thisTest = new SetTickPosition();
+        thisTest.runTest();
+        if (!testPassed) {
+            throw new Exception("Test FAILED");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Sequencer/TickLength.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MetaEventListener;
+import javax.sound.midi.MetaMessage;
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 4427890
+ * @run main/othervm TickLength
+ * @summary Sequencer.getTickLength() and Sequence.getTickLength() report the
+ *          wrong length
+ */
+public class TickLength implements MetaEventListener {
+    private Sequence          theSequence;
+    private Sequencer         theSequencer;
+
+    public TickLength() {
+     this.initMidiCompoments();
+     System.out.println("Got Sequencer "+theSequencer);
+     theSequence = this.generateSequence();
+     try {
+       theSequencer.setSequence(theSequence);
+     }
+     catch(Exception e) {
+       System.out.println(this.getClass()+"\tCannot set sequence to sequencer ("+e+")");
+       return;
+     }
+    }
+
+    public  void start() {
+     theSequencer.start();
+    }
+
+    /*
+     instantiate the necessary midi components
+    */
+    private boolean initMidiCompoments() {
+
+
+     try {
+       theSequencer = MidiSystem.getSequencer();
+     }
+     catch(Exception e) {
+       System.out.println(this.getClass()+"\tSequencer Device not supported"+e+")");
+       return false;
+     }
+
+     try {
+       theSequencer.open();
+     }
+     catch(Exception e) {
+       System.out.println(this.getClass()+"Cannot open Sequencer Device");
+       return false;
+     }
+     if(!theSequencer.addMetaEventListener(this)) {
+       System.out.println(this.getClass()+"\tCould not register MetaEventListener - there will be problems with scrolling! ");
+       return false;
+     }
+     return true;
+    }
+
+    static int lastTick = 0;
+
+    private Sequence generateSequence() {
+     MidiEvent dummyMidiEvent;
+     ShortMessage dummyShortMessage;
+     Sequence dummySequence        = null;
+     Track[] allTracks ;
+     Track theTrack;
+
+     try {
+       dummySequence = new Sequence(Sequence.PPQ,1500);
+     }
+     catch(InvalidMidiDataException e) {
+       System.out.println("O o "+e);
+     }
+
+     dummySequence.createTrack();
+     allTracks = dummySequence.getTracks();
+     theTrack = allTracks[0];
+    lastTick = 0;
+     for(int i=0;i<20; i++) {
+       theTrack.add(this.createShortMidiEvent(ShortMessage.NOTE_ON, 2, 30+i, 100,100+1000*i));
+       theTrack.add(this.createMetaMidiEvent(1,"start",100+1000*i));
+       lastTick = (1000*i)+600;
+       theTrack.add(this.createShortMidiEvent(ShortMessage.NOTE_OFF, 2, 30+i, 100, lastTick));
+       theTrack.add(this.createMetaMidiEvent(1,"end",lastTick));
+     }
+
+     return dummySequence;
+    }
+
+    /*
+     A method to create a short midi event (sound)
+    */
+
+    public MidiEvent createShortMidiEvent(int theCommand, int theChannel, int theData1, int theData2, long theTime) {
+     ShortMessage dummyShortMessage;
+     MidiEvent    dummyMidiEvent;
+
+     try {
+       dummyShortMessage = new ShortMessage();
+       dummyShortMessage.setMessage(theCommand, theChannel, theData1, theData2);
+       dummyMidiEvent    = new MidiEvent(dummyShortMessage,theTime);
+     }
+     catch (Exception e) {
+       System.out.println(this.getClass()+"\t"+e);
+       return null;
+     }
+
+     return dummyMidiEvent;
+    }
+
+    /*
+     A method to create a meta midi event (used in  meta() method)
+    */
+    public MidiEvent createMetaMidiEvent(int theType, String theData1, long theTime) {
+     MetaMessage  dummyMetaMessage;
+     MidiEvent    dummyMidiEvent;
+
+     try {
+       dummyMetaMessage = new MetaMessage();
+       dummyMetaMessage.setMessage(theType, theData1.getBytes(), theData1.length());
+       dummyMidiEvent    = new MidiEvent(dummyMetaMessage,theTime);
+     }
+     catch (Exception e) {
+       System.out.println(e);
+       return null;
+     }
+
+     return dummyMidiEvent;
+    }
+
+    /*
+     the method is activated by each meta midi event
+     it puts out the actual tick position, as well as the WRONG total tick length and the RIGHT
+     tick length using the work around by dividing the total length by 64
+    */
+    public void meta(MetaMessage p1) {
+     if(p1.getType() ==47) {
+       return;
+     }
+     System.out.println("getTickPosition:\t"+theSequencer.getTickPosition()
+         +"\t Sequencer.getTickLength:\t"+theSequencer.getTickLength()
+         +"\tReal Length:\t"+lastTick
+         +"\t Sequence.getTickLength:\t"+theSequence.getTickLength()
+         //(theSequencer.getTickLength()/64));
+         );
+    }
+
+    public void checkLengths() throws Exception {
+        System.out.println("Sequencer.getTickLength() = "+theSequencer.getTickLength());
+        System.out.println("Sequence.getTickLength() = "+theSequence.getTickLength());
+        long diff = theSequencer.getTickLength() - theSequence.getTickLength();
+        if (diff > 100 || diff < -100) {
+                throw new Exception("Difference too large! Failed.");
+        }
+        System.out.println("Passed");
+    }
+
+    public static void main(String[] args) throws Exception {
+        if (!hasSequencer()) {
+            return;
+        }
+         TickLength tlt = new TickLength();
+         //tlt.start();
+         tlt.checkLengths();
+    }
+
+    static boolean hasSequencer() {
+        try {
+            Sequencer seq = MidiSystem.getSequencer();
+            if (seq != null) {
+                seq.open();
+                seq.close();
+                return true;
+            }
+        } catch (Exception e) {}
+        System.out.println("No sequencer available! Cannot execute test.");
+        return false;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/ShortMessage/FastShortMessage.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 4851018
+ * @summary MidiMessage.getLength and .getData return wrong values.
+ *          also: 4890405: Reading MidiMessage byte array fails in 1.4.2
+ */
+public class FastShortMessage {
+    public static void main(String args[]) throws Exception {
+        int[] dataMes =  {ShortMessage.NOTE_ON | 9, 0x24, 0x50};
+        int res = 240;
+        Sequence midiData = new Sequence(Sequence.PPQ, res);
+
+        Track track = midiData.createTrack();
+        ShortMessage msg = new ShortMessage();
+        msg.setMessage(dataMes[0], dataMes[1], dataMes[2]);
+        track.add(new MidiEvent(msg, 0));
+
+        // save sequence to outputstream
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        MidiSystem.write(midiData, 0, baos);
+
+        // reload that sequence
+        InputStream is = new ByteArrayInputStream(baos.toByteArray());
+        Sequence seq = MidiSystem.getSequence(is);
+
+        track = seq.getTracks()[0];
+        msg = (ShortMessage) (track.get(0).getMessage());
+        byte[] msgData = msg.getMessage();
+
+        if (msgData.length != dataMes.length
+         || (msgData[0] & 0xFF) != dataMes[0]
+         || (msgData[1] & 0xFF) != dataMes[1]
+         || (msgData[2] & 0xFF) != dataMes[2]) {
+            throw new Exception("test failed. read length="+msgData.length);
+        }
+        System.out.println("Test Passed.");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/ShortMessage/FastShortMessage2.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 5011306
+ * @summary FastShortMessage.setMessage does not use the data2 parameter
+ */
+public class FastShortMessage2 {
+
+    public static void main(String args[]) throws Exception {
+        int[] dataMes =  {ShortMessage.NOTE_ON | 9, 0x24, 0x50};
+
+        Sequence midiData = new Sequence(Sequence.PPQ, 240);
+        Track track = midiData.createTrack();
+        ShortMessage msg = new ShortMessage();
+        msg.setMessage(dataMes[0], dataMes[1], dataMes[2]);
+        track.add(new MidiEvent(msg, 0));
+        // save sequence to outputstream
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        MidiSystem.write(midiData, 0, baos);
+        // reload that sequence
+        InputStream is = new ByteArrayInputStream(baos.toByteArray());
+        Sequence seq = MidiSystem.getSequence(is);
+        track = seq.getTracks()[0];
+        msg = (ShortMessage) (track.get(0).getMessage());
+        if (!msg.getClass().toString().contains("FastShortMessage")) {
+            System.out.println("msg is not FastShortMessage, this test is useless then..."+msg.getClass());
+        }
+
+        msg.setMessage(dataMes[0], dataMes[1], dataMes[2]);
+        byte[] msgData = msg.getMessage();
+
+        if (msgData.length != dataMes.length
+         || (msgData[0] & 0xFF) != dataMes[0]
+         || (msgData[1] & 0xFF) != dataMes[1]
+         || (msgData[2] & 0xFF) != dataMes[2]) {
+            System.out.println("status="+(msgData[0] & 0xFF)+" and expected "+dataMes[0]);
+            System.out.println("data1="+(msgData[1] & 0xFF)+" and expected "+dataMes[1]);
+            System.out.println("data2="+(msgData[2] & 0xFF)+" and expected "+dataMes[2]);
+            throw new Exception("Test FAILED!");
+        }
+        System.out.println("Test Passed.");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Soundbanks/ExtraCharInSoundbank.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.Instrument;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Soundbank;
+import javax.sound.midi.Synthesizer;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Mixer;
+
+/**
+ * @test
+ * @bug 4429762
+ * @summary Some instrument names in some soundbanks include bad extra characters
+ */
+public class ExtraCharInSoundbank {
+
+    private static void printName(String loadedName)
+    {
+        System.out.println("Loaded Name: " + loadedName);
+        byte[] theLoadedNameByteArray = loadedName.getBytes();
+
+        System.out.print("Name Bytes: ");
+        for(int i = 0; i < theLoadedNameByteArray.length; i++)
+            System.out.print((Integer.toHexString((int)theLoadedNameByteArray[i]).toUpperCase()) + " ");
+        System.out.println("");
+        System.out.println("");
+    }
+
+    private static boolean containsControlChar(String name) {
+        byte[] bytes = name.getBytes();
+        for (int i = 0; i < bytes.length; i++) {
+            if (bytes[i] < 32) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static boolean checkInstrumentNames(Synthesizer theSynthesizer)
+    {
+        boolean containsControlCharacters = false;
+
+        Instrument[] theLoadedInstruments = theSynthesizer.getLoadedInstruments();
+
+        System.out.println("Checking soundbank...");
+        for(int theInstrumentIndex = 0; theInstrumentIndex < theLoadedInstruments.length; theInstrumentIndex++) {
+            String name = theLoadedInstruments[theInstrumentIndex].getName();
+            if (containsControlChar(name)) {
+                containsControlCharacters = true;
+                System.out.print("Instrument[" + theInstrumentIndex + "] contains unexpected control characters: ");
+                printName(name);
+            }
+        }
+        return !containsControlCharacters;
+    }
+
+    public static void main(String[] args) throws Exception {
+        // the internal synthesizer needs a soundcard to work properly
+        if (!isSoundcardInstalled()) {
+            return;
+        }
+        Synthesizer theSynth = MidiSystem.getSynthesizer();
+        System.out.println("Got synth: "+theSynth);
+        theSynth.open();
+        try {
+            Soundbank theSoundbank = theSynth.getDefaultSoundbank();
+            System.out.println("Got soundbank: "+theSoundbank);
+            theSynth.loadAllInstruments(theSoundbank);
+            try {
+                    if (!checkInstrumentNames(theSynth)) {
+                            throw new Exception("Test failed");
+                    }
+            } finally {
+                    theSynth.unloadAllInstruments(theSoundbank);
+            }
+        } finally {
+            theSynth.close();
+        }
+        System.out.println("Test passed.");
+    }
+
+    /**
+     * Returns true if at least one soundcard is correctly installed
+     * on the system.
+     */
+    public static boolean isSoundcardInstalled() {
+        boolean result = false;
+        try {
+            Mixer.Info[] mixers = AudioSystem.getMixerInfo();
+            if (mixers.length > 0) {
+                result = AudioSystem.getSourceDataLine(null) != null;
+            }
+        } catch (Exception e) {
+            System.err.println("Exception occured: "+e);
+        }
+        if (!result) {
+            System.err.println("Soundcard does not exist or sound drivers not installed!");
+            System.err.println("This test requires sound drivers for execution.");
+        }
+        return result;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Soundbanks/GetSoundBankIOException.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MidiSystem;
+
+/**
+ * @test
+ * @bug 4629810
+ * @summary MidiSystem.getSoundbank() throws unexpected IOException
+ */
+public class GetSoundBankIOException {
+
+    public static void main(String args[]) throws Exception {
+        boolean failed = false;
+        try {
+            String filename = "GetSoundBankIOException.java";
+            System.out.println("Opening "+filename+" as soundbank...");
+            File midiFile = new File(System.getProperty("test.src", "."), filename);
+            MidiSystem.getSoundbank(midiFile);
+            //Soundbank sBank = MidiSystem.getSoundbank(new NonMarkableIS());
+            System.err.println("InvalidMidiDataException was not thrown!");
+            failed = true;
+        } catch (InvalidMidiDataException invMidiEx) {
+            System.err.println("InvalidMidiDataException was thrown. OK.");
+        } catch (IOException ioEx) {
+            System.err.println("Unexpected IOException was caught!");
+            System.err.println(ioEx.getMessage());
+            ioEx.printStackTrace();
+            failed = true;
+        }
+
+        if (failed) throw new Exception("Test FAILED!");
+        System.out.println("Test passed.");
+    }
+
+    private static class NonMarkableIS extends InputStream {
+        int counter = 0;
+
+        public NonMarkableIS() {
+        }
+
+        public int read() throws IOException {
+            if (counter > 1000) return -1;
+            return (++counter) % 256;
+        }
+
+        public synchronized void mark(int readlimit) {
+            System.out.println("Called mark with readlimit= "+readlimit);
+        }
+
+        public synchronized void reset() throws IOException {
+            throw new IOException("mark/reset not supported");
+        }
+
+        public boolean markSupported() {
+            return false;
+        }
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Synthesizer/AsynchronousMidiChannel.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.PrintStream;
+
+import javax.sound.midi.Instrument;
+import javax.sound.midi.MidiChannel;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Soundbank;
+import javax.sound.midi.Synthesizer;
+
+/**
+ * @test
+ * @bug 4987585
+ * @summary Some MidiChannel methods are asynchronous
+ */
+public class AsynchronousMidiChannel {
+    static PrintStream log = System.err;
+    static PrintStream ref = System.out;
+
+    public static void main(String args[]) {
+        doIt(args);
+    }
+
+    public static void doIt(String args[]) {
+        Synthesizer synth = null;
+        MidiChannel mChanArr[];
+        MidiChannel chan = null;
+        boolean failed = false;
+        int i = 0;
+        int chanNum = 0;
+
+        int val = 1;
+        int contr = 0;
+        Soundbank sBank;
+        Instrument[] insArr;
+        Instrument instr = null;
+        Object ev = new Object();
+
+        try {
+            synth = MidiSystem.getSynthesizer();
+            System.out.println("Got synth: "+synth);
+            synth.open();
+
+            int latency = (int) synth.getLatency();
+            System.out.println("  -> latency: "
+                               +latency
+                               +" microseconds");
+
+            mChanArr = synth.getChannels();
+            while ((i < mChanArr.length) && (chan == null)) {
+                chanNum = i;
+                chan = mChanArr[i++];
+            }
+            if (chan == null) {
+                System.out.println("No channels in "
+                                   +"this synthesizer!");
+                return;
+            }
+            System.out.println("Got MidiChannel: "+chan);
+
+
+            sBank = synth.getDefaultSoundbank();
+            if (sBank == null) {
+                System.out.println("No default sound bank!");
+                return;
+            }
+
+
+            insArr = sBank.getInstruments();
+            for (int j = 0; j < insArr.length; j++) {
+                if (insArr[j].getPatch().getBank() == val) {
+                    instr = insArr[j];
+                    synth.loadInstrument(instr);
+                }
+            }
+            if (instr == null) {
+                System.out.println("No instr. with this bank!");
+                return;
+            }
+
+            chan.controlChange(contr, val);
+
+            // need to respect the synthesizer's latency
+            if (latency > 0) {
+                try {
+                    Thread.sleep(latency/1000);
+                } catch (InterruptedException inEx) {
+                }
+            }
+
+            if (chan.getController(contr) != val) {
+                failed = true;
+                System.err.println("getController() does not "
+                                   +"return proper value: "
+                + chan.getController(contr));
+            }  else {
+                System.out.println("getController("
+                + contr + ") returns proper value: "
+                + chan.getController(contr));
+            }
+
+        } catch (MidiUnavailableException mue) {
+            System.err.println("MidiUnavailableException was "
+                               +"thrown: " + mue);
+            System.out.println("could not test.");
+            return;
+        } catch(SecurityException se) {
+            se.printStackTrace();
+            System.err.println("Sound access is not denied but "
+            + "SecurityException was thrown!");
+            return;
+
+        } finally {
+            if (synth != null) synth.close();
+        }
+
+
+        if (failed == true) {
+            System.out.println("test failed");
+        } else {
+            System.out.println("OKAY");
+        }
+        return;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Synthesizer/Receiver/bug6186488.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiMessage;
+import javax.sound.midi.MidiSystem;
+
+/**
+ * @test
+ * @bug 6186488
+ * @summary Tests that software Java Syntesizer processed
+ *          non-ShortMessage-derived messages
+ * @run main/manual=yesno bug6186488
+ */
+public class bug6186488 {
+    public static void main(String[] args) throws Exception {
+        MidiDevice/*Synthesizer*/ synth = null;
+
+        try {
+            synth = MidiSystem.getSynthesizer();
+            //synth = MidiSystem.getMidiDevice(infos[0]);
+
+            System.out.println("Synthesizer: " + synth.getDeviceInfo());
+            synth.open();
+            MidiMessage msg = new GenericMidiMessage(0x90, 0x3C, 0x40);
+            //ShortMessage msg = new ShortMessage();
+            //msg.setMessage(0x90, 0x3C, 0x40);
+
+            synth.getReceiver().send(msg, 0);
+            Thread.sleep(2000);
+
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            throw ex;
+        } finally {
+            if (synth != null && synth.isOpen())
+                synth.close();
+        }
+        System.out.print("Did you heard a note? (enter 'y' or 'n') ");
+        int result = System.in.read();
+        System.in.skip(1000);
+        if (result == 'y' || result == 'Y')
+        {
+            System.out.println("Test passed sucessfully.");
+        }
+        else
+        {
+            System.out.println("Test FAILED.");
+            throw new RuntimeException("Test failed.");
+        }
+    }
+
+    private static class GenericMidiMessage extends MidiMessage {
+        GenericMidiMessage(int... message) {
+            super(new byte[message.length]);
+            for (int i=0; i<data.length; i++) {
+                data[i] = (byte)(0xFF & message[i]);
+            }
+        }
+
+        GenericMidiMessage(byte... message) {
+            super(message);
+        }
+
+        public Object clone() {
+            return new GenericMidiMessage((byte[])data.clone());
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Synthesizer/SynthesizerGetLatency.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Synthesizer;
+
+/**
+ * @test
+ * @bug 5029790
+ * @summary Synthesizer.getLatency returns wrong value
+ */
+public class SynthesizerGetLatency {
+
+    public static void main(String args[]) throws Exception {
+        Synthesizer synth = null;
+        boolean failed = false;
+        boolean notexec = false;
+        try {
+            synth = MidiSystem.getSynthesizer();
+            System.out.println("Got synth: "+synth);
+            synth.open();
+
+            int latency = (int) synth.getLatency();
+            System.out.println("  -> latency: "
+                               +latency
+                               +" microseconds");
+            if (latency < 5000 && latency > 0) {
+                System.out.println("## This latency is VERY small, probably due to this bug.");
+                System.out.println("## This causes failure of this test.");
+                failed = true;
+            }
+        } catch (MidiUnavailableException mue) {
+            System.err.println("MidiUnavailableException was "
+                               +"thrown: " + mue);
+            System.out.println("could not test.");
+            notexec = true;
+        } catch(SecurityException se) {
+            se.printStackTrace();
+            System.err.println("Sound access is not denied but "
+            + "SecurityException was thrown!");
+            notexec = true;
+        } finally {
+            if (synth != null) synth.close();
+        }
+
+
+        if (failed) {
+            throw new Exception("Test FAILED!");
+        }
+        if (notexec) {
+            System.out.println("Test not failed.");
+        } else {
+            System.out.println("Test Passed.");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Synthesizer/bug4685396.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,218 @@
+/*
+ * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.Instrument;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Soundbank;
+import javax.sound.midi.Synthesizer;
+
+/**
+ * @test
+ * @bug 4685396
+ * @summary Tests that Synthesizer.remapInstrument works
+ * @run main bug4685396
+ * @key headful
+ */
+public class bug4685396 {
+
+    static Synthesizer synth = null;
+
+    public static boolean isInstrumentExist(Instrument inst, Instrument[] insts) {
+        for (int i = 0; i < insts.length; i++) {
+            if (inst.equals(insts[i]))
+                return true;
+        }
+        return false;
+    }
+
+    static boolean test(
+            boolean reloadInstr,    // reload all instruments?
+            boolean unloadFrom,     // unload "from" instrument?
+            boolean unloadTo        // unload "to" instrument?
+            ) throws Exception
+    {
+        log("Starting test: reloadInstr=" + reloadInstr
+                + ", unloadFrom=" + unloadFrom
+                + ", unloadTo=" + unloadTo
+                + "");
+
+        log("  creating synthesizer...");
+        synth = MidiSystem.getSynthesizer();
+        log("  opening synthesizer...");
+        synth.open();
+
+        Soundbank sbank = synth.getDefaultSoundbank();
+        if (sbank == null)
+            throw new RuntimeException("ERROR: Could not get default soundbank");
+
+        if (reloadInstr) {
+            synth.unloadAllInstruments(sbank);
+            synth.loadAllInstruments(sbank);
+        }
+
+        Instrument[] instrs = synth.getLoadedInstruments();
+
+        log("  " + instrs.length + " instruments loaded.");
+
+        if (instrs.length < 2)
+            throw new RuntimeException("ERROR: need at least 2 loaded instruments");
+
+        Instrument from = instrs[0];
+        Instrument to = instrs[instrs.length - 1];
+
+        if (unloadFrom)
+            synth.unloadInstrument(from);
+        if (unloadTo)
+            synth.unloadInstrument(to);
+
+        log("  from instrument (" + (unloadFrom ? "UNLOADED" : "LOADED")
+                                + "): " + from.toString());
+        log("  to instrument (" + (unloadTo ? "UNLOADED" : "LOADED")
+                                + "): " + to.toString());
+
+        boolean result = false;
+        boolean excepted = false;
+        try {
+            result = synth.remapInstrument(from, to);
+            log("  remapInstrument(from, to) returns " + result);
+        } catch (IllegalArgumentException ex) {
+            excepted = true;
+            log("  EXCEPTION:");
+            ex.printStackTrace(System.out);
+        }
+
+        instrs = synth.getLoadedInstruments();
+        log("  " + instrs.length + " instruments remains loaded.");
+
+        boolean toUnloaded = !isInstrumentExist(to, instrs);
+        boolean fromUnloaded = !isInstrumentExist(from, instrs);
+
+        log("  from instrument is " + (fromUnloaded ? "UNLOADED" : "LOADED"));
+        log("  to instrument is " + (toUnloaded ? "UNLOADED" : "LOADED"));
+
+        boolean bOK = true;
+        if (result) {
+            if (unloadTo) {
+                bOK = false;
+                log("ERROR: unloaded to, but sucessfull remap");
+            }
+            if (!fromUnloaded) {
+                bOK = false;
+                log("ERROR: sucessfull remap, but from hasn't been unloaded");
+            }
+            if (toUnloaded) {
+                bOK = false;
+                log("ERROR: to has been unloaded!");
+            }
+        } else {
+            if (!excepted) {
+                bOK = false;
+                log("ERROR: remap returns false, exception hasn't been thrown");
+            }
+            if (!unloadTo) {
+                bOK = false;
+                log("ERROR: to is loaded, but remap returns false");
+            }
+            if (unloadFrom != fromUnloaded) {
+                bOK = false;
+                log("ERROR: remap returns false, but status of from has been changed");
+            }
+        }
+
+        if (bOK) {
+            log("Test result: OK\n");
+        } else {
+            log("Test result: FAIL\n");
+        }
+
+        return bOK;
+    }
+
+    static void cleanup() {
+        if (synth != null) {
+            synth.close();
+            synth = null;
+        }
+    }
+
+    static boolean runTest(
+            boolean reloadInstr,    // reload all instruments?
+            boolean unloadTo,       // unload "to" instrument?
+            boolean unloadFrom      // unload "from" instrument?
+            )
+    {
+        boolean success = false;
+        try {
+            success = test(reloadInstr, unloadFrom, unloadTo);
+        } catch (Exception ex) {
+            log("Exception: " + ex.toString());
+        }
+        cleanup();
+        return success;
+    }
+
+    public static void main(String args[]) throws Exception {
+        boolean failed = false;
+        if (!runTest(true, false, false))
+            failed = true;
+        if (!runTest(true, false, true))
+            failed = true;
+        if (!runTest(true, true, false))
+            failed = true;
+        if (!runTest(true, true, true))
+            failed = true;
+
+        if (failed) {
+            throw new RuntimeException("Test FAILED.");
+        }
+        log("Test sucessfully passed.");
+    }
+
+
+    // helper routines
+    static long startTime = currentTimeMillis();
+    static long currentTimeMillis() {
+        //return System.nanoTime() / 1000000L;
+        return System.currentTimeMillis();
+    }
+    static void log(String s) {
+        long time = currentTimeMillis() - startTime;
+        long ms = time % 1000;
+        time /= 1000;
+        long sec = time % 60;
+        time /= 60;
+        long min = time % 60;
+        time /= 60;
+        System.out.println(""
+                + (time < 10 ? "0" : "") + time
+                + ":" + (min < 10 ? "0" : "") + min
+                + ":" + (sec < 10 ? "0" : "") + sec
+                + "." + (ms < 10 ? "00" : (ms < 100 ? "0" : "")) + ms
+                + " (" + Thread.currentThread().getName() + ") " + s);
+    }
+    static void delay(int millis) {
+        try {
+            Thread.sleep(millis);
+        } catch (InterruptedException e) {}
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Track/TrackAddSameTick.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.ShortMessage;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 4941944
+ * @summary Track may not have a determined order for inserting events at same
+ *          tick time
+ */
+public class TrackAddSameTick {
+
+    static boolean failed = false;
+    static MidiEvent[] evs = new MidiEvent[10];
+
+    public static void main(String argv[]) throws Exception {
+        Sequence seq = new Sequence(Sequence.PPQ, 240);
+        Track t = seq.createTrack();
+
+        log("add 10 events in random order");
+        t.add(createEvent(10, 5));
+        t.add(createEvent(0, 0));
+        t.add(createEvent(10, 6));
+        t.add(createEvent(11, 8));
+        t.add(createEvent(10, 7));
+        t.add(createEvent(0, 1));
+        t.add(createEvent(0, 2));
+        t.add(createEvent(15, 9));
+        t.add(createEvent(0, 3));
+        t.add(createEvent(1, 4));
+
+        // now compare the events.
+        // The note param will tell us the
+        // the expected position
+        long lastTick = 0;
+        for (int i = 0; i < t.size(); i++) {
+            MidiEvent ev = t.get(i);
+            if (ev.getMessage() instanceof ShortMessage) {
+                ShortMessage msg = (ShortMessage) ev.getMessage();
+                log(""+i+": ShortMessage at tick "+ev.getTick()
+                    +" with expected position "+msg.getData1());
+                if (ev.getTick() < lastTick) {
+                    log("  FAILED: last tick is larger than this event's tick!");
+                    failed = true;
+                }
+                if (i != msg.getData1()) {
+                    log("  FAILED: Track did not order correctly.");
+                    failed = true;
+                }
+            }
+        }
+
+        if (failed) throw new Exception("Test FAILED!");
+        log("Test passed.");
+    }
+
+    public static MidiEvent createEvent(long tick, int expectedPos)
+        throws Exception {
+        ShortMessage msg = new ShortMessage();
+        msg.setMessage(0x90, (int) expectedPos, 00);
+        MidiEvent ev = new MidiEvent(msg, tick);
+        return ev;
+    }
+
+    public static void log(String s) {
+        System.out.println(s);
+    }
+
+    public static void log(Exception e) {
+        //System.out.println(s);
+        e.printStackTrace();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Track/bug6416024.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MetaMessage;
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Track;
+
+/**
+ * @test
+ * @bug 6416024
+ * @summary Tests that sequence correctly handle removing of EndOfTrack event
+ * @run main bug6416024
+ */
+public class bug6416024 {
+
+    boolean test() {
+        Sequence sequence = null;
+        Track track = null;
+        MidiEvent event = null;
+
+        log("creating sequence...");
+        try {
+            sequence = new Sequence(Sequence.PPQ, 10);
+            log("  - OK: " + sequence);
+        } catch(InvalidMidiDataException e ) {
+            log("  - FAILED: got exception");
+            e.printStackTrace(System.out);
+            return false;
+        }
+
+        log("creating track...");
+        track = sequence.createTrack();
+        log("  - OK: " + track);
+        log("initial track size=" + track.size());
+
+        log("removing all track events...");
+        while (track.size() > 0) {
+            try {
+                event = track.get(0);
+                log("  ..removing event " + event);
+                track.remove(event);
+                log("    - OK, track size=" + track.size());
+            } catch (Exception e) {
+                log("  - FAILED: got exception");
+                e.printStackTrace(System.out);
+                return false;
+            }
+        }
+
+        MetaMessage newMsg = new MetaMessage();
+        MidiEvent newEvent = new MidiEvent(newMsg, 10);
+        log("adding new event...");
+        try {
+            if (!track.add(newEvent)) {
+                log("event hasn't been added");
+                return false;
+            }
+            log("    - OK, track size=" + track.size());
+        } catch (Exception e) {
+            log("  - FAILED: got exception");
+            e.printStackTrace(System.out);
+            return false;
+        }
+
+        return true;
+    }
+
+    public static void main(String args[]) throws Exception {
+        bug6416024 This = new bug6416024();
+        if (This.test()) {
+            log("Test passed sucessfully.");
+        } else {
+            log("Test FAILED!");
+            delay(1000);
+            throw new RuntimeException("Test failed!");
+        }
+    }
+
+    // helper routines
+    static long startTime = currentTimeMillis();
+    static long currentTimeMillis() {
+        //return System.nanoTime() / 1000000L;
+        return System.currentTimeMillis();
+    }
+    static void log(String s) {
+        long time = currentTimeMillis() - startTime;
+        long ms = time % 1000;
+        time /= 1000;
+        long sec = time % 60;
+        time /= 60;
+        long min = time % 60;
+        time /= 60;
+        System.out.println(""
+                + (time < 10 ? "0" : "") + time
+                + ":" + (min < 10 ? "0" : "") + min
+                + ":" + (sec < 10 ? "0" : "") + sec
+                + "." + (ms < 10 ? "00" : (ms < 100 ? "0" : "")) + ms
+                + " (" + Thread.currentThread().getName() + ") " + s);
+    }
+    static void delay(int millis) {
+        try {
+            Thread.sleep(millis);
+        } catch (InterruptedException e) {}
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/Transmitter/bug6415669.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Transmitter;
+
+/**
+ * @test
+ * @bug 6415669
+ * @summary Tests that terminating thread which got transmitter doesn't cause
+ *          JVM crash (windows)
+ * @run main bug6415669
+ */
+public class bug6415669 {
+
+    public static void main(String args[]) throws Exception {
+        String osStr = System.getProperty("os.name");
+        boolean isWin = osStr.toLowerCase().startsWith("windows");
+        log("OS: " + osStr);
+        log("Arch: " + System.getProperty("os.arch"));
+        if (!isWin) {
+            log("The test is for Windows only");
+            return;
+        }
+
+        bug6415669 This = new bug6415669();
+        if (This.test()) {
+            log("Test sucessfully passed.");
+        } else {
+            log("Test FAILED!");
+            throw new RuntimeException("Test FAILED!");
+        }
+    }
+
+    volatile Transmitter transmitter = null;
+    Thread openThread = null;
+    boolean test() {
+        openThread = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    log("openThread: getting transmitter...");
+                    transmitter = MidiSystem.getTransmitter();
+                    log("openThread:   - OK: " + transmitter);
+                } catch (MidiUnavailableException ex) {
+                    log("openThread:   - Exception: ");
+                    ex.printStackTrace(System.out);
+                    log("openThread: skipping...");
+                }
+                log("openThread: exiting...");
+            }
+        });
+        log("starting openThread...");
+        openThread.start();
+
+        while (openThread.isAlive())
+            delay(500);
+        // make additional delay
+        delay(500);
+
+        if (transmitter == null) {
+            return true;   // midi is not available, just ignore
+        }
+
+        log("closing transmitter");
+        transmitter.close();
+        log("  - OK");
+
+        return true;
+    }
+
+    // helper routines
+    static long startTime = currentTimeMillis();
+    static long currentTimeMillis() {
+        //return System.nanoTime() / 1000000L;
+        return System.currentTimeMillis();
+    }
+    static void log(String s) {
+        long time = currentTimeMillis() - startTime;
+        long ms = time % 1000;
+        time /= 1000;
+        long sec = time % 60;
+        time /= 60;
+        long min = time % 60;
+        time /= 60;
+        System.out.println(""
+                + (time < 10 ? "0" : "") + time
+                + ":" + (min < 10 ? "0" : "") + min
+                + ":" + (sec < 10 ? "0" : "") + sec
+                + "." + (ms < 10 ? "00" : (ms < 100 ? "0" : "")) + ms
+                + " (" + Thread.currentThread().getName() + ") " + s);
+    }
+    static void delay(int millis) {
+        try {
+            Thread.sleep(millis);
+        } catch (InterruptedException e) {}
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioFileFormat/AudioFileFormatToString.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,235 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.sampled.AudioFileFormat;
+import javax.sound.sampled.AudioFormat;
+
+/**
+ * @test
+ * @bug 4672864
+ * @summary AudioFileFormat.toString() throws unexpected NullPointerException
+ */
+public class AudioFileFormatToString {
+
+    static final int STATUS_PASSED = 0;
+    static final int STATUS_FAILED = 2;
+    static final int STATUS_TEMP = 95;
+
+    public static void main(String argv[]) throws Exception {
+        int testExitStatus = run(argv, System.out);
+        if (testExitStatus != STATUS_PASSED) {
+            throw new Exception("Test FAILED " + testExitStatus);
+        }
+        System.out.println("Test passed.");
+    }
+
+    public static int run(String argv[], java.io.PrintStream out) {
+        int testResult = STATUS_PASSED;
+
+        out.println("\n==> Test for AudioFileFormat class:");
+
+        AudioFormat testAudioFormat =
+         new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,  // AudioFormat.Encoding
+                         (float) 44100.0, // float SampleRate
+                         (int) 8, // int sampleSizeInBits
+                         (int) 2, // int channels
+                         (int) 2,    // int frameSize
+                         (float) 110.0,    // float frameRate
+                         true    // boolean bigEndian
+                         );
+        AudioFormat nullAudioFormat = null;
+
+        AudioFileFormat.Type testAudioFileFormatType = AudioFileFormat.Type.WAVE;
+        AudioFileFormat.Type nullAudioFileFormatType = null;
+
+        AudioFileFormat testedAudioFileFormat = null;
+        out.println("\n>> public AudioFileFormat constructor for AudioFileFormat.Type = null: ");
+        try {
+         testedAudioFileFormat =
+             new AudioFileFormat(nullAudioFileFormatType,  // AudioFileFormat.Type
+                                 testAudioFormat, // AudioFormat
+                                 (int) 1024 // int frameLength
+                                 );
+         out.println(">  No any Exception was thrown!");
+         out.println(">  testedAudioFileFormat.getType():");
+         try {
+             AudioFileFormat.Type producedType = testedAudioFileFormat.getType();
+             out.println(">   PASSED: producedType = " + producedType);
+         } catch (Throwable thrown) {
+             out.println("##  FAILED: unexpected Exception was thrown:");
+             thrown.printStackTrace(out);
+             testResult = STATUS_FAILED;
+         }
+         out.println(">  testedAudioFileFormat.toString():");
+         try {
+             String producedString = testedAudioFileFormat.toString();
+             out.println(">   PASSED: producedString = " + producedString);
+         } catch (Throwable thrown) {
+             out.println("##  FAILED: unexpected Exception was thrown:");
+             thrown.printStackTrace(out);
+             testResult = STATUS_FAILED;
+         }
+        } catch (IllegalArgumentException illegArgExcept) {
+         out.println(">   PASSED: expected IllegalArgumentException was thrown:");
+         illegArgExcept.printStackTrace(out);
+        } catch (NullPointerException nullPE) {
+         out.println(">   PASSED: expected NullPointerException was thrown:");
+         nullPE.printStackTrace(out);
+        } catch (Throwable thrown) {
+         out.println("##  FAILED: unexpected Exception was thrown:");
+         thrown.printStackTrace(out);
+         testResult = STATUS_FAILED;
+        }
+
+        out.println("\n>> public AudioFileFormat constructor for AudioFormat = null: ");
+        try {
+         testedAudioFileFormat =
+             new AudioFileFormat(testAudioFileFormatType,  // AudioFileFormat.Type
+                                 nullAudioFormat, // AudioFormat
+                                 (int) 1024 // int frameLength
+                                 );
+         out.println(">  No any Exception was thrown!");
+         out.println(">  testedAudioFileFormat.getFormat():");
+         try {
+             AudioFormat producedFormat = testedAudioFileFormat.getFormat();
+             out.println(">   PASSED: producedFormat = " + producedFormat);
+         } catch (Throwable thrown) {
+             out.println("##  FAILED: unexpected Exception was thrown:");
+             thrown.printStackTrace(out);
+             testResult = STATUS_FAILED;
+         }
+         out.println(">  testedAudioFileFormat.toString():");
+         try {
+             String producedString = testedAudioFileFormat.toString();
+             out.println(">   PASSED: producedString = " + producedString);
+         } catch (Throwable thrown) {
+             out.println("##  FAILED: unexpected Exception was thrown:");
+             thrown.printStackTrace(out);
+             testResult = STATUS_FAILED;
+         }
+        } catch (IllegalArgumentException illegArgExcept) {
+            out.println(">   PASSED: expected IllegalArgumentException was thrown:");
+            illegArgExcept.printStackTrace(out);
+        } catch (NullPointerException nullPE) {
+            out.println(">   PASSED: expected NullPointerException was thrown:");
+            nullPE.printStackTrace(out);
+        } catch (Throwable thrown) {
+            out.println("##  FAILED: unexpected Exception was thrown:");
+            thrown.printStackTrace(out);
+            testResult = STATUS_FAILED;
+        }
+
+        out.println("\n>> protected AudioFileFormat constructor for AudioFileFormat.Type = null: ");
+        try {
+         testedAudioFileFormat =
+             new TestAudioFileFormat(nullAudioFileFormatType,  // AudioFileFormat.Type
+                                     (int) 1024, // byteLength
+                                     testAudioFormat, // AudioFormat
+                                     (int) 1024 // int frameLength
+                                     );
+         out.println(">  No any Exception was thrown!");
+         out.println(">  testedAudioFileFormat.getType():");
+         try {
+             AudioFileFormat.Type producedType = testedAudioFileFormat.getType();
+             out.println(">   PASSED: producedType = " + producedType);
+         } catch (Throwable thrown) {
+             out.println("##  FAILED: unexpected Exception was thrown:");
+             thrown.printStackTrace(out);
+             testResult = STATUS_FAILED;
+         }
+         out.println(">  testedAudioFileFormat.toString():");
+         try {
+             String producedString = testedAudioFileFormat.toString();
+             out.println(">   PASSED: producedString = " + producedString);
+         } catch (Throwable thrown) {
+             out.println("##  FAILED: unexpected Exception was thrown:");
+             thrown.printStackTrace(out);
+             testResult = STATUS_FAILED;
+         }
+        } catch (IllegalArgumentException illegArgExcept) {
+         out.println(">   PASSED: expected IllegalArgumentException was thrown:");
+         illegArgExcept.printStackTrace(out);
+        } catch (NullPointerException nullPE) {
+         out.println(">   PASSED: expected NullPointerException was thrown:");
+         nullPE.printStackTrace(out);
+        } catch (Throwable thrown) {
+         out.println("##  FAILED: unexpected Exception was thrown:");
+         thrown.printStackTrace(out);
+         testResult = STATUS_FAILED;
+        }
+
+        out.println("\n>> protected AudioFileFormat constructor for AudioFormat = null: ");
+        try {
+         testedAudioFileFormat =
+             new TestAudioFileFormat(testAudioFileFormatType,  // AudioFileFormat.Type
+                                     (int) 1024, // byteLength
+                                     nullAudioFormat, // AudioFormat
+                                     (int) 1024 // int frameLength
+                                     );
+         out.println(">  No any Exception was thrown!");
+         out.println(">  testedAudioFileFormat.getFormat():");
+         try {
+             AudioFormat producedFormat = testedAudioFileFormat.getFormat();
+             out.println(">   PASSED: producedFormat = " + producedFormat);
+         } catch (Throwable thrown) {
+             out.println("##  FAILED: unexpected Exception was thrown:");
+             thrown.printStackTrace(out);
+             testResult = STATUS_FAILED;
+         }
+         out.println(">  testedAudioFileFormat.toString():");
+         try {
+             String producedString = testedAudioFileFormat.toString();
+             out.println(">   PASSED: producedString = " + producedString);
+         } catch (Throwable thrown) {
+             out.println("##  FAILED: unexpected Exception was thrown:");
+             thrown.printStackTrace(out);
+             testResult = STATUS_FAILED;
+         }
+        } catch (IllegalArgumentException illegArgExcept) {
+         out.println(">   PASSED: expected IllegalArgumentException was thrown:");
+         illegArgExcept.printStackTrace(out);
+        } catch (NullPointerException nullPE) {
+         out.println(">   PASSED: expected NullPointerException was thrown:");
+         nullPE.printStackTrace(out);
+        } catch (Throwable thrown) {
+         out.println("##  FAILED: unexpected Exception was thrown:");
+         thrown.printStackTrace(out);
+         testResult = STATUS_FAILED;
+        }
+
+        if (testResult == STATUS_FAILED) {
+            out.println("\n==> test FAILED!");
+        } else {
+            out.println("\n==> test PASSED!");
+        }
+        return testResult;
+    }
+}
+
+class TestAudioFileFormat extends AudioFileFormat {
+
+    TestAudioFileFormat(AudioFileFormat.Type type, int byteLength,
+                        AudioFormat format, int frameLength) {
+        super(type, byteLength, format, frameLength);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioFileFormat/Properties.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.sound.midi.MidiFileFormat;
+import javax.sound.midi.Sequence;
+import javax.sound.sampled.AudioFileFormat;
+import javax.sound.sampled.AudioFormat;
+
+/**
+ * @test
+ * @bug 4666845
+ * @summary RFE: Add properties to AudioFileFormat and MidiFileFormat
+ */
+public class Properties {
+
+    static boolean g_failed = false;
+
+    // all of p1 need to be in p2
+    static boolean compare(Map p1, Map p2) {
+        boolean failed = false;
+        for(String key: (Set<String>) p1.keySet()) {
+            out("  testing key: "+key);
+            if (!p2.containsKey(key)) {
+                out("  missing property: '"+key+"'. Failed");
+                failed = true;
+            }
+            Object v1 = p1.get(key);
+            Object v2 = p2.get(key);
+            if (((v1 == null) && (v2 != null))
+                || ((v1 != null) && (v2 == null))
+                || !(v1.equals(v2))) {
+                out("  property '"+key+"' is different: "
+                    +"expected='"+v1+"'  "
+                    +"actual='"+v2+"'. Failed");
+                failed = true;
+            }
+        }
+        // test if we can modify p2
+        try {
+             int oldSize = p2.size();
+             p2.clear();
+             if (oldSize > 0 && p2.size() == 0) {
+                 out("  could clear the properties! Failed.");
+                 failed = true;
+             }
+        } catch (Exception e) {
+            // correct
+        }
+        return failed;
+    }
+
+    public static void main(String argv[]) throws Exception {
+        // don't need to catch exceptions: any exception is a
+        // failure of this test
+
+        Map<String, Object> p = new HashMap<String,Object>();
+        p.put("author", "Florian");
+        p.put("duration", new Long(1000));
+        p.put("MyProp", "test");
+
+        out("Testing AudioFileFormat properties:");
+        // create an AudioFileFormat with properties
+        AudioFormat format = new AudioFormat( 44100.0f, 16, 2, true, false);
+        AudioFileFormat aff =
+            new AudioFileFormat(AudioFileFormat.Type.WAVE,
+                                format, 1000, p);
+        // test that it has the properties
+        boolean failed = compare(p, aff.properties());
+        // test getProperty()
+        Object o = aff.getProperty("author");
+        if (o == null || !o.equals("Florian")) {
+            out("  getProperty did not report an existing property!");
+            failed = true;
+        }
+        o = aff.getProperty("does not exist");
+        if (o != null) {
+            out("  getProperty returned something for a non-existing property!");
+            failed = true;
+        }
+        if (!failed) {
+            out("  OK");
+        } else {
+            g_failed = true;
+        }
+
+
+
+        out("Testing MidiFileFormat properties:");
+        // create a MidiFileFormat with properties
+        MidiFileFormat mff =
+            new MidiFileFormat(0, Sequence.PPQ, 240,
+                               1000, 100, p);
+        // test that it has the properties
+        failed = compare(p, mff.properties());
+        // test getProperty()
+        o = mff.getProperty("author");
+        if (o == null || !o.equals("Florian")) {
+            out("  getProperty did not report an existing property!");
+            failed = true;
+        }
+        o = mff.getProperty("does not exist");
+        if (o != null) {
+            out("  getProperty returned something for a non-existing property!");
+            failed = true;
+        }
+        if (!failed) {
+            out("  OK");
+        } else {
+            g_failed = true;
+        }
+
+
+        if (g_failed) throw new Exception("Test FAILED!");
+        System.out.println("Test passed.");
+    }
+
+    static void out(String s) {
+        System.out.println(s);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioFileFormat/TypeEquals.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.sampled.AudioFileFormat;
+
+/**
+ * @test
+ * @bug 4925483
+ * @summary RFE: equals() should compare string in Encoding and Type
+ */
+public class TypeEquals {
+
+    public static void main(String argv[]) throws Exception {
+        // first test that we can create our own type
+        // (the constructor was made public)
+        AudioFileFormat.Type myType = new AudioFileFormat.Type("WAVE", "wav");
+
+        // then check if this one equals this new one
+        // with the static instance in AudioFileFormat.Type
+        if (!myType.equals(AudioFileFormat.Type.WAVE)) {
+         throw new Exception("Types do not equal!");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioFormat/AudioFormatBitSize.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 4754759
+ * @summary AudioFormat does not handle uncommon bit sizes correctly
+ */
+
+import javax.sound.sampled.AudioFormat;
+
+public class AudioFormatBitSize {
+
+    public static void main(String[] args) throws Exception {
+        int bits = 18;
+        AudioFormat format = new AudioFormat(44100.0f, bits, 1, true, false);
+        if (format.getFrameSize() * 8 < bits) {
+            System.out.println("bits = "+bits+" do not fit into a "+format.getFrameSize()+" bytes sample!");
+            throw new Exception("Test failed");
+        } else
+            System.out.println("bits = "+bits+" fit OK into a "+format.getFrameSize()+" bytes sample!");
+            System.out.println("Test passed");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioFormat/EncodingEquals.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.sampled.AudioFormat;
+
+/**
+ * @test
+ * @bug 4925483
+ * @summary RFE: equals() should compare string in Encoding and Type
+ */
+public class EncodingEquals {
+
+    public static void main(String argv[]) throws Exception {
+         // first test that we can create our own encoding
+         // (the constructor was made public)
+         AudioFormat.Encoding myType = new AudioFormat.Encoding("PCM_SIGNED");
+
+         // then check if this one equals this new one
+         // with the static instance in AudioFormat.Encoding
+         if (!myType.equals(AudioFormat.Encoding.PCM_SIGNED)) {
+             throw new Exception("Encodings do not equal!");
+         }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioFormat/Properties.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.sound.sampled.AudioFormat;
+
+/**
+ * @test
+ * @bug 4925767
+ * @summary RFE: Add Properties to AudioFormat
+ */
+public class Properties {
+
+    static boolean g_failed = false;
+
+    // all of p1 need to be in p2
+    static boolean compare(Map p1, Map p2) {
+        boolean failed = false;
+        for(String key: (Set<String>) p1.keySet()) {
+            out("  testing key: "+key);
+            if (!p2.containsKey(key)) {
+                out("  missing property: '"+key+"'. Failed");
+                failed = true;
+            }
+            Object v1 = p1.get(key);
+            Object v2 = p2.get(key);
+            if (((v1 == null) && (v2 != null))
+                || ((v1 != null) && (v2 == null))
+                || !(v1.equals(v2))) {
+                out("  property '"+key+"' is different: "
+                    +"expected='"+v1+"'  "
+                    +"actual='"+v2+"'. Failed");
+                failed = true;
+            }
+        }
+        // test if we can modify p2
+        try {
+             int oldSize = p2.size();
+             p2.clear();
+             if (oldSize > 0 && p2.size() == 0) {
+                 out("  could clear the properties! Failed.");
+                 failed = true;
+             }
+        } catch (Exception e) {
+            // correct
+        }
+        return failed;
+    }
+
+
+    public static void main(String argv[]) throws Exception {
+        // don't need to catch exceptions: any exception is a
+        // failure of this test
+
+        Map<String, Object> p = new HashMap<String,Object>();
+        p.put("bitrate", new Integer(128));
+        p.put("quality", new Integer(10));
+        p.put("MyProp", "test");
+
+        out("Testing AudioFileFormat properties:");
+        // create an AudioFileFormat with properties
+        AudioFormat format =
+            new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
+                            44100.0f, 16, 2, 4, 44100.0f, false, p);
+        // test that it has the properties
+        boolean failed = compare(p, format.properties());
+        // test getProperty()
+        Object o = format.getProperty("MyProp");
+        if (o == null || !o.equals("test")) {
+            out("  getProperty did not report an existing property!");
+            failed = true;
+        }
+        o = format.getProperty("does not exist");
+        if (o != null) {
+            out("  getProperty returned something for a non-existing property!");
+            failed = true;
+        }
+        if (!failed) {
+            out("  OK");
+        } else {
+            g_failed = true;
+        }
+
+        if (g_failed) throw new Exception("Test FAILED!");
+        System.out.println("Test passed.");
+    }
+
+    static void out(String s) {
+        System.out.println(s);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioInputStream/AISReadFraction.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,237 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+
+/**
+ * @test
+ * @bug 4948663
+ * @summary AudioInputStream does not use the original stream passed to its constructor
+ */
+public class AISReadFraction {
+
+    static int failed = 0;
+    static byte[] testData = new byte[256];
+    static boolean DEBUG = false;
+
+    static AudioFormat[] formats = {
+        new AudioFormat(44100.0f, 8, 1, false, false), // frameSize = 1
+        new AudioFormat(44100.0f, 8, 2, false, false), // frameSize = 2
+        new AudioFormat(44100.0f, 16, 1, true, false), // frameSize = 2
+        new AudioFormat(44100.0f, 24, 1, true, false), // frameSize = 3
+        new AudioFormat(44100.0f, 16, 2, true, false), // frameSize = 4
+        new AudioFormat(44100.0f, 8, 5, false, false), // frameSize = 5
+        new AudioFormat(44100.0f, 16, 3, true, false), // frameSize = 6
+        new AudioFormat(44100.0f, 8, 7, false, false), // frameSize = 7
+        new AudioFormat(44100.0f, 32, 2, true, false)  // frameSize = 8
+    };
+
+
+    public static void main(String args[]) throws Exception {
+        for (int i = 0; i<testData.length; i++) {
+                testData[i] = (byte) (i % 128);
+        }
+
+        for (int f = 0; f < formats.length; f++) {
+                // first test without marking
+                doTest(formats[f], false);
+                // then with marking
+                doTest(formats[f], true);
+        }
+
+        out(""+failed+" failures.");
+        if (failed>0) throw new Exception("Test FAILED!");
+        out("Test passed.");
+    }
+
+    static void doTest(AudioFormat format, boolean doMark) {
+        out("Test with"+(doMark?"":"out")+" marking. Audio format: "
+            +"sampleSize="+format.getSampleSizeInBits()+"bits "
+            +"channels="+format.getChannels()+" "
+            +"frameSize="+format.getFrameSize()+"byte(s)");
+        int maxReadBytes = (testData.length / format.getFrameSize()) * format.getFrameSize();
+        InputStream is = new FractionalIS(testData, doMark);
+        AudioInputStream ais = new AudioInputStream(is, format, AudioSystem.NOT_SPECIFIED);
+        // first some general tests
+        if (ais.markSupported() && !doMark) {
+                out("  #AIS reports markSupported, but underlying stream cannot! FAILED");
+                failed ++;
+        }
+        if (!ais.markSupported() && doMark) {
+                out("  #AIS does not report markSupported, but underlying stream can mark! FAILED");
+                failed++;
+        }
+        byte[] data = new byte[1000];
+        int frameSize = format.getFrameSize();
+        int counter = 5;
+        int totalReadBytes = 0;
+        boolean hasRead0 = false;
+        boolean hasMarked = false;
+        boolean hasReset = false;
+        int markPos = 0;
+        while (true) {
+            try {
+                int toBeRead = frameSize * counter;
+                counter += 3;
+                if (counter > 14) {
+                        counter -= 14;
+                }
+                int read = ais.read(data, 0, toBeRead);
+                if (DEBUG) out("  -> ais.read(data, 0, "+toBeRead+"): "+read+"  (frameSize="+frameSize+")");
+                if ((totalReadBytes == maxReadBytes) && (read != -1)
+                     && ((read > 0) || hasRead0)) {
+                        if (read == 0) {
+                            out("  #stream was read to the end ("+maxReadBytes+"), but ais.read returned repeatedly 0 bytes. FAILED");
+                        } else {
+                            out("  #stream was read to the end ("+maxReadBytes+"), but ais.read returned "+read+" bytes... FAILED");
+                        }
+                        failed++;
+                        break;
+                }
+                if (read > 0) {
+                        verifyReadBytes(data, totalReadBytes, read);
+                        if ((read % frameSize) != 0) {
+                                out("  #Read non-integral number of frames: "+read+" bytes, frameSize="+frameSize+" bytes. FAILED");
+                                failed++;
+                        }
+                        totalReadBytes += read;
+                        hasRead0 = false;
+                }
+                else if (read == 0) {
+                        //out("  wanted to read "+toBeRead+" at position "+totalReadBytes+", but got 0 bytes!");
+                        if (hasRead0) {
+                                out("  read 0 twice in a row! FAILED");
+                                failed++;
+                                break;
+                        }
+                        hasRead0 = true;
+                } else {
+                        // end of stream
+                        out("  End of stream reached. Total read bytes: "+totalReadBytes);
+                        if (totalReadBytes != maxReadBytes) {
+                                out("  #Failed: should have read "+maxReadBytes+" bytes! FAILED.");
+                                failed++;
+                        }
+                        break;
+                }
+
+                // test marking
+                if (totalReadBytes > 50 && !hasMarked && !hasReset && doMark) {
+                        out("  Marking at position "+totalReadBytes);
+                        hasMarked = true;
+                        ais.mark(0);
+                        markPos = totalReadBytes;
+                }
+                if (totalReadBytes > 100 && hasMarked && !hasReset && doMark) {
+                        out("  Resetting at position "+totalReadBytes+" back to "+markPos);
+                        hasReset = true;
+                        ais.reset();
+                        totalReadBytes = markPos;
+                }
+
+            } catch (IOException e) {
+                out("  #caught unexpected exception:");
+                e.printStackTrace();
+                failed++;
+            }
+        }
+    }
+
+    static void verifyReadBytes(byte[] data, int offset, int len) {
+        int firstWrongByte = -1;
+        for (int i = 0; i < len; i++) {
+                int expected = ((offset + i) % 128);
+                if (data[i] != expected) {
+                        out("  read data is not correct! offset="+offset+"  expected="+expected+"  actual="+data[i]);
+                        failed++;
+                        break;
+                }
+        }
+    }
+
+
+    public static void out(String s) {
+        System.out.println(s);
+    }
+
+
+    static class FractionalIS extends InputStream {
+        byte[] data;
+        int pos = 0;
+        boolean canMark;
+        // a counter how many bytes are not returned
+        int missingBytes = 0;
+        int markPos = -1;
+
+        FractionalIS(byte[] data, boolean canMark) {
+                this.data = data;
+                this.canMark = canMark;
+        }
+
+        public int read() throws IOException {
+                if (pos >= data.length) {
+                        return -1;
+                }
+                return data[pos++] & 0xFF;
+        }
+
+        public int read(byte[] b, int off, int len) throws IOException {
+                if (++missingBytes > 5) {
+                        missingBytes = 0;
+                }
+                int reducedLen = len - missingBytes;
+                if (reducedLen <= 0) reducedLen = 1;
+                if (DEBUG) out("  FIS.read(data, 0, "+len+"): reducing len to "+reducedLen+" bytes.");
+                int ret = super.read(b, off, reducedLen);
+                if (DEBUG) out("                              returning "+ret+" bytes. Now at pos="+pos);
+                return ret;
+        }
+
+        public void mark(int readlimit) {
+                markPos = pos;
+                if (DEBUG) out("  FIS.mark(): marking at "+pos);
+        }
+
+        public void reset() throws IOException {
+                if (!canMark) {
+                        throw new IOException("reset not supported!");
+                }
+                if (markPos == -1) {
+                        throw new IOException("Mark position not set!");
+                }
+                pos = markPos;
+                if (DEBUG) out("  FIS.reset(): now back at "+pos);
+        }
+
+        public boolean markSupported() {
+                return canMark;
+        }
+
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioInputStream/bug6188860.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+
+/**
+ * @test
+ * @bug 6188860
+ * @summary Tests that method AudioInputStream.read() returns right value
+ */
+public class bug6188860 {
+
+    public static void main(String[] args) throws Exception {
+        byte[] testData = new byte[256];
+
+        // fill data
+        for (int i = 0; i < testData.length; i++)
+            testData[i] = (byte) (i % 128);
+
+        InputStream streamSrc = new TestInputStream(testData);
+        AudioFormat format = new AudioFormat(44100.0f, 8, 1, false, false); // frameSize = 1
+        AudioInputStream streamAudio = new AudioInputStream(streamSrc, format, AudioSystem.NOT_SPECIFIED);
+
+        int nErrCount = 0;
+        int nTotal = 0;
+
+        int dataSrc, dataRead;
+        while (nTotal < (testData.length - 1)) {
+            dataRead = streamAudio.read();
+            if (dataRead < 0) {
+                System.out.println("end of stream");
+                break;
+            }
+
+            dataSrc = testData[nTotal];
+
+            if (dataRead != dataSrc) {
+                System.out.println("" + nTotal + " - mismatch :" + dataRead + " <> " + dataSrc);
+                nErrCount++;
+            }
+            nTotal++;
+        }
+
+        System.out.println("Total: " + nTotal + "; Mismatches: " + nErrCount);
+
+        if (nErrCount > 0) {
+            throw new RuntimeException("test failed: " + nErrCount + " mismatches of total " + nTotal + " bytes.");
+        }
+        System.out.println("Test sucessfully passed.");
+    }
+
+
+    static class TestInputStream extends InputStream {
+        byte[] data;
+        int pos = 0;
+
+        TestInputStream(byte[] data) {
+            this.data = data;
+        }
+
+        public int read() throws IOException {
+            if (pos >= data.length) {
+                return -1;
+            }
+            return data[pos++] & 0xFF;
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioSystem/AudioFileTypes/AudioFileTypeUniqueness.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.sampled.AudioFileFormat;
+import javax.sound.sampled.AudioSystem;
+
+/**
+ * @test
+ * @bug 4883060
+ * @summary AudioSystem.getAudioFileTypes returns duplicates
+ */
+public class AudioFileTypeUniqueness {
+
+    public static void main(String[] args) throws Exception {
+        boolean foundDuplicates = false;
+        AudioFileFormat.Type[]  aTypes = AudioSystem.getAudioFileTypes();
+        for (int i = 0; i < aTypes.length; i++)
+        {
+            for (int j = 0; j < aTypes.length; j++)
+            {
+                if (aTypes[i].equals(aTypes[j]) && i != j) {
+                    foundDuplicates = true;
+                }
+            }
+        }
+        if (foundDuplicates) {
+            throw new Exception("Test failed");
+        } else {
+            System.out.println("Test passed");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioSystem/AudioFileTypes/ShowAudioFileTypes.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.sampled.AudioFileFormat;
+import javax.sound.sampled.AudioSystem;
+
+/**
+ * @test
+ * @bug 4303037
+ * @summary Shows the existing audio file types of AudioSystem and checks
+ *          whether there are some at all
+ */
+public class ShowAudioFileTypes {
+
+    public static void main(String[] args) throws Exception {
+        AudioFileFormat.Type[]  aTypes = AudioSystem.getAudioFileTypes();
+        System.out.println(aTypes.length+" supported target types:");
+        for (int i = 0; i < aTypes.length; i++)
+        {
+            System.out.println("  "+(i+1)+". " + aTypes[i]+" with ext. '"+aTypes[i].getExtension()+"'");
+        }
+        if (aTypes.length<3) {
+            throw new Exception("Test failed");
+        } else {
+            System.out.println("Test passed");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioSystem/DefaultMixers.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,198 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.List;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Clip;
+import javax.sound.sampled.DataLine;
+import javax.sound.sampled.Line;
+import javax.sound.sampled.Mixer;
+import javax.sound.sampled.Port;
+import javax.sound.sampled.SourceDataLine;
+import javax.sound.sampled.TargetDataLine;
+import javax.sound.sampled.spi.MixerProvider;
+
+import com.sun.media.sound.JDK13Services;
+
+/**
+ * @test
+ * @bug 4776511
+ * @summary RFE: Setting the default MixerProvider. Test the retrieving of lines
+ *          with defaut mixer properties.
+ * @modules java.desktop/com.sun.media.sound
+ */
+public class DefaultMixers {
+
+    private static final String ERROR_PROVIDER_CLASS_NAME = "abc";
+    private static final String ERROR_INSTANCE_NAME = "def";
+
+    private static final Class[] lineClasses = {
+        SourceDataLine.class,
+        TargetDataLine.class,
+        Clip.class,
+        Port.class,
+    };
+
+    public static void main(String[] args) throws Exception {
+        boolean allOk = true;
+        Mixer.Info[] infos;
+
+        out("Testing Mixers retrieved via AudioSystem");
+        infos = AudioSystem.getMixerInfo();
+        allOk &= testMixers(infos, null);
+
+        out("Testing MixerProviders");
+        List providers = JDK13Services.getProviders(MixerProvider.class);
+        for (int i = 0; i < providers.size(); i++) {
+            MixerProvider provider = (MixerProvider) providers.get(i);
+            infos = provider.getMixerInfo();
+            allOk &= testMixers(infos, provider.getClass().getName());
+        }
+
+        if (! allOk) {
+            throw new Exception("Test failed");
+        } else {
+            out("Test passed");
+        }
+    }
+
+    private static boolean testMixers(Mixer.Info[] infos,
+                                      String providerClassName) {
+        boolean allOk = true;
+
+        for (int i = 0; i < infos.length; i++) {
+            Mixer mixer = null;
+            try {
+                mixer = AudioSystem.getMixer(infos[i]);
+            } catch (NullPointerException e) {
+                out("Exception thrown; Test NOT failed.");
+                e.printStackTrace();
+            }
+            for (int j = 0; j < lineClasses.length; j++) {
+                if (mixer.isLineSupported(new Line.Info(lineClasses[j]))) {
+                    allOk &= testMixer(mixer, lineClasses[j],
+                                       providerClassName);
+                }
+            }
+        }
+        return allOk;
+    }
+
+    private static boolean testMixer(Mixer mixer, Class lineType,
+                                      String providerClassName) {
+        boolean allOk = true;
+        String instanceName = mixer.getMixerInfo().getName();
+
+        // no error
+        allOk &= testMixer(mixer, lineType,
+                           providerClassName, instanceName);
+
+        // erroneous provider class name, correct instance name
+        allOk &= testMixer(mixer, lineType,
+                           ERROR_PROVIDER_CLASS_NAME, instanceName);
+
+        // erroneous provider class name, no instance name
+        allOk &= testMixer(mixer, lineType,
+                           ERROR_PROVIDER_CLASS_NAME, "");
+
+        // erroneous provider class name, erroneous instance name
+        allOk &= testMixer(mixer, lineType,
+                           ERROR_PROVIDER_CLASS_NAME, ERROR_INSTANCE_NAME);
+
+        return allOk;
+    }
+
+    private static boolean testMixer(Mixer mixer, Class lineType,
+                                     String providerClassName,
+                                     String instanceName) {
+        boolean allOk = true;
+
+        try {
+            String propertyValue = (providerClassName != null) ? providerClassName: "" ;
+            propertyValue += "#" + instanceName;
+            out("property value: " + propertyValue);
+            System.setProperty(lineType.getName(), propertyValue);
+            Line line = null;
+            Line.Info info = null;
+            Line.Info[] infos;
+            AudioFormat format = null;
+            if (lineType == SourceDataLine.class || lineType == Clip.class) {
+                infos = mixer.getSourceLineInfo();
+                format = getFirstLinearFormat(infos);
+                info = new DataLine.Info(lineType, format);
+            } else if (lineType == TargetDataLine.class) {
+                infos = mixer.getTargetLineInfo();
+                format = getFirstLinearFormat(infos);
+                info = new DataLine.Info(lineType, format);
+            } else if (lineType == Port.class) {
+                /* Actually, a Ports Mixer commonly has source infos
+                   as well as target infos. We ignore this here, since we
+                   just need a random one. */
+                infos = mixer.getSourceLineInfo();
+                for (int i = 0; i < infos.length; i++) {
+                    if (infos[i] instanceof Port.Info) {
+                        info = infos[i];
+                        break;
+                    }
+                }
+            }
+            out("Line.Info: " + info);
+            line = AudioSystem.getLine(info);
+            out("line: " + line);
+            if (! lineType.isInstance(line)) {
+                out("type " + lineType + " failed: class should be '" +
+                    lineType + "' but is '" + line.getClass() + "'!");
+                allOk = false;
+            }
+        } catch (Exception e) {
+            out("Exception thrown; Test NOT failed.");
+            e.printStackTrace();
+        }
+        return allOk;
+    }
+
+    private static AudioFormat getFirstLinearFormat(Line.Info[] infos) {
+        for (int i = 0; i < infos.length; i++) {
+            if (infos[i] instanceof DataLine.Info) {
+                AudioFormat[] formats = ((DataLine.Info) infos[i]).getFormats();
+                for (int j = 0; j < formats.length; j++) {
+                    AudioFormat.Encoding encoding = formats[j].getEncoding();
+                    int sampleSizeInBits = formats[j].getSampleSizeInBits();
+                    if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED) &&
+                        sampleSizeInBits == 16 ||
+                        encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED) &&
+                        sampleSizeInBits == 16) {
+                        return formats[j];
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioSystem/DefaultProperties.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+
+import com.sun.media.sound.JDK13Services;
+
+/**
+ * @test
+ * @bug 4776511
+ * @build DefaultProperties
+ * @run main/othervm DefaultProperties
+ * @summary RFE: Setting the default MixerProvider. Test the retrieving and
+ *          parsing of properties.
+ * @modules java.desktop/com.sun.media.sound
+ */
+public class DefaultProperties {
+
+    private static final Class[] lineTypeClasses = {
+        javax.sound.sampled.SourceDataLine.class,
+        javax.sound.sampled.TargetDataLine.class,
+        javax.sound.sampled.Clip.class,
+        javax.sound.sampled.Port.class,
+    };
+
+    public static void main(String[] args) throws Exception {
+        boolean allOk = true;
+        File file = new File(System.getProperty("test.src", "."), "testdata");
+        System.setProperty("java.home", file.getCanonicalPath());
+
+        for (int i = 0; i < lineTypeClasses.length; i++) {
+            Class cls = lineTypeClasses[i];
+            String propertyName = cls.getName();
+            String result;
+            String provClassName;
+            String instanceName;
+
+            // properties file, both provider class name and instance name
+            provClassName = "xyz";
+            instanceName = "123";
+            result = JDK13Services.getDefaultProviderClassName(cls);
+            if (! provClassName.equals(result)) {
+                out("type " + cls + " failed: provider class should be '" +
+                    provClassName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+            result = JDK13Services.getDefaultInstanceName(cls);
+            if (! instanceName.equals(result)) {
+                out("type " + cls + " failed: instance name should be '" +
+                    instanceName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+
+            // system property, provider class name only, no trailing hash
+            provClassName = "abc";
+            System.setProperty(propertyName, provClassName);
+            result = JDK13Services.getDefaultProviderClassName(cls);
+            if (! provClassName.equals(result)) {
+                out("type " + cls + " failed: provider class should be '" +
+                    provClassName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+            result = JDK13Services.getDefaultInstanceName(cls);
+            if (result != null) {
+                out("type " + cls + " failed: instance name should be " +
+                    "null but is '" + result + "'!");
+                allOk = false;
+            }
+
+            // system property, provider class name only, trailing hash
+            provClassName = "def";
+            System.setProperty(propertyName, provClassName + "#");
+            result = JDK13Services.getDefaultProviderClassName(cls);
+            if (! provClassName.equals(result)) {
+                out("type " + cls + " failed: provider class should be '" +
+                    provClassName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+            result = JDK13Services.getDefaultInstanceName(cls);
+            if (result != null) {
+                out("type " + cls + " failed: instance name should be " +
+                    "null but is '" + result + "'!");
+                allOk = false;
+            }
+
+            // system property, instance name only
+            instanceName = "ghi";
+            System.setProperty(propertyName, "#" + instanceName);
+            result = JDK13Services.getDefaultProviderClassName(cls);
+            if (result != null) {
+                out("type " + cls + " failed: provider class should be " +
+                    "null but is '" + result + "'!");
+                allOk = false;
+            }
+            result = JDK13Services.getDefaultInstanceName(cls);
+            if (! instanceName.equals(result)) {
+                out("type " + cls + " failed: instance name should be '" +
+                    instanceName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+
+            // system property, both provider class and instance name
+            provClassName = "jkl";
+            instanceName = "mno";
+            System.setProperty(propertyName, provClassName + "#" + instanceName);
+            result = JDK13Services.getDefaultProviderClassName(cls);
+            if (! provClassName.equals(result)) {
+                out("type " + cls + " failed: provider class should be '" +
+                    provClassName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+            result = JDK13Services.getDefaultInstanceName(cls);
+            if (! instanceName.equals(result)) {
+                out("type " + cls + " failed: instance name should be '" +
+                    instanceName + "' but is '" + result + "'!");
+                allOk = false;
+            }
+
+            // system property, empty
+            System.setProperty(propertyName, "");
+            result = JDK13Services.getDefaultProviderClassName(cls);
+            if (result != null) {
+                out("type " + cls + " failed: provider class should be " +
+                    "null but is '" + result + "'!");
+                allOk = false;
+            }
+            result = JDK13Services.getDefaultInstanceName(cls);
+            if (result != null) {
+                out("type " + cls + " failed: instance name should be " +
+                    "null but is '" + result + "'!");
+                allOk = false;
+            }
+        }
+        if (! allOk) {
+            throw new Exception("Test failed");
+        } else {
+            out("Test passed");
+        }
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioSystem/ProviderCacheing.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.List;
+import com.sun.media.sound.JDK13Services;
+
+/**
+ * @test
+ * @bug 4776511
+ * @summary RFE: Setting the default MixerProvider. Test the cacheing of
+ *          providers.
+ * @modules java.desktop/com.sun.media.sound
+ */
+public class ProviderCacheing {
+
+    private static final Class[] providerClasses = {
+        javax.sound.sampled.spi.AudioFileReader.class,
+        javax.sound.sampled.spi.AudioFileWriter.class,
+        javax.sound.sampled.spi.FormatConversionProvider.class,
+        javax.sound.sampled.spi.MixerProvider.class,
+    };
+
+    public static void main(String[] args) throws Exception {
+        boolean allCached = true;
+        for (int i = 0; i < providerClasses.length; i++) {
+            List list0 = JDK13Services.getProviders(providerClasses[i]);
+            List list1 = JDK13Services.getProviders(providerClasses[i]);
+            if (list0 == list1) {
+                out("Providers should not be cached for " + providerClasses[i]);
+                allCached = false;
+            }
+        }
+
+        if (! allCached) {
+            throw new Exception("Test failed");
+        } else {
+            out("Test passed");
+        }
+    }
+
+    private static void out(String message) {
+        System.out.println(message);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/AudioSystem/testdata/conf/sound.properties	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,27 @@
+#
+# Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+javax.sound.sampled.SourceDataLine=xyz#123
+javax.sound.sampled.TargetDataLine=xyz#123
+javax.sound.sampled.Clip=xyz#123
+javax.sound.sampled.Port=xyz#123
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/Clip/ClipCloseLoss.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Clip;
+import javax.sound.sampled.DataLine;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.Mixer;
+
+/**
+ * @test
+ * @bug 4946913
+ * @summary DirectClip doesn't kill the thread correctly, sometimes
+ * @run main/othervm ClipCloseLoss
+ * @key headful
+ */
+public class ClipCloseLoss {
+    static int frameCount = 441000; // lets say 10 seconds
+    static AudioFormat format = new AudioFormat(44100.0f, 16, 2, true, false);
+    static ByteArrayInputStream bais =
+    new ByteArrayInputStream(new byte[frameCount * format.getFrameSize()]);
+
+    static int success = 0;
+    static boolean failed = false;
+
+    public static void run(Mixer m) {
+        Clip clip = null;
+        try {
+            if (m == null) {
+                out("Using default mixer");
+                clip = (Clip) AudioSystem.getClip();
+            } else {
+                out("Using mixer: "+m);
+                DataLine.Info info = new DataLine.Info(Clip.class, format, AudioSystem.NOT_SPECIFIED);
+                clip = (Clip) m.getLine(info);
+            }
+            out(" got clip: "+clip);
+            if (!clip.getClass().toString().contains("Direct")) {
+                out(" no direct audio clip -> do not test.");
+                return;
+            }
+
+            out(" open");
+            bais.reset();
+            clip.open(new AudioInputStream(bais, format, frameCount));
+
+            out(" clip.close()");
+            //long t = System.currentTimeMillis();
+            clip.close();
+            //if (System.currentTimeMillis() - t > 1950) {
+            //  out(" clip.close needed more than 2 seconds! Causes failure of this test.");
+            //  failed = true;
+            //}
+            out(" clip closed");
+            success++;
+        } catch (LineUnavailableException luae) {
+            // line not available, test not failed
+            System.err.println(luae);
+        } catch (IllegalArgumentException iae) {
+            // line not available, test not failed
+            System.err.println(iae);
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    public static int getClipThreadCount() {
+        int ret = 0;
+        ThreadGroup tg = Thread.currentThread().getThreadGroup();
+        while (tg.getParent() != null) { tg = tg.getParent(); }
+        Thread[] threads = new Thread[500];
+        int count = tg.enumerate(threads, true);
+        for (int i = 0; i < count; i++) {
+                if (threads[i].getName().contains("Direct")
+                    && threads[i].getName().contains("Clip")) {
+                        out("Found Direct Clip thread object: "+threads[i]);
+                        ret++;
+                }
+        }
+        return ret;
+    }
+
+    public static void main(String[] args) throws Exception    {
+        if (isSoundcardInstalled()) {
+            bais.mark(0);
+            run(null);
+            Mixer.Info[] infos = AudioSystem.getMixerInfo();
+            for (int i = 0; i<infos.length; i++) {
+                try {
+                    Mixer m = AudioSystem.getMixer(infos[i]);
+                    run(m);
+                } catch (Exception e) {
+                }
+            }
+            out("Waiting 1 second to dispose of all threads");
+            Thread.sleep(1000);
+            if (getClipThreadCount() > 0) {
+                out("Unused clip threads exist! Causes test failure");
+                failed = true;
+            }
+            if (failed) throw new Exception("Test FAILED!");
+            if (success > 0) {
+                out("Test passed.");
+            } else {
+                System.err.println("Test could not execute: please install an audio device");
+            }
+        }
+    }
+
+    /**
+    * Returns true if at least one soundcard is correctly installed
+    * on the system.
+    */
+    public static boolean isSoundcardInstalled() {
+        boolean result = false;
+        try {
+            Mixer.Info[] mixers = AudioSystem.getMixerInfo();
+            if (mixers.length > 0) {
+                result = AudioSystem.getSourceDataLine(null) != null;
+            }
+        } catch (Exception e) {
+            System.err.println("Exception occured: "+e);
+        }
+        if (!result) {
+            System.err.println("Soundcard does not exist or sound drivers not installed!");
+            System.err.println("This test requires sound drivers for execution.");
+        }
+        return result;
+    }
+
+    public static void out(String s) {
+        /*long t = System.nanoTime() / 1000000l;
+        String ts = ""+(t % 1000);
+        while (ts.length() < 3) ts = "0"+ts;
+        System.out.println(""+(t/1000)+":"+ts+" "+s);
+        System.out.flush();*/
+        System.out.println(s);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/Clip/ClipFlushCrash.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Clip;
+import javax.sound.sampled.DataLine;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.Mixer;
+
+/**
+ * @test
+ * @bug 4946945
+ * @summary Crash in javasound while running TicTacToe demo applet tiger b26
+ */
+public class ClipFlushCrash {
+    static int frameCount = 441000; // lets say 10 seconds
+    static AudioFormat format = new AudioFormat(44100.0f, 16, 2, true, false);
+    static ByteArrayInputStream bais =
+      new ByteArrayInputStream(new byte[frameCount * format.getFrameSize()]);
+
+    static int success = 0;
+
+    public static void run(Mixer m) {
+        Clip clip = null;
+        try {
+            if (m == null) {
+                out("Using default mixer");
+                clip = (Clip) AudioSystem.getClip();
+            } else {
+                out("Using mixer: "+m);
+                DataLine.Info info = new DataLine.Info(Clip.class, format, AudioSystem.NOT_SPECIFIED);
+                clip = (Clip) m.getLine(info);
+            }
+            out(" got clip: "+clip);
+            if (!clip.getClass().toString().contains("Direct")) {
+                out(" no direct audio clip -> do not test.");
+                return;
+            }
+
+            out(" open");
+            bais.reset();
+            clip.open(new AudioInputStream(bais, format, frameCount));
+
+            AT at1 = new AT(clip, "flush thread", 123) {
+                public void doAction() throws Exception {
+                        log("flush");
+                        clip.flush();
+                }
+            };
+            AT at2 = new AT(clip, "setFramePosition thread", 67) {
+                public void doAction() throws Exception {
+                        int pos = (int) (Math.random() * clip.getFrameLength());
+                        log("setPosition to frame "+pos);
+                        clip.setFramePosition(pos);
+                }
+            };
+            AT at3 = new AT(clip, "start/stop thread", 300) {
+                public void doAction() throws Exception {
+                        if (clip.isRunning()) {
+                                log("stop");
+                                clip.stop();
+                        } else {
+                                log("start");
+                                clip.setFramePosition(0);
+                                clip.start();
+                        }
+                }
+            };
+            AT at4 = new AT(clip, "open/close thread", 600) {
+                public synchronized void doAction() throws Exception {
+                        log("close");
+                        clip.close();
+                        wait(50);
+                        if (!terminated) {
+                                log("open");
+                                bais.reset();
+                                clip.open(new AudioInputStream(bais, format, frameCount));
+                        }
+                }
+            };
+
+            out(" clip.start");
+            clip.start();
+            out(" for 10 seconds, call start/stop, setFramePosition, and flush from other threads");
+            at1.start();
+            at2.start();
+            at3.start();
+            at4.start();
+            try {
+                Thread.sleep(10000);
+            } catch (InterruptedException ie) {}
+            out(" finished.");
+                at1.terminate();
+                at2.terminate();
+                at3.terminate();
+                at4.terminate();
+            out(" clip.close()");
+            clip.close();
+            success++;
+        } catch (LineUnavailableException luae) {
+            // line not available, test not failed
+            System.err.println(luae);
+        } catch (IllegalArgumentException iae) {
+            // line not available, test not failed
+            System.err.println(iae);
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    public static void main(String[] args) throws Exception     {
+        if (isSoundcardInstalled()) {
+                bais.mark(0);
+            run(null);
+            Mixer.Info[] infos = AudioSystem.getMixerInfo();
+            for (int i = 0; i<infos.length; i++) {
+                try {
+                        Mixer m = AudioSystem.getMixer(infos[i]);
+                        run(m);
+                } catch (Exception e) {
+                }
+            }
+            if (success > 0) {
+                out("No crash -> Test passed");
+            } else {
+                System.err.println("Test could not execute: please install an audio device");
+            }
+        }
+    }
+
+    /**
+     * Returns true if at least one soundcard is correctly installed
+     * on the system.
+     */
+    public static boolean isSoundcardInstalled() {
+        boolean result = false;
+        try {
+            Mixer.Info[] mixers = AudioSystem.getMixerInfo();
+            if (mixers.length > 0) {
+                result = AudioSystem.getSourceDataLine(null) != null;
+            }
+        } catch (Exception e) {
+            System.err.println("Exception occured: "+e);
+        }
+        if (!result) {
+            System.err.println("Soundcard does not exist or sound drivers not installed!");
+            System.err.println("This test requires sound drivers for execution.");
+        }
+        return result;
+    }
+
+    public static void out(String s) {
+        /*long t = System.nanoTime() / 1000000l;
+        String ts = ""+(t % 1000);
+        while (ts.length() < 3) ts = "0"+ts;
+        System.out.println(""+(t/1000)+":"+ts+" "+s);
+        System.out.flush();*/
+        System.out.println(s);
+    }
+
+    private abstract static class AT extends Thread {
+        protected boolean terminated = false;
+        protected Clip clip;
+        private int waitTime;
+
+        public AT(Clip clip, String name, int waitTime) {
+                super(name);
+                this.clip = clip;
+                this.waitTime = waitTime;
+        }
+
+        public abstract void doAction() throws Exception;
+
+                public void run() {
+                        log("start");
+                        while (!terminated) {
+                                try {
+                                        synchronized(this) {
+                                            wait(waitTime);
+                                        }
+                                        if (!terminated) {
+                                                doAction();
+                                        }
+                                } catch(Exception e) {
+                                        log("exception: "+e);
+                                }
+                        }
+                        log("exit");
+                }
+
+                public synchronized void terminate() {
+                        log("terminate");
+                        terminated = true;
+                        notifyAll();
+                }
+
+        protected void log(String s) {
+            //out("   "+Thread.currentThread().getId()+" "+getName()+": "+s);
+            out("   "+getName()+": "+s);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/Clip/Drain/ClipDrain.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Clip;
+import javax.sound.sampled.DataLine;
+import javax.sound.sampled.Mixer;
+
+/**
+ * @test
+ * @bug 4732218
+ * @summary Clip.drain does not actually block until all I/O is complete as
+ *          documented.
+ */
+public class ClipDrain {
+    static int successfulTests = 0;
+    static AudioFormat format = new AudioFormat(8000, 16, 1, true, false);
+    // create a 10-second file
+    static byte[] soundData = new byte[(int) (format.getFrameRate() * format.getFrameSize() * 10)];
+
+    static int TOLERANCE_MS = 2500; // how many milliseconds too short is tolerated...
+
+    private static void doMixerClip(Mixer mixer) throws Exception {
+        boolean waitedEnough=false;
+        try {
+            DataLine.Info info = new DataLine.Info(Clip.class, format);
+            Clip clip = (Clip) mixer.getLine(info);
+            clip.open(format, soundData, 0, soundData.length);
+
+            // sanity
+            if (clip.getMicrosecondLength()/1000 < 9900) {
+                throw new Exception("clip's microsecond length should be at least 9900000, but it is "+clip.getMicrosecondLength());
+            }
+            long start = System.currentTimeMillis();
+
+            System.out.println(" ---------- start --------");
+            clip.start();
+            // give time to actually start it. ALSA implementation needs that...
+            Thread.sleep(300);
+            System.out.println("drain ... ");
+            clip.drain();
+            long elapsedTime = System.currentTimeMillis() - start;
+            System.out.println("close ... ");
+            clip.close();
+            System.out.println("... done");
+            System.out.println("Playback duration: "+elapsedTime+" milliseconds.");
+            waitedEnough = elapsedTime >= ((clip.getMicrosecondLength() / 1000) - TOLERANCE_MS);
+        } catch (Throwable t) {
+                System.out.println("  - Caught exception. Not failed.");
+                System.out.println("  - "+t.toString());
+                return;
+        }
+        if (!waitedEnough) {
+            throw new Exception("Drain did not wait long enough to play entire clip.");
+        }
+        successfulTests++;
+    }
+
+
+    private static void doAll() throws Exception {
+        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
+        for (int i=0; i<mixers.length; i++) {
+            Mixer mixer = AudioSystem.getMixer(mixers[i]);
+            System.out.println("--------------");
+            System.out.println("Testing mixer: "+mixers[i]);
+            doMixerClip(mixer);
+        }
+        if (mixers.length==0) {
+            System.out.println("No mixers available!");
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        if (!isSoundcardInstalled()) {
+            return;
+        }
+        doAll();
+        if (successfulTests==0) {
+            System.out.println("Could not execute any of the tests. Test NOT failed.");
+        } else {
+            System.out.println("Test PASSED.");
+        }
+    }
+
+    /**
+     * Returns true if at least one soundcard is correctly installed
+     * on the system.
+     */
+    public static boolean isSoundcardInstalled() {
+        boolean result = false;
+        try {
+            Mixer.Info[] mixers = AudioSystem.getMixerInfo();
+            if (mixers.length > 0) {
+                result = AudioSystem.getSourceDataLine(null) != null;
+            }
+        } catch (Exception e) {
+            System.err.println("Exception occured: "+e);
+        }
+        if (!result) {
+            System.err.println("Soundcard does not exist or sound drivers not installed!");
+            System.err.println("This test requires sound drivers for execution.");
+        }
+        return result;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/Clip/Duration/ClipDuration.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Clip;
+import javax.sound.sampled.DataLine;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.Mixer;
+
+/**
+ * @test
+ * @bug 4237703
+ * @summary Check that Clip.getMicrosecondLength() returns correct value.
+ */
+public class ClipDuration {
+
+    public static int run(Mixer m) {
+        int res=1; // failed
+        int frameCount = 441000; // lets say 10 seconds
+        AudioFormat f = new AudioFormat(44100.0f, 16, 2, true, false);
+        AudioInputStream audioInputStream =
+            new AudioInputStream(new ByteArrayInputStream(new byte[frameCount * f.getFrameSize()]),
+                                 f, frameCount);
+        AudioFormat     format = audioInputStream.getFormat();
+        Clip m_clip = null;
+        try {
+            if (m == null) {
+                m_clip = (Clip) AudioSystem.getClip();
+            } else {
+                DataLine.Info   info = new DataLine.Info(Clip.class, format, AudioSystem.NOT_SPECIFIED);
+                m_clip = (Clip) m.getLine(info);
+            }
+            System.out.println("Got clip: "+m_clip);
+            m_clip.open(audioInputStream);
+            long microseconds=m_clip.getMicrosecondLength();
+            System.out.println("getFrameLength()="+m_clip.getFrameLength()+" frames");
+            System.out.println("getMicrosecondLength()="+microseconds+" us");
+            if (Math.abs(microseconds-10000000)<50) {
+                System.out.println("->Clip OK");
+                res=0; // passes if less than 50us error
+            }
+        } catch (LineUnavailableException luae) {
+            System.err.println(luae);
+            res = 3; // line not available, test not failed
+        } catch (Throwable t) {
+            System.out.println("->Exception:"+t);
+            t.printStackTrace();
+            res=2; // exception
+        }
+        if (m_clip != null) {
+            m_clip.close();
+        }
+        return res;
+    }
+
+
+
+    public static void main(String[] args) throws Exception     {
+        if (isSoundcardInstalled()) {
+            int res=3;
+            res = run(null);
+            Mixer.Info[] infos = AudioSystem.getMixerInfo();
+            for (int i = 0; i<infos.length; i++) {
+                try {
+                        Mixer m = AudioSystem.getMixer(infos[i]);
+                        int r = run(m);
+                        if (r == 1) res = 1;
+                } catch (Exception e) {
+                }
+            }
+            if (res!=1) {
+                System.out.println("Test passed");
+            } else {
+                if (res==2) {
+                    System.err.println("Test could not execute: test threw unexpected Exception.");
+                    throw new Exception("Test threw exception");
+                }
+                else if (res==3) {
+                    System.err.println("Test could not execute: please install an audio device");
+                    return;
+                }
+                throw new Exception("Test returned wrong length");
+            }
+        }
+    }
+
+    /**
+     * Returns true if at least one soundcard is correctly installed
+     * on the system.
+     */
+    public static boolean isSoundcardInstalled() {
+        boolean result = false;
+        try {
+            Mixer.Info[] mixers = AudioSystem.getMixerInfo();
+            if (mixers.length > 0) {
+                result = AudioSystem.getSourceDataLine(null) != null;
+            }
+        } catch (Exception e) {
+            System.err.println("Exception occured: "+e);
+        }
+        if (!result) {
+            System.err.println("Soundcard does not exist or sound drivers not installed!");
+            System.err.println("This test requires sound drivers for execution.");
+        }
+        return result;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/sampled/Clip/Endpoint/ClipSetEndPoint.java	Mon Oct 31 14:50:09 2016 +0300
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Clip;
+import javax.sound.sampled.DataLine;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.Mixer;
+
+/**
+ * @test
+ * @bug 4385928
+ * @summary Verify that an endpoint -1 in Clip does not throw an exception
+ */
+//public class test048 extends TRTest
+public class ClipSetEndPoint {
+
+    private Clip theClip;
+
+    boolean testPassed = true;
+
+    //_______________________________________________
+    //      Method: runTest
+    //_______________________________________________
+    public boolean runTest() {
+        AudioInputStream theAudioInputStream = new AudioInputStream(
+                new ByteArrayInputStream(new byte[2000]),
+                new AudioFormat(8000.0f, 8, 1, false, false), 2000); //
+
+        AudioFormat theAudioFormat = theAudioInputStream.getFormat();
+
+        DataLine.Info info = new DataLine.Info(Clip.class, theAudioFormat,
+                                               AudioSystem.NOT_SPECIFIED);
+        try {
+            theClip = (Clip) AudioSystem.getLine(info);
+            theClip.open(theAudioInputStream);
+
+            int theStartLoopPoint = 0;
+            int theEndLoopPoint = -1;       //      -1 signifies the last frame
+
+            theClip.setLoopPoints(theStartLoopPoint, theEndLoopPoint);
+            //theClip.start();
+        } catch (LineUnavailableEx