Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5078989

Null Pointer exception in SpinnerListMode

XMLWordPrintable

    • b19
    • x86
    • windows_2000

      Name: gm110360 Date: 07/27/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_05"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
      Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)
      and
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      When the data in SpinnerListModel as a null value, Pressing any key after deleting the current value throws null pointer exception

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      When we have null data in the SpinnerListModel, we get Null pointer exception when pressing anykey in spinnner.
      In order to reproduce this bug, use the following piece of code.
      Invoke the frame.

      Put the cursor, (focus) inside spinner and then press space bar.

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

      public class SpinnerTest extends JPanel implements ActionListener
      {
         public SpinnerTest()
         {

              String[] values = {"Month: ", "Year: ", null, "Date", "Sent"};

              SpinnerListModel listModel = null;

              listModel = new SpinnerListModel(values);

              JLabel l = new JLabel("Spinner");
              add(l);

              JSpinner spinner = new JSpinner(listModel);
              l.setLabelFor(spinner);
              add(spinner);
      JButton button = new JButton("click me");

      button.addActionListener(this);
      add(button);

          }

      public void actionPerformed(ActionEvent e)
      {
      System.out.println("=============================");
      System.out.println("");
      System.out.println("e::"+e.getActionCommand());
      System.out.println("");
      System.out.println("=============================");

      }


          public static void main(String[] args) {

              JFrame.setDefaultLookAndFeelDecorated(true);

              //Create and set up the window.
              JFrame frame = new JFrame("SpinnerDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              //Set up the content pane.
              SpinnerTest newContentPane = new SpinnerTest();
              newContentPane.setOpaque(true); //content panes must be opaque
              frame.setContentPane(newContentPane);

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

      -----------------------------

      java.lang.NullPointerException

      at javax.swing.SpinnerListModel.findNextMatch(SpinnerListModel.java:221)

      at javax.swing.JSpinner$ListEditor$ListFormatter$Filter.replace(JSpinner.java:1226)

      at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:660)

      at javax.swing.text.JTextComponent.replaceSelection(JTextComponent.java:1072)

      at javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(DefaultEditorKit.java:839)

      at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1530)

      at javax.swing.JComponent.processKeyBinding(JComponent.java:2438)



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should not throw NPE
      ACTUAL -
      Throws NPE

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.NullPointerException

      at javax.swing.SpinnerListModel.findNextMatch(SpinnerListModel.java:221)

      at javax.swing.JSpinner$ListEditor$ListFormatter$Filter.replace(JSpinner.java:1226)

      at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:660)

      at javax.swing.text.JTextComponent.replaceSelection(JTextComponent.java:1072)

      at javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(DefaultEditorKit.java:839)

      at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1530)

      at javax.swing.JComponent.processKeyBinding(JComponent.java:2438)

      at javax.swing.JComponent.processKeyBindings(JComponent.java:2473)

      at javax.swing.JComponent.processKeyEvent(JComponent.java:2401)

      at java.awt.Component.processEvent(Component.java:4909)

      at java.awt.Container.processEvent(Container.java:1569)

      at java.awt.Component.dispatchEventImpl(Component.java:3615)

      at java.awt.Container.dispatchEventImpl(Container.java:1627)

      at java.awt.Component.dispatchEvent(Component.java:3477)

      at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1713)

      at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:627)

      at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:831)

      at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:741)

      at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:592)

      at java.awt.Component.dispatchEventImpl(Component.java:3506)

      at java.awt.Container.dispatchEventImpl(Container.java:1627)

      at java.awt.Window.dispatchEventImpl(Window.java:1606)

      at java.awt.Component.dispatchEvent(Component.java:3477)

      at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

      at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)



      REPRODUCIBILITY :
      This bug can be reproduced always.
      (Incident Review ID: 285321)
      ======================================================================

            psadhukhan Prasanta Sadhukhan
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: