Path: blob/master/test/jdk/javax/sound/midi/SysexMessage/SendRawSysexMessage.java
41153 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.sound.midi.MidiDevice;24import javax.sound.midi.MidiMessage;25import javax.sound.midi.MidiSystem;26import javax.sound.midi.MidiUnavailableException;27import javax.sound.midi.Receiver;28import javax.sound.midi.ShortMessage;29import javax.sound.midi.SysexMessage;3031import static javax.sound.midi.SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE;32import static javax.sound.midi.SysexMessage.SYSTEM_EXCLUSIVE;3334/**35* @test36* @bug 823749537* @summary fail with a dereferenced memory error when asked to send a raw 0xF738*/39public final class SendRawSysexMessage {4041private static final class RawMidiMessage extends MidiMessage {42@Override43public RawMidiMessage clone() {44return new RawMidiMessage(getMessage());45}46@Override47public int getStatus() {48return SYSTEM_EXCLUSIVE; // not that this really matters49}5051RawMidiMessage(byte[] data) {52super(data.clone());53}54}5556public static void main(String[] args) throws Exception {57MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();58System.err.println("List of devices to test:");59for (int i = 0; i < infos.length; i++) {60System.err.printf("\t%d.\t%s%n", i, infos[i]);61}62for (int i = 0; i < infos.length; i++) {63System.err.printf("%d.\t%s%n", i, infos[i]);64try {65test(infos[i]);66} catch (MidiUnavailableException ignored){67// try next68}69}70}7172private static void test(MidiDevice.Info info) throws Exception {73try (MidiDevice device = MidiSystem.getMidiDevice(info)) {74System.err.println("Sending to " + device + " (" + info + ")");75if (!device.isOpen())76device.open();77try (Receiver r = device.getReceiver()) {78System.err.println("note on");79r.send(new ShortMessage(ShortMessage.NOTE_ON, 5, 5), -1);80System.err.println("sysex");81r.send(new SysexMessage(new byte[]{82(byte) SYSTEM_EXCLUSIVE, 0x0, 0x03, 0x04,83(byte) SPECIAL_SYSTEM_EXCLUSIVE}, 5), -1);84System.err.println("raw 1");85r.send(new RawMidiMessage(new byte[]{86(byte) 0x02, 0x02, 0x03, 0x04}), -1);87System.err.println("raw 2");88r.send(new RawMidiMessage(new byte[]{89(byte) 0x09, 0x02, 0x03, 0x04}), -1);90System.err.println("raw 3");91r.send(new RawMidiMessage(new byte[]{92(byte) SYSTEM_EXCLUSIVE, 0x02, 0x03, 0x04}), -1);93System.err.println("raw 4");94r.send(new RawMidiMessage(new byte[]{95(byte) 0x02, 0x02, 0x03, 0x04}), -1);96System.err.println("raw 5");97r.send(new RawMidiMessage(new byte[]{98(byte) 0x02, 0x02, 0x03,99(byte) SPECIAL_SYSTEM_EXCLUSIVE}), -1);100System.err.println("raw 6");101r.send(new RawMidiMessage(new byte[]{102(byte) SYSTEM_EXCLUSIVE, 0x02, 0x03, 0x04}), -1);103System.err.println("sleep");104Thread.sleep(1000);105System.err.println("raw 7");106r.send(new RawMidiMessage(new byte[]{107(byte) 0x02, 0x02, 0x03, 0x04}), -1);108System.err.println("sleep");109Thread.sleep(1000);110System.err.println("raw 8");111r.send(new RawMidiMessage(new byte[]{112(byte) SPECIAL_SYSTEM_EXCLUSIVE}), -1);113System.err.println("note off");114r.send(new ShortMessage(ShortMessage.NOTE_OFF, 5, 5), -1);115System.err.println("done, should quit");116System.err.println();117}118}119}120}121122123