{"record":{"id":"23e34078bc987c53","repo":"openjdk/jdk","slug":"s-d-invalid-message-message-status-0x-x-while","errorCode":null,"errorMessage":"%s: %d->Invalid message: message status=0x%X while sending short message\n","messagePattern":"(.+?): (.+?)->Invalid message: message status=0x%X while sending short message\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_MidiOut.c","lineNumber":156,"sourceCode":"                    break;\n                case 0xF3:    // Song select\n                    //fprintf(stderr, \">>>MIDI_OUT_SendShortMessage: Song select....\\n\");\n                    nData = 2;\n                    break;\n\n                case 0xF2:    // Song position pointer\n                    //fprintf(stderr, \">>>MIDI_OUT_SendShortMessage: Song position pointer....\\n\");\n                    nData = 3;\n                    break;\n\n                case 0xF6:    // Tune request\n                    //fprintf(stderr, \">>>MIDI_OUT_SendShortMessage: Tune request....\\n\");\n                    nData = 1;\n                    break;\n\n                default:\n                    // Invalid message\n                    fprintf(stderr, \"%s: %d->Invalid message: message status=0x%X while sending short message\\n\",\n                            __FILE__, __LINE__, data[0]);\n                    byteIsInvalid = TRUE;\n                    break;\n            }\n            break;\n        }\n\n        default:\n            // This can't happen, but handle it anyway.\n            fprintf(stderr, \"%s: %d->Invalid message: message status=0x%X while sending short message\\n\",\n                    __FILE__, __LINE__, data[0]);\n            byteIsInvalid = TRUE;\n            break;\n    }\n\n    if (byteIsInvalid) return -1;\n\n    MIDIPacketListAdd(packetList, sizeof(mBuffers), packet, 0, nData, data);","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_MidiOut.c#L138-L174","documentation":"Emitted by the macOS CoreMIDI MIDI output port when MIDI_OUT_SendShortMessage receives a short message whose status byte falls into the 0xF0..0xF7 system-common range but is not one of the recognized codes (only Song Position Pointer 0xF2 needs 3 bytes and Tune Request 0xF6 needs 1 are handled). The native switch hits its inner 'default: Invalid message' branch, sets byteIsInvalid, and the function returns -1 without sending anything to the endpoint. It is a data-validation error in the status-byte dispatch table of PLATFORM_API_MacOSX_MidiOut.c.","triggerScenarios":"Calling javax.sound.midi.Receiver.send() / MidiDevice.getReceiver().send() with a ShortMessage whose status is an unhandled system-common byte such as 0xF1 (MIDI Time Code), 0xF3 (Song Select), 0xF4, 0xF5 (undefined), or 0xF7 (EOX) as the leading byte; also any 0xFn byte the switch did not map. Occurs only on macOS because the dispatch logic is platform-specific.","commonSituations":"Hand-built Sysex/short-message byte arrays passed through ShortMessage.setMessage(int,...) with raw ints; porting MIDI code from Windows (where the win32 MM API accepts these bytes) to macOS; test fixtures that iterate over all 0x80-0xFF status values; misinterpreting running-status data where a data byte is mistakenly used as status.","solutions":["Validate the status byte on the Java side before send(): reject anything outside 0x80-0xEF plus 0xF2/0xF6 for short messages on macOS","Send system-realtime bytes (0xF8-0xFF) only — they are handled; route other system-common messages through SysexMessage/long-message APIs","Check your message construction: use ShortMessage.setMessage(command, channel, data1, data2) rather than setMessage(status) with raw status ints","If you must send 0xF1/0xF3, wrap the send and ignore the -1 return plus stderr line, or use a different MIDI backend"],"exampleFix":"// before\nint status = 0xF1; // MIDI Time Code quarter frame\nmsg.setMessage(status, 0, 0);\nreceiver.send(msg, -1); // macOS: prints 'Invalid message ... 0xF1', returns -1\n\n// after\nint status = 0xF1;\nif (status == 0xF2 || status == 0xF6 || (status >= 0xF8 && status <= 0xFF)\n        || (status >= 0x80 && status <= 0xEF)) {\n    msg.setMessage(status, 0, 0);\n    receiver.send(msg, -1);\n} else {\n    // system-common not supported as a short message here; skip or log\n}","handlingStrategy":"validation","validationCode":"// before receiver.send(msg, -1)\nprivate static final int REALTIME_MIN = 0xF8;\nstatic boolean isSupportedShortStatus(int status) {\n    return (status >= 0x80 && status <= 0xEF)      // channel voice\n        || status == 0xF2 || status == 0xF6        // song pos, tune request\n        || (status >= REALTIME_MIN && status <= 0xFF); // realtime\n}\nif (!isSupportedShortStatus(msg.getStatus())) {\n    // log and drop instead of native 'Invalid message' + return -1\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never construct ShortMessage with raw 0xF0-0xF7 system-common statuses on macOS","Centralize all message construction in one factory that validates status bytes","Add unit tests iterating status 0x00-0xFF through your send path to catch unsupported values early"],"tags":["midi","macos","native","validation","javax-sound"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}