JDK-4703628 : SPEC: actual parameters are not verified by ShortMessage.setMessage
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-06-18
  • Updated: 2017-05-16
  • Resolved: 2003-10-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b26Fixed
Description

Name: vtR10009			Date: 06/17/2002


  Specification for the method ShortMessage.setMessage from the 
package javax.sound.midi reads:
"public void setMessage(int command, int channel, int data1, int data2)
  Sets the short message parameters for a channel message which takes one or 
two data bytes. If the message only takes one data byte, the second data byte
value passed should be 0."

  But reference implementation does not verify the data bytes and as a 
result InvalidMidiDataException is not thrown for incorrect one-byte 
messages.

This bug causes failure of new JCK test:
  api/javax_sound/midi/ShortMessage/index.html#SetMessage
  
To reproduce the bug run the following test with JDK build 1.4.1-beta-b14:
------------------------------- test.java --------------------------------
import javax.sound.midi.*;

public class test{

    public static void main(String args[]) {
        ShortMessage se = new ShortMessage();
        boolean failed = false;
        int[] ch_cmds = { ShortMessage.CHANNEL_PRESSURE, 
                ShortMessage.PROGRAM_CHANGE };

        for (int i = 0; i < ch_cmds.length; i++) {
            try {
                se = new ShortMessage();
                se.setMessage(ch_cmds[i], 2, 3, 3);
                System.err.println("  InvalidMidiDataException was not thrown: " 
                        + ch_cmds[i] + " [" + i + "]");
                failed = true;
            } catch (InvalidMidiDataException inEx) {}
        }

        if( failed ) {
            System.err.println("test failed");
            System.exit(1);
        } else {
            System.out.println("OKAY");
            System.exit(0);
        }
        
    }
}
---------------------------Logs-------------------------------------------
novo101:templates$ javac test.java; java -showversion test
java version "1.4.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)

  InvalidMidiDataException was not thrown: 208 [0]
  InvalidMidiDataException was not thrown: 192 [1]
test failed
--------------------------------------------------------------------------
======================================================================
###@###.### 2003-10-23
checked in fix

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger tiger-beta FIXED IN: tiger-beta INTEGRATED IN: tiger-b26 tiger-beta VERIFIED IN: tiger-b41
14-06-2004

EVALUATION ###@###.### 2002-06-18 "should be 0" is only a recommendation. I wouldn't expect this method to throw an exception if a non-used data byte causes an exception if not set to 0. If the submitter of this bug agrees, we should change this bug to a spec bug to reformulate the javadoc like this: "If the message only takes one data byte, the second data byte is ignored; if the message does not take any data bytes, both data bytes are iognored." This should be changed for both setMessage() methods. If we made the assertion stronger by saying (or implementing): "If the message only takes one data byte, the second data byte value should be 0.", we'd risk compatibility with existing applications, by no functional or semantic improvement of the implementation. ###@###.### 2002-07-29 In the discussion with the JCK team, we got the conclusion that fixing it by clarifying that unused parameters are ignored may have impact on third-party implementations. So this should be made a CCC request for Tiger. It should be fixed with a formulation like this: "If the message only takes one data byte, the second data byte is ignored; if the message does not take any data bytes, both data bytes are iognored.". The exception's description should be reformulated, too. Something in the sense of: "Throws: InvalidMidiDataException - if the the status and all to the MIDI message belonging data bytes do not specify a valid MIDI message"
11-06-2004

PUBLIC COMMENTS actual parameters are not verified by ShortMessage.setMessage
10-06-2004