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

method Choice.remove(String item) incorrectly changes selected item

XMLWordPrintable

    • sparc
    • solaris_2.5



      Name: dsC58869 Date: 04/09/98



      The method java.awt.Choice.remove(String item) works wrong
      while removing non-selected item. It should adjust the selected item index,
      otherwise the selected item may change.


      ==== Here is the test demonstrating the bug ====
      import java.awt.*;

      public class Test{
          
          public static void main(String[] args){
      String item0 = "Item 0";
      String item1 = "Item 1";
      String item2 = "Item 2";
      Choice ch = new Choice();
      ch.add(item0);
      ch.add(item1);
      ch.add(item2);
      ch.select(item1);
      System.out.println("Selected item : " + ch.getSelectedItem());
      System.out.println("Selected index: " + ch.getSelectedIndex());
      System.out.println("Remove Item 0");
      ch.remove(item0);
      System.out.println("Selected item : " + ch.getSelectedItem());
      System.out.println("Selected index: " + ch.getSelectedIndex());
      if(ch.getSelectedItem().equals(item1) && ch.getSelectedIndex() == 0)
      System.out.println("OKAY");
      else
      System.out.println("FAILED: selected item was changed");
          }
      }


      ==== Here is the output of the test ====
      %java Test
      Selected item : Item 1
      Selected index: 1
      Remove Item 0
      Selected item : Item 2
      Selected index: 1
      FAILED: selected item was changed
      ^C
      ======================================================================
       Justification:
      There is no reason to change selected item

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

            duke J. Duke
            dsilaev Dmitri Silaev
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: