JDK-8072767 : DefaultCellEditor for comboBox creates ActionEvent with wrong source object
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u20
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-02-07
  • Updated: 2021-06-10
  • Resolved: 2015-04-15
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 JDK 9 Other
8u291Fixed 9 b65Fixed openjdk8u312Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Recent implementation of JComboBox.actionPerformed(ActionEvent e) in Java 1.8 checks that the given ActionEvent source is identical with  ComboBoxEditor editor returned by getEditor().

In the same Java version EditorDelegate implementation used in DefaultCellEditor(final JComboBox comboBox) generates ActionEvent using DefaultCellEditor.this as its source in its method stopCellEditing()

comboBox.actionPerformed(new ActionEvent(
                                     DefaultCellEditor.this, 0, ""));

ComboBoxEditor and DefaultCellEditor are different things.

Therefore this call is ignored by JComboBox  in the recent Java version. Implementation of stopCellEditing in this EditorDelegate  should be fixed.

REGRESSION.  Last worked in version 7u75

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following application.

Click at cell "Kathy" , replace its content by text "Andrew". Do not hit "Enter".

Then click at cell "Smith" and replace its content by text "Brown" .  Do not hit "Enter".

Then click at cell "John", and replace its content by text "Robert" . Press TAB.


// CODE BEGIN
/*
 * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
 * Modified by Dimitry Polivaev, 2015
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 *   - Neither the name of Oracle or the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */ 

package components;

/*
 * SimpleTableDemo.java requires no other files.
 */

import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class SimpleTableDemo extends JPanel {

    public SimpleTableDemo() {
        super(new GridLayout(1,0));

        String[] columnNames = {"First Name",
                                "Last Name"};

        Object[][] data = {
	    {"Kathy", "Smith"},
	    {"John", "Doe"}};

        final JTable table = new JTable(data, columnNames);
        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
        table.setFillsViewportHeight(true);
        
        final JComboBox<Object> comboBox = new JComboBox<>();
        comboBox.setEditable(true);
		table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(comboBox));
        table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(new JTextField()));
        
        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);

        //Add the scroll pane to this panel.
        add(scrollPane);
    }


    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("SimpleTableDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the content pane.
        SimpleTableDemo newContentPane = new SimpleTableDemo();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

// CODE END


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The first table row should contain cells with content "Andrew" and "Brown".
The second line should contain cells with content "Robert" and "Doe".
ACTUAL -
The first table row contains cells with content "Smith" and "Brown".
The second line should contain cells with content "John" and "Doe

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
Use following combobox implementation:

final JComboBox<Object> comboBox =  new JComboBox(){
@Override
public void actionPerformed(ActionEvent e) {
  if(e != null && e.getSource() == table.getCellEditor())
    super.actionPerformed(new ActionEvent(getEditor(), e.getID(), e.getActionCommand(),e.getWhen(),e.getModifiers()));
  else
    super.actionPerformed(e);
};


Comments
[~andrew] The test failed again and fixed by JDK-8196093. The JDK-8196093 contains extra delay purposed by 8u patch, so it can be removed, that results clean backport of this patch. I will purpose backport JDK-8196093 and push them together.
09-06-2021

Ok, a small comment above the addition would be helpful for anyone finding it in future. Approved.
09-06-2021

It looks like a 8u specific bug, 11u passed without additional delay.
17-05-2021

Does the test fix apply to the version in trunk too? If so, it should be resolved under a separate bug.
17-05-2021

Fix Request (8u) I would like to backport this patch to 8u for parity with Oracle 8u291. 8u patch has been reviewed.
27-04-2021

8u Code review: https://mail.openjdk.java.net/pipermail/jdk8u-dev/2021-January/013330.html
18-01-2021

openjdk8u backport: I think I found the root cause why test failed on Fedora. It seems components should receive/process two RESIZE messages before layout is stable. On Fedora, test starts to execute after one RESIZE message and layout has yet to be stable, therefore, test calculates wrong cell location. Adding 500ms delay before starting execute test fixes the problem.
12-01-2021

openjdk8u backport: This backport has dependence on JDK-8074286. Strangely, it was not backported to 8u. However, test still fails on Fedora 33 most of times (not 100%). But it looks like that it is Fedora specific issue due to window location issue, which is not a case for Windows and Ubuntu. I think I will pursue 8u backport after JDK-8074286, and file bug to address Fedora issue.
12-01-2021

[~alexsch] Thanks, Alexey. We may miss some relevant backports.
12-01-2021

[~zgu] I sponsored the backport, it's a clean backport. The unmodified test passes successfully on the build with the fix applied; the test fails if the fix is not applied.
12-01-2021

openjdk8u backport: The jdk9u patch applies cleanly, but test fails. The test also failed with Oracle jdk1.8.0_271. Searched 8u281 and 8u291 backports, did not find any relevant fix. Apparently, calculated cell location is off and also needs to add delay to make test to work. diff -r 6c5759044813 test/javax/swing/JComboBox/8072767/bug8072767.java --- a/test/javax/swing/JComboBox/8072767/bug8072767.java Mon Nov 30 17:36:45 2020 +0000 +++ b/test/javax/swing/JComboBox/8072767/bug8072767.java Mon Jan 11 15:21:06 2021 -0500 @@ -64,7 +64,8 @@ Rectangle rect = table.getCellRect(0, 0, true); point.translate(rect.width / 2, rect.height / 2); }); - robot.mouseMove(point.x, point.y); + robot.delay(500); + robot.mouseMove(point.x, point.y + 10); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.waitForIdle(); @alexsch, could you shed some light on Oracle's backport? Thanks!
11-01-2021

Reproducible in 8u20 b26 on Windows 7 x64, not reproducible in 8u11 b12
03-11-2015

please evaluate, does it affect 8u20? 8 GA?
09-02-2015