JDK-8065081 : Intermittent NPE in Java2Demo applet on Stop/Restart in appletviewer
  • Type: Bug
  • Component: client-libs
  • Sub-Component: demo
  • Affected Version: 8u25,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • Submitted: 2014-11-17
  • Updated: 2016-01-14
  • Resolved: 2015-07-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u72Fixed 9 b76Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
JDK 9 b68, JDK 8u25 b18

ADDITIONAL OS VERSION INFORMATION :
MS Windows 7 OS, but it should be generic for all OSs.

A DESCRIPTION OF THE PROBLEM :
When "Java2Demo" applet is loaded in JDK's "appletviewer" tool with disabled just in time (JIT) compiler, occasionally "java.lang.NullPointerException" occurs on repetitive clicks on "Stop", "Restart" menu items of appletviewer's "Applet" menu. Also after "Restart" menu item is clicked at least 1 time tab navigation in "Java2Demo" applet becomes broken and sometimes obvious visual problems in the animation window can be observed.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Download a testable "jdk*demos.*" archive for corresponding platform and extract the archive to any directory.
2. Install JDK corresponding to demos downloaded in point #1.
3. Execute the following command.
<JDK_HOME_DIR>\bin\appletviewer -J-Xint <DEMOS_DIR>jfc\Java2D\Java2Demo.html
4. Select "Applet->Stop" and "Applet->Restart" multiple times in random order until "java.lang.NullPointerException" is displayed in the command line. Also it can be observed that tab navigation of "Java2Demo" applet becomes broken after the first restart of the applet.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
        at sun.dc.DuctusRenderingEngine.getAATileGenerator(DuctusRenderingEngine.java:398)
        at sun.java2d.pipe.AAShapePipe.renderPath(AAShapePipe.java:152)
        at sun.java2d.pipe.AAShapePipe.fill(AAShapePipe.java:68)
        at sun.java2d.pipe.PixelToParallelogramConverter.fill(PixelToParallelogramConverter.java:164)
        at sun.java2d.pipe.ValidatePipe.fill(ValidatePipe.java:160)
        at sun.java2d.SunGraphics2D.fill(SunGraphics2D.java:2527)
        at java2d.Intro$Surface$TxE.render(Intro.java:800)
        at java2d.Intro$Surface$Scene.render(Intro.java:638)
        at java2d.Intro$Surface.paint(Intro.java:391)
        at javax.swing.JComponent.paintChildren(JComponent.java:886)
        at javax.swing.JComponent.paint(JComponent.java:1062)
        at javax.swing.JComponent.paintChildren(JComponent.java:886)
        at javax.swing.JComponent.paint(JComponent.java:1062)
        at javax.swing.JComponent.paintChildren(JComponent.java:886)
        at javax.swing.JComponent.paint(JComponent.java:1062)
        at javax.swing.JComponent.paintChildren(JComponent.java:886)
        at javax.swing.JComponent.paint(JComponent.java:1062)
        at javax.swing.JComponent.paintChildren(JComponent.java:886)
        at javax.swing.JComponent.paint(JComponent.java:1062)
        at javax.swing.JComponent.paintChildren(JComponent.java:886)
        at javax.swing.JComponent.paint(JComponent.java:1062)
        at javax.swing.JLayeredPane.paint(JLayeredPane.java:584)
        at javax.swing.JComponent.paintChildren(JComponent.java:886)
        at javax.swing.JComponent.paintToOffscreen(JComponent.java:5254)
        at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1609)
        at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1532)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1302)
        at javax.swing.JComponent.paint(JComponent.java:1039)
        at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39)
        at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:78)
        at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:115)
        at java.awt.Container.paint(Container.java:1998)
        at javax.swing.RepaintManager$4.run(RepaintManager.java:857)
        at javax.swing.RepaintManager$4.run(RepaintManager.java:829)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:77)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:829)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:804)
        at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:753)
        at javax.swing.RepaintManager.access$1200(RepaintManager.java:65)
        at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1762)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:759)
        at java.awt.EventQueue.access$500(EventQueue.java:97)
        at java.awt.EventQueue$3.run(EventQueue.java:712)
        at java.awt.EventQueue$3.run(EventQueue.java:706)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:77)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:729)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:192)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:117)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:106)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:102)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:94)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:83)
Comments
It was discovered that "Java2Demo" applet cannot be reloaded in the browser, for example Internet Explorer 11, Firefox 37.0.2, because of another "java.lang.NullPointerException", whose call stack is specified below. -------------------- Call stack of NPE, which occurs on reloading of the demo applet in the browser. -------------------- java.lang.NullPointerException at java.awt.EventQueue$2.isDispatchThreadImpl(EventQueue.java:201) at sun.awt.SunToolkit.isDispatchThreadForAppContext(SunToolkit.java:588) at javax.swing.JComponent.revalidate(JComponent.java:4884) at javax.swing.JComponent.setFont(JComponent.java:2776) at java2d.MemoryMonitor.<init>(MemoryMonitor.java:94) at java2d.Java2Demo.<init>(Java2Demo.java:151) at java2d.Java2DemoApplet.init(Java2DemoApplet.java:122) at sun.plugin2.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Thread.java:745) -------------------------------------------------------------------------------------------------------------------------------------------- Analysis of the demo's source code shows that it is designed to be run as a standalone application with 1 "Java2Demo" instance, because the source code contains a big number of various entities and variables which are declared with "static" modifier making them singletons for the whole JVM. The fact that "java2d.Java2Demo" instance with various UI elements and other objects are singletons declared as "static", is a root cause of all problems observed during restarting and reloading of the applet either in appletviewer or a real browser. So the alternative solution for resolution of NPE errors seen after applet restarting and reloading could be to refactor code of the demo in the way which will eliminate all currently existing "static" variables and will allow 2 and more instances of "Java2Demo" exist and function normally in one JVM.
26-06-2015

The bug was reproduced on: 1. MS Windows 7 OS with: - JDK 9 b68 and "Java2Demo" from JDK 9 b68 Demos. - JDK 8u45 b15 and "Java2Demo" from JDK 8u45 b15 Demos. 2. Linux OS with: - JDK 9 b68 and "Java2Demo" from JDK 9 b68 Demos. - JDK 8u45 b14 and "Java2Demo" from JDK 8u45 b14 Demos. Analysis of the bug shows that a cause of the bug is in "Java2Demo" source code and not in JDK. Root causes of 2 parts of this bug are following: PART #1. NPE occurs intermittently on restarting of the demo applet through "Applet->Restart" in the appletviewer. The method "java2d.Intro.Surface.paint(Graphics)" calls "java2d.Intro.Surface.Scene.step(int, int)", if "Intro.Surface.thread" variable is not "null", then it ALWAYS calls "java2d.Intro.Surface.Scene.render(int, int, Graphics2D)". NPE occurs in "Intro.Surface.Scene.render", because a subsequent call "Intro.Surface.TxE.render(int, int, Graphics2D)" transfers "Intro.Surface.TxE.txShapes[i]", which equals "null", to "Graphics2D.fill(java.awt.Shape)" as "Shape" object. Root cause of NPE is the fact that, "Intro.Surface.paint" calls "Intro.Surface.Scene.render" without prior call to "Intro.Surface.Scene.step", which initializes "Intro.Surface.TxE.txShapes" with valid values, when a new instance of "Intro.Surface" was created and "Intro.Surface.thread" is not initialized yet. THE SUGGESTED SOLUTION: To edit "Intro.Surface.paint" to not call "Intro.Surface.Scene.render", if "Intro.Surface.Scene.step" is not called. PART #2. Tab navigation of the demo applet stops functioning after the applet is restarted 1 time in the appletviewer. This issue is caused by the fact that during each restart of the applet in appletviewer, appletviewer uses the same instance of "java2d.Java2DemoApplet" and calls its methods sequentially: "stop()", "init()", "start()". In its turn "Java2DemoApplet.init()" method creates a new instance of "java2d.Java2Demo" and adds it the applet's "java.awt.Container" through "getContentPane().add" method without removal of the previous instance of "java2d.Java2Demo". So after 10 restarts "Java2DemoApplet" contains and holds in memory 11 instances of "java2d.Java2Demo" components and other GUI elements. THE SUGGESTED SOLUTION: To remove all components from the applet's container by the call "getContentPane().removeAll()" in the method "Java2DemoApplet.init()" the existing applet initializing code.
19-06-2015