United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4703628 SPEC: actual parameters are not verified by ShortMessage.setMessage
JDK-4703628 : SPEC: actual parameters are not verified by ShortMessage.setMessage

Details
Type:
Bug
Submit Date:
2002-06-18
Status:
Closed
Updated Date:
2004-03-12
Project Name:
JDK
Resolved Date:
2003-10-24
Component:
client-libs
OS:
generic
Sub-Component:
javax.sound
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.1
Fixed Versions:
5.0 (b26)

Related Reports

Sub Tasks

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
PUBLIC COMMENTS

actual parameters are not verified by ShortMessage.setMessage
                                     
2004-06-10
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"
                                     
2004-06-11
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


                                     
2004-06-14



Hardware and Software, Engineered to Work Together