United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4910211 : "alt" key causes java.lang.NullPointerException in 1.5b14

Details
Type:
Bug
Submit Date:
2003-08-21
Status:
Closed
Updated Date:
2004-04-29
Project Name:
JDK
Resolved Date:
2003-09-05
Component:
client-libs
OS:
windows_xp,windows_2000
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.2,5.0
Fixed Versions:
1.4.2_05 (05)

Related Reports
Backport:
Duplicate:

Sub Tasks

Description
When the cursor moves on a dialogue and press "alt" key,
Thej ava.lang.NullPointerException  exception occurs both in 1.4.2fcs 
and 1.5(b14).

This issues does not occurs in 1.4.1_0X.
It seems regression.

Configration:
  OS Windows2000/WindowsXP, both are japanese edition.

Reproduce:
  1) Compile the attached test Case.
  2) Invoke " java Test'
  3) Click the "dialog" button in opened window and
     you will see a dialog appears.
  4) Move the pointer in the dialog and press the "alt" key.

The exception in the attached file "log-1.5b14.txt"  will show up.


Test Case:

==== Test.java =====>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test extends JFrame implements ActionListener {

    public JButton  button = new JButton("Dialog");

    public Test() {

        try {

            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLoo
kAndFeel");

            setSize(300,300);
            getContentPane().setBackground(Color.white);
            getContentPane().setLayout(null);
            getContentPane().add(button);

            button.setBounds(100,100,100,50);
            button.addActionListener(this) ;

            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        } catch (Exception ex) {
            System.out.println(ex);
        }

    }

    public void actionPerformed(ActionEvent e) {
        Dialog dialog = new Dialog(this,true);
        dialog.setSize(200,200);
        dialog.show();
    }

    public static void main(String[] argv) {

        Test test = new Test();
        test.show();

    }

}

<=== Test.java =====


==============================================================================

                                    

Comments
EVALUATION

The reason of this bug is that we are trying to get the window ancestor of the null component. The idea of suggested fix is to assume that null component have null window ancestor.

###@###.### 2003-08-22

Fix verified on Winxp Home for build 1.4.2_05-ea-b01
###@###.### 2004-04-29
                                     
2003-08-22
SUGGESTED FIX

------- WindowsRootPaneUI.java -------
*** /tmp/sccs.mLaOO2	Fri Aug 22 12:33:46 2003
--- WindowsRootPaneUI.java	Fri Aug 22 12:33:08 2003
***************
*** 155,161 ****
          public boolean postProcessKeyEvent(KeyEvent ev) {
              if (ev.getKeyCode() == KeyEvent.VK_ALT) {
                  root = SwingUtilities.getRootPane(ev.getComponent());
!                 winAncestor = SwingUtilities.getWindowAncestor(root);
  
                  if (ev.getID() == KeyEvent.KEY_PRESSED) {
                      if (!altKeyPressed) {
--- 155,162 ----
          public boolean postProcessKeyEvent(KeyEvent ev) {
              if (ev.getKeyCode() == KeyEvent.VK_ALT) {
                  root = SwingUtilities.getRootPane(ev.getComponent());
!                 winAncestor = (root == null ? null : 
!                         SwingUtilities.getWindowAncestor(root));
  
                  if (ev.getID() == KeyEvent.KEY_PRESSED) {
                      if (!altKeyPressed) {
                                     
2004-08-24
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
1.4.2_05
generic
tiger

FIXED IN:
1.4.2_05
tiger

INTEGRATED IN:
1.4.2_05
tiger
tiger-b19

VERIFIED IN:
1.4.2_05


                                     
2004-08-24



Hardware and Software, Engineered to Work Together