United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6938583 Unexpected NullPointerException by InputContext.endComposition()
JDK-6938583 : Unexpected NullPointerException by InputContext.endComposition()

Details
Type:
Bug
Submit Date:
2010-03-26
Status:
Resolved
Updated Date:
2013-06-26
Project Name:
JDK
Resolved Date:
2011-12-14
Component:
client-libs
OS:
os_x,windows_xp
Sub-Component:
javax.swing
CPU:
x86,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
7,7u6
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Duplicate:

Sub Tasks

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.
                                     
2011-11-10



Hardware and Software, Engineered to Work Together