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

The java.awt.swing.JTabbedPane indexOfTab doesn't work prop. with null

XMLWordPrintable

    • swing1.0fcs
    • sparc
    • solaris_2.6
    • Verified



      Name: akC57697 Date: 12/08/97


       The java.awt.swing.JTable indexOfTab does not work properly with null.


      The documentation says:
          /**
           * Adds a <i>component</i> represented by a <i>title</b> and no icon.
           * Cover method for insertTab().
           * @see #insertTab
           */
          public void addTab(String title, Component component)
          
          /**
           * Inserts a <i>component</i>, at <i>index</i>, represented by a
           * <i>title</i> and/or <i>icon</i>, either of which may be null.
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           * Uses java.util.Vector internally, see insertElementAt()
           * for details of insertion conventions.
           * @param component The component to be displayed when this tab is clicked.
           */
          public void insertTab(String title, Icon icon, Component component, String tip, int index)


          /**
           * Convenience method for locating the first tab with a given <i>title</i>,
           * testing for equality with String.equals. Returns -1 if no tab has this title.
           */
          public int indexOfTab(String title)




      The linear search with invoking String.equals without checking for null is
      the reason of this bug.




       --------------8-<-----------------------------------
      import java.awt.swing.JTabbedPane;
      import java.awt.Component;

      public class JTabbedPaneBug {
          public static void main(String s[]) {

       Component components [] ={new JTabbedPane(),new JTabbedPane(),new JTabbedPane()};
       String names [] ={"1",null,"3"};
       int result=0;

            JTabbedPane c = new JTabbedPane();

            for(int j=0;j<components.length;j++)
              c.addTab(names[j],components[j]); //Fill the set

            try {
               result=c.indexOfTab("3"); //Try to find "3" through the null
             } catch (Exception e) {
                System.out.println("Unexpected in indexOfTab() : "+e);
               }
            
            System.exit(0);
         }
      }

       --------------8-<-----------------------------------
       The output is:
      (novo35 46): java JTabbedPaneBug
      Unexpected in indexOfTab() : java.lang.NullPointerException
      (novo35 47): java -fullversion
      java full version "JDK-1.2beta2-Y"

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

            amfowler Anne Fowler (Inactive)
            akuzminorcl Alexander Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: