(original) (raw)

Hi Tim,

sorry for long-awaited answer, thank you for your work and here are my comments...

Reviewing the code related to 7171412 I found another issue 6770017 where 'm\_selectedItem' was added.
The purpose of that variable is to avoid surplus sending of ItemEvent when the user selects the same item once again
(combo-box send CBN\_CHANGE on Windows XP each time regardless the index chosen).
From the other side mirroring index variable is not a clear solution.
So your second version of fix is more suitable.

Retrieving field value is better by performance but requires more changes like implementation of 'initIDs()' native method
and calling it from Choice static section (when in non-headless mode) to initialize 'jfieldID' for 'selectedIndex'.

7171412 has 'medium' priority that is enough for the issue that touches a specific behavior of one component only
and is not so critical as crash or deadlock.

It would be nice to have an automatic regression test for this issue :)

Thanks,
Oleg

25.07.2012 1:31, Tim English wrote:
newb here.. Trying to follow procedure and run this by awt-dev before I dive into this.
I ran into 7171412, produced a similar test case to the one in the bug report, and then found the existing bug report.
I consider this High priority since any GUI that uses an awt Choice could be showing the end user the wrong information
if the GUI is counting on the ItemListener for correct state.
 
The code in AwtChoice::WmNotify looks like it is trying to prevent notifications if the user keeps selecting the same item over and over.
I came across a bug/feature request along those lines when searching for 7171412.
 
Possible Fix 1 update m\_selectedItem when select(int) called
 
void AwtChoice::\_Select(void \*param)
{
    JNIEnv \*env = (JNIEnv \*)JNU\_GetEnv(jvm, JNI\_VERSION\_1\_2);
    SelectStruct \*ss = (SelectStruct \*)param;
    jobject choice = ss->choice;
    jint index = ss->index;
    AwtChoice \*c = NULL;
    PDATA pData;
    JNI\_CHECK\_PEER\_GOTO(choice, done);
    c = (AwtChoice \*)pData;
    if (::IsWindow(c->GetHWnd()))
    {
        c->SendMessage(CB\_SETCURSEL, index);
+        m\_selectedItem = index;
//        c->VerifyState();
    }
done:
    env->DeleteGlobalRef(choice);
    delete ss;
}
 
Possible Fix 2 Eliminate m\_selectedItem and replace it with java object value
Only notify java if java's selected index does not match the Windows control selected index
This eliminates the m\_selectedItem so we only have 2 copies of the state instead of 3.
 
It is probably more efficient to hit the java field, directly, but I have not researched jfieldID.
This is just a first stab.       
 
MsgRouting AwtChoice::WmNotify(UINT notifyCode)
{
    if (notifyCode == CBN\_SELCHANGE) {
        int selectedItem = (int)SendMessage(CB\_GETCURSEL);
+        // tim\_english: not sure if it is legal to call from here
+        JNIEnv \*env = (JNIEnv \*)JNU\_GetEnv(jvm, JNI\_VERSION\_1\_2);
+        jobject target = GetTarget(env);
+        int javaIndex = JNU\_CallMethodByName(env, NULL, target, "getSelectedIndex", "()I").i;
+        env->DeleteLocalRef(target);

+        if (selectedItem != CB\_ERR && javaIndex != selectedItem){
\-        if (selectedItem != CB\_ERR && m\_selectedItem != selectedItem){
\-            m\_selectedItem = selectedItem;
            DoCallback("handleAction", "(I)V", selectedItem);
        }
    } else if (notifyCode == CBN\_DROPDOWN) {
 

 
 
http://hg.openjdk.java.net/jdk8/awt/jdk/rev/3a2355dcef13
 
http://hg.openjdk.java.net/jdk7u/jdk7u6/jdk/rev/3a2355dcef13
 
Any advice is appreciated..
Tim