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

CardLayout, show method: NullPointerException when card doesn't exists

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.4.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      generic, x86
    • OS:
      generic, windows_2000

      Description



      Name: bsC130419 Date: 06/06/2001


      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

      class: java.awt.CardLayout
      method: public void show(Container parent, String name)

      API tells that if the component to show doesn't exists, nothing happens. This
      is the case in jdk1.3.

      In 1.4, a NullPointerException occurs because the code doesn't check for a null
      result in this line (CardLayout.java, line 449):

                  if (((Card) vector.get(currentCard)).name.equals(name))

      The code should check that vector.get(currentCard) doesn't return null.

      It was the case in 1.3:
                  if ((next != null) && !next.visible){ ... }


      Here is small application to reproduce the problem. It works fine in 1.3 but
      generates an exception in 1.4 :

      import java.awt.*;
      import javax.swing.*;

      public class Test extends JFrame {
              public Test() {
                      CardLayout layout = new CardLayout();
                      getContentPane().setLayout(layout);
                      layout.show(getContentPane(), "panel");
              }

              public static void main(String[] s){
                      (new Test()).show();
              }
      }


      (Review ID: 125931)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              son Oleg Sukhodolsky (Inactive)
              Reporter:
              bstrathesunw Bill Strathearn (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: