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

One time in 5, appletviewer fails to allocate AWT resources, and applet cannot s

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.4.1
    • Fix Version/s: None
    • Component/s: tools
    • Labels:

      Description



      Name: gm110360 Date: 04/25/2003


      FULL PRODUCT VERSION :
      java version "1.4.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

      FULL OS VERSION :
      Linux Kernel 2.4.18

      A DESCRIPTION OF THE PROBLEM :
      I have an application that can be run and works every time.
      The same code, when launched from an applet instead of an application, approx 20% of the time doesn't run. Debugging shows that the Graphics objects for the awt components added to the applets have a size of "-1,-1" - and this lasts for at least a minute (I haven't run it for much longer than that).

      Any attempt to paint to the Graphics objects are ignored.

      Note: in the other 80% of cases, the Graphics objects are initialised to their expected sizes ( approx 200,200) and everything works fine.

      I eventually found that calling ".validate()" on the Applet after the components had been added made this problem go away. Whilst this method SHOULD be called always, appletviewier should NOT crash without explanation if it is not called.

      Also, it was my understanding that calls to Applet.add( Component ) *automatically* called .validate()? Certainly, there is no need to call .validate() for the application version.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      NOTE: The small example code supplied shows the problem EVERY time - this makes it *appear* a straightforward error in the applet design.

      However, I also have a JAR file which I can email you of the original, slightly larger applet (20k source + class files) that shows the problem intermittently.

      Because the problem is intermittent with that code, I believe this is a timing error somewhere in the appletviewer?

      Compile the attached source code, and run from the attached HTML file.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Should display w and h of approx 400 or so, depending on the values in the HTML file, and it should be drawing big coloured rectangles.
      it continuously prints "width and height = 0,0" and draws NOTHING to the screen

      REPRODUCIBILITY :
      This bug can be reproduced often.

      ---------- BEGIN SOURCE ----------
      NOTE: these were compiled as separate files - you may need to split them out. And the HTML file needs to be separated out!

      <html>
         <head>
         </head>
         <body>
            <!-- Don't touch this: this is the code to start the Applet. -->
            <applet ARCHIVE="m.jar" code="testApplet.class" width="256" height="400">
            </applet>
            <!-- ...end of the code to start the Applet. -->
         </body>
      </html>

      import java.awt.*;
      import java.applet.*;

      public class testApplet extends Applet
      {
         public void start()
         {
            c myc = new c();
            myc.start( this );
            setVisible( true );
         }
      }

      import java.awt.*;
      import java.applet.*;

      public class c extends Component implements Runnable
      {
         Container container;
         public Thread myself;
         public void start( Container cont )
         {
            container = cont;
            myself = new Thread( this );
            myself.start();
         }

         public void run()
         {
            container.setLayout( new BorderLayout() );
            container.add( BorderLayout.CENTER, this );

            while( true )
            {
               try{
                  Thread.sleep( 500 );
               }catch( InterruptedException e ) {}

               repaint();
            }
         }

         public void repaint()
         {
            System.out.println( "Graphics w and h = "+getWidth()+", "+getHeight() );
            paint( getGraphics() );
         }

         public void paint( Graphics g )
         {
            Color col = Color.getHSBColor( (float)Math.random(), 1f, 1f );
            g.setColor( col );
            g.fillRect( 0,0, getWidth(), getHeight() );
         }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      calling Container.validate() makes the applet work - the bug is that SOMETIMES the applet works WITHOUT calling this method.
      (Review ID: 183476)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              ehawkessunw Eric Hawkes (Inactive)
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: