JDK-7157829 : Choice control doesn't respond properly after call to select(pos)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-03-29
  • Updated: 2013-07-10
  • Resolved: 2013-05-22
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.
JDK 8
8Resolved
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
If a user selects a value in a Choice control, the control is then reset programatically via control.select(0), and the user then reselects the same value, the item state change callback is not fired and control.getSelectedIndex() will return 0 instead of the index of the selected value.  The control visually shows the proper selected item.

This behavior did not occur in prior java versions up through Java 6.

REGRESSION.  Last worked in version 6u31

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute provided test Applet under Java 6 and Java 7.

1. Select value "BBB" from Choice.
2. Press "Index" button, current selected index/value of Control "BBB" (1)  is printed to System.out
3. Press "Reset" button, control displays "AAA" again.
4. Select value "BBB" from Choice
5. Press "Index" button again, "BBB" (1) is printed again


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Output from run on 1.6.0_31

Java Version: 1.6.0_31
Choice changed BBB (1)
Choice is BBB (1)
Reset choice to 0
Choice changed BBB (1)
Choice is BBB (1)
ACTUAL -
Output from run on 1.7.0_03

Note that "Choice changed" output from item state callback is missing following the "Reset choice..." output.  The selected output from the second press of the "Index" button reports "AAA" (0) even though the control visually displays "BBB".

Java Version: 1.7.0_03
Choice changed BBB (1)
Choice is BBB (1)
Reset choice to 0
Choice is AAA (0)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.applet.Applet;
import java.awt.Button;
import java.awt.Choice;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;


public class ChoiceBug extends Applet implements ActionListener, ItemListener {

	Choice c;
	Button reset;
	Button index;
	
	public void start()
	{
		String ver = System.getProperty("java.version");
		System.out.println("Java Version: "+ver);
		
		c = new Choice();
		c.add("AAA");
		c.add("BBB");
		c.add("CCC");
		c.addItemListener(this);
		
		add(c);
		
		reset = new Button("Reset");
		reset.addActionListener(this);
		
		add(reset);
		
		index = new Button("Index");
		index.addActionListener(this);
		
		add(index);
	}

	public void actionPerformed(ActionEvent arg0) {
		Object src = arg0.getSource();
		
		if (src == reset) {
			c.select(0);
			System.out.println("Reset choice to 0");
		} else if (src == index)
			System.out.println("Choice is "+c.getSelectedItem()+" ("+c.getSelectedIndex()+")");
	}

	public void itemStateChanged(ItemEvent arg0) {
		System.out.println("Choice changed "+c.getSelectedItem()+" ("+c.getSelectedIndex()+")");
	}
}
---------- END SOURCE ----------

Comments
Duplicates JDK-7171412 which was fixed in 8 but was not backported to 7.
23-04-2013

EVALUATION This is a regression of CR 6770017. I have reverted the change and the problem desapeared.
17-05-2012

EVALUATION This is not a regression for 7u releases. The test fails with jdk7b147.
11-05-2012