JDK-6938583 : Unexpected NullPointerException by InputContext.endComposition()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7,7u6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x,windows_xp
  • CPU: generic,x86
  • Submitted: 2010-03-26
  • Updated: 2013-06-26
  • Resolved: 2011-12-14
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 7 JDK 8
7u40Fixed 8 b17Fixed
Related Reports
Duplicate :  
Description
SYNOPSIS
--------
Unexpected NullPointerException by InputContext.endComposition()

OPERATING SYSTEM
----------------
Windows (tested on XP, Vista, Server 2008)

FULL JDK VERSION
----------------
All 5.0, 6 and 7

DESCRIPTION:
------------
When I use JavaIM (CodePointIM) on JTextArea, unexpected
NullPointerException is happened by InputContext.endComposition()

The problem is not seen when using Japanese MS-IME.

REPRODUCTION INSTRUCTIONS
-------------------------
Testcase:
1. Copy CodePointIM.jar which is in demo\jfc\CodoPointIM directory
   to jre\lib\ext directory
2. Compile and run above test program
3. On Window menu, select "Switch Input Method"
4. Select "CodePoint Input Method"
5. Type "\u3042" and press right mouse button on JTextArea.
   Then following NullPointerException is displayed

================================================================
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at sun.swing.SwingUtilities2.getAdjustedClickCount(SwingUtilities2.java:1647)
        at javax.swing.text.DefaultCaret.mouseClicked(DefaultCaret.java:406)
        at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
        at java.awt.Component.processMouseEvent(Component.java:6433)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
        at java.awt.Component.processEvent(Component.java:6195)
        at java.awt.Container.processEvent(Container.java:2203)
        at java.awt.Component.dispatchEventImpl(Component.java:4790)
        at java.awt.Container.dispatchEventImpl(Container.java:2261)
        at java.awt.Component.dispatchEvent(Component.java:4616)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4800)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4472)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4393)
        at java.awt.Container.dispatchEventImpl(Container.java:2247)
        at java.awt.Window.dispatchEventImpl(Window.java:2671)
        at java.awt.Component.dispatchEvent(Component.java:4616)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:651)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:255)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:170)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:155)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:136)
================================================================

TESTCASE SOURCE
---------------

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Date;

class MouseEventTest2 extends JFrame implements MouseListener {
    JTextArea text;
    MouseEventTest2() {
        setTitle("MouseEventTest2");
        Container c = getContentPane();
        c.setLayout(new GridLayout(1,0));
        text = new JTextArea();
        text.addMouseListener(this);
        c.add(text);
        setSize(300,200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
    public void mouseClicked(MouseEvent me) {
        if (me.getButton() == MouseEvent.BUTTON3) {
            text.getInputContext().endComposition();
            System.out.println((new Date()).toString()+"; endComposition() is called");
        }
    };
    public void mousePressed(MouseEvent me) {};
    public void mouseReleased(MouseEvent me) {};
    public void mouseEntered(MouseEvent me) {};
    public void mouseExited(MouseEvent me) {};
    public static void main(String[] args) {
        new MouseEventTest2();
    }
}

Comments
EVALUATION The endComposition method shouldn't send anything to deinstalled DefaultCaret. Actually we shouldn't send anything to deinstalled DefaultCaret and I found code that removes listener of deinstalled DefaultCaret. But at the same time deinstalled DefaultCaret gets mouseClick notification because AWT makes copy of all listeners before notifications. Unfortunately we can't change such functionality and the best and simplest way to fix the problem is to skip mouseClicked notification for deinstalled carets.
10-11-2011