bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug awt/30576] New: Constructor for Window calls overridable method


From: bmeike at d2tech dot com
Subject: [Bug awt/30576] New: Constructor for Window calls overridable method
Date: 24 Jan 2007 17:56:52 -0000

The following code fails with an NPE:

include java.awt.Window;

public class MyWindow extends Window {

    private final Button button = new Button("Stop");

    public void invalidate() {
        // ...
        button.invalidate();

        //...
    }
}

The reason for the failure is that MyWindow().invalidate() will be called
*before* the MyWindow object is constructed.  This is because Window's
constructor calls setLayout, which, in turn, calls invalidate.

I believe that the general rule is that constructors should not call
overridable methods.  Perhaps the call to invalidate should be put
on the EventQueue?


-- 
           Summary: Constructor for Window calls overridable method
           Product: classpath
           Version: 0.93
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: awt
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bmeike at d2tech dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30576





reply via email to

[Prev in Thread] Current Thread [Next in Thread]