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

If getPreferredSize is called after setLayout(null), within a Frame's getNotify

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.1.7
    • client-libs
    • x86
    • windows_nt

      Name: md23716 Date: 10/25/99


      If getPreferredSize is called after setLayout(null), within a
      Frame's getNotify method, a NullPointerException is thrown.

      i.e. overriding addNotify in a Frame;

      public void addNotify()
          {
              super.addNotify();

              setLayout(null); //Remove this and problem does not occur

              setBackground(bColor);

              int i = getPreferredSize().height; //The exception is thrown here
          }

      Throws..........

      java.lang.NullPointerException: null peer
              at sun.awt.windows.WFramePeer.getMinimumSize(WFramePeer.java:28)
              at sun.awt.windows.WComponentPeer.getPreferredSize(WComponentPeer.java:123)
              at sun.awt.windows.WComponentPeer.preferredSize(WComponentPeer.java:369)
              at java.awt.Component.preferredSize(Component.java:1017)
              at java.awt.Container.preferredSize(Container.java:559)
              at java.awt.Container.getPreferredSize(Container.java:541)
              at MainFrame.addNotify(MainFrame.java:37)
              at java.awt.Window.show(Window.java:141)
              at java.awt.Component.show(Component.java:506)
              at java.awt.Component.setVisible(Component.java:468)
              at MainFrame.setVisible(MainFrame.java:25)
              at MainFrame.<init>(MainFrame.java:18)
              at MainFrame.main(MainFrame.java:10)

      Does NOT occur on Sun reference port 118.

      The problem occurs in the new native methods 'getSysMin(Max)Width'
      in awt_Window.cpp which get called with a null WWindowPeer
      reference. The methods explicitly check this and throw the observed
      'null peer' exception.
      These methods were ported into our code from a Sun fix relating to
      a previous defect (SunBug 422955).
      The g118n reference port does NOT include this fix. The g117n
      reference port DOES include this fix and throws the exception as
      per n117p and n118p.

      A note from the customer;

      Tom,
      thanks for your hint on the setLayout method. I scanned through our
      code, but could not find any occurrence of setLayout(null) for the
      failing component. Actually no setLayout at all is done for this
      component which is of type JToolBar in our case.
      .
      Unfortunately I'm not able to create a small testcase for you, as
      the problem occurs only about at every 10th application startup, and
      even then it does not occur in my development environment but on a
      system test machine in the IBM Poughkeepsie lab. To me it looks very
      much like a timing issue.
      .
      But we will try follow up on the hint you gave with the setLayout()
      method and see if there is something we can do to solve our problem.

      In case you might want to have a look at our code or even tryout the
      product itself you can go to our webpage and download the latest
      version (45). It is available as installable as well as a zipfile
      containing all of our sourcecode. The relevant part is SMAppl.java,
      located in bbon/html/classes/com/ibm/cb390sm. In case you don't want
      to download the whole source, here is just that one part:

      (/defects/11684/SMAppl.java)

      The method where to exception occurs is doShowToolbar().

      The webpage is: CB390 Systems Management EUI
      (http://boedom1.boeblingen.de.ibm.com/domino/webnsf/s_390sw/
              ha3151/ha3151.nsf/lookup/CB390+Systems+Management+EUI)
      -----------------------------
      Note by Phil Vickers, JTC, IBM

      This bug is caused by the declaration of the native
      methods 'getSysMinWidth' and 'getSysMinHeight' in
      WWindowPeer.java.

      They are declared as static native int and the JNI
      does not therefore pass 'this' as the self
      Hsun_awt_windows_WWindowPeer* parameter
      across the JNI.

      This could be cured in two ways :-

      (1) Remove check on 'self' in the awt_Window.cpp
      native methods. As all they do is call Win32 APIs
      and return a primitive type this should be OK.

      However, I think the more elegant solution is to
      change the Java native method declaration to
      'public native int' whence all is well.

      After discussing this with Matthew White, who did the
      Sun port, we decided that the designers original
      intent was probably to make the new methods static and
      that there is a simple mistake made in copying a function
      template inside awt_Window.cpp

      I'll remove the check on 'self' in this code and add a
      comment to warn that the method is static.




      (Review ID: 96965)

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

            Unassigned Unassigned
            mdevereuorcl Michelle Devereux (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: