-
Bug
-
Resolution: Fixed
-
P4
-
1.2.0
-
1.2fcs
-
sparc
-
solaris_2.5
-
Verified
Name: dsC58869 Date: 04/13/98
The method java.awt.Choice.select(int pos) works wrong with negative parameter.
In this case it should throw IllegalArgumentException (by Java 1.2 API Docs):
/**
* Sets the selected item in this <code>Choice</code> menu to be the
* item at the specified position.
* @param pos the positon of the selected item.
* @exception IllegalArgumentException if the specified
* position is invalid.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* @see java.awt.Choice#getSelectedItem
* @see java.awt.Choice#getSelectedIndex
*/
But it accepts the negative value.
==== Here is the test demonstrating the bug ====
import java.awt.*;
public class Test{
public static void main(String[] args){
String item0 = "Item 0";
String item1 = "Item 1";
String item2 = "Item 2";
Choice ch = new Choice();
ch.add(item0);
ch.add(item1);
ch.add(item2);
try {
ch.select(-10);
} catch (IllegalArgumentException iae) {
System.out.println("OKAY: IllegalArgumentException thrown");
System.exit(0);
}
}
}
==== Here is the output of the test ====
%java Test
FAILED: IllegalArgumentException expected
======================================================================
Justification:
The method should work properly
======================================================================