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

validate() treewalk can fail to visit invalid subcomponents

    Details

    • Subcomponent:
    • Resolved In Build:
      1.0.2
    • CPU:
      sparc
    • OS:
      solaris_2.4
    • Verification:
      Verified

      Description

      In the following test case, the treewalk done by validate()
      fails to visit all nodes of the tree, leaving parts of the layout
      not updated.

      This occurs because validate() does not recurse into a component
      if the component is valid, but yet invalidity does not propagate up
      to all levels of the tree.

      awt.Container.java:
          /**
           * Validates this Container and all of the components contained within it.
           * @see #validate
           * @see #invalidate
           */
          public synchronized void validate() {
      super.validate();
      for (int i = 0 ; i < ncomponents ; i++) {
      Component comp = component[i];
      if (!comp.valid) {
      comp.validate();
      }
      }
          }

      Test case:

      ////////////////////////////////////////////////////////////////////////////
      //
      // @(#)ValidateTree.java 1.1 26 Oct 1995 17:52:21
      //
      // Copyright 26 Oct 1995 Sun Microsystems, Inc. All Rights Reserved
      //
      ////////////////////////////////////////////////////////////////////////////

      package test;
      import java.awt.*;

      public class ValidateTree extends Frame {

      public static void main(String[] args) {
          ValidateTree w = new ValidateTree();
          w.init();
      }

      private Button b;
      private Label label;

      private Panel panel1;
      private StiffPanel panel2;


      public void init() {
          setLayout(new FlowLayout());

          panel1 = new StiffPanel();
          add(panel1);
          panel1.reshape(0,0,300,100);

          panel2 = new StiffPanel2();
          panel1.add(panel2);
          panel2.reshape(0,0,300,100);

          b = new Button("Push Me");
          panel2.add(b);

          resize(300, 100);
          show();
      }

      public boolean action(Event e, Object o) {
          System.out.println("Pushed b");
          if (e.target==b) {
      System.out.println("Panel 2 is "
      + (panel2.isValid() ? "valid" : "invalid"));
      System.out.println("Panel 1 is "
      + (panel1.isValid() ? "valid" : "invalid"));

      System.out.println("Invalidating Panel 2");
      panel2.invalidate();
      return true;
          } else {
      return false;
          }
      }

      }

      class StiffPanel extends Panel {
      public void validate() {
          System.out.println("Validating " + this);
          super.validate();
      }
      public Dimension preferredSize() {
          return size();
      }
      }

      class StiffPanel2 extends StiffPanel {
      }

        Attachments

          Activity

            People

            • Assignee:
              duke J. Duke (Inactive)
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: