JDK-5054449 : example3.html of MoleculeViewer throws NullPointerException
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_9
  • CPU: generic
  • Submitted: 2004-05-28
  • Updated: 2004-06-18
  • Resolved: 2004-06-18
Related Reports
Duplicate :  
Description
Build : Tiger Beta2 - Build 51
OS : IA 9 (Browser : MZ 1.6)
Steps to Reproduce :
====================
1. Download JDK 1.5.0 beta2 build b51 from "http://webwork.sfbay/j2se/1.5.0/download.jsp" and Install on IA 9
2. Execute example3.html of MoleculeViewer under jdk1.5.0/demo/plugin/applets on IA 9 / MZ 1.6. 
3. NullPointerException will be thrown and the cross symbol in the applet. 

Note : The exception is thrown intermittently.

   Please have a look at the exception :

   java.lang.NullPointerException
       at XYZApp.newBackBuffer(XYZApp.java:296)
       at XYZApp.init(XYZApp.java:312)
       at sun.applet.AppletPanel.run(AppletPanel.java:373)
       at java.lang.Thread.run(Thread.java:595) 
###@###.### 2004-05-28

Comments
EVALUATION This is an error in applet's code. I don't think we can consider this as regression because the error always been in the code, it just became reproducible with JRE 1.5. I am able to reproduce this problem on unix(sparc) as well. Function newBackBuffer creates image: private synchronized void newBackBuffer() { backBuffer = createImage(getSize().width, getSize().height); if (backGC != null) { backGC.dispose(); } backGC = backBuffer.getGraphics(); backSize = getSize(); } In Component's API it says that createImage(int width, int height) might return null if component is not displayable. This can be checked with isDisplayable(). I added a check to find out if isDisplayable() returns false in cases when applet throws nullPointerException. The fix is simple - before calling backBuffer.getGraphics() we should add a check to see if backBuffer is null: private synchronized void newBackBuffer() { backBuffer = createImage(getSize().width, getSize().height); if (backGC != null) { backGC.dispose(); } if (backBuffer != null){ backGC = backBuffer.getGraphics(); } backSize = getSize(); } I verified that this fixes the problem described in this bug report. ###@###.### 2004-06-02
02-06-2004