JDK-8175915 : NullPointerException from JComboBox and JList when Accessibility enabled
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.accessibility
  • Affected Version: 8u102,9
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-02-27
  • Updated: 2017-11-29
  • Resolved: 2017-05-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 10 JDK 8 JDK 9
10Fixed 8u152Fixed 9 b172Fixed
Description
The following JList test code generates a NullPointerException (below) when the accessibility subsystem is active (imports not included):

public class TestJList extends JFrame {
    private final static String [] ANIMALS = {
            "Bird", "Cat", "Dog", "Rabbit", "Pig"
    };

    TestJList () {
        DefaultListModel<String> model = new DefaultListModel<>();
        for (String s : ANIMALS) {
            model.addElement(s);
        }

        JList<String> list = new JList<>(model);
        list.addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent e) {
                if (    e.getKeyChar() == KeyEvent.VK_ENTER
                    ||  e.getKeyCode() == KeyEvent.VK_ENTER) {

                    String s = list.getSelectedValue();
                    model.removeAllElements();
                    model.addElement(s);
                }
            }
        });

        add(list);
        pack();
    }

    public static void main(String args[]) {
        TestJList tj = new TestJList();
        tj.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        tj.setLocationRelativeTo(null);
        tj.setVisible(true);
    }

stacktrace:
....
java.lang.RuntimeException: java.lang.NullPointerException
    at com.sun.java.accessibility.AccessBridge$InvocationUtils.invokeAndWait(AccessBridge.java:7206)
    at com.sun.java.accessibility.AccessBridge$InvocationUtils.invokeAndWait(AccessBridge.java:7181)
    at com.sun.java.accessibility.AccessBridge.getAccessibleActionFromContext(AccessBridge.java:1782)
    at com.sun.java.accessibility.AccessBridge.runDLL(Native Method)
    at com.sun.java.accessibility.AccessBridge.access$300(AccessBridge.java:57)
    at com.sun.java.accessibility.AccessBridge$dllRunner.run(AccessBridge.java:141)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at javax.swing.JList$AccessibleJList$AccessibleJListChild.getAccessibleAction(JList.java:3374)
    at com.sun.java.accessibility.AccessBridge$70.call(AccessBridge.java:1785)
    at com.sun.java.accessibility.AccessBridge$70.call(AccessBridge.java:1782)
    at com.sun.java.accessibility.AccessBridge$InvocationUtils$CallableWrapper.run(AccessBridge.java:7262)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:301)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)


To reproduce the exception use the keyboard to navigate to any item in the JList after "Bird" and press the Enter key.
Comments
Fix Request : Java applications can fail with exception without the fix if it works with JAWS. The problem is easy to fix, there's debug message that doesn't have nul check, I added this check. The fix is reviewed by Sergey Bylokhov. webrev: http://cr.openjdk.java.net/~mcherkas/8175915/webrev/ review thread: http://mail.openjdk.java.net/pipermail/swing-dev/2017-May/007335.html
12-05-2017