United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-7169161 : JRE 7u4 causes NoClassDefFoundError exception in nimbus AbstractRegionPainter

Details
Type:
Bug
Submit Date:
2012-05-16
Status:
Open
Updated Date:
2014-12-12
Project Name:
JDK
Resolved Date:
Component:
client-libs
OS:
windows_7
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Unresolved
Affected Versions:
7u4
Targeted Versions:
9

Related Reports

Sub Tasks

Description
FULL PRODUCT VERSION :
JDK:
java version "1.6.0_27"
Java(TM) SE Runtime Environment (build 1.6.0_27-b07)
Java HotSpot(TM) Client VM (build 20.2-b06, mixed mode, sharing)

JRE:
Java Plug-in 10.4.1.255
Using JRE version 1.7.0_04-b22 Java HotSpot(TM) Client VM

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]java

A DESCRIPTION OF THE PROBLEM :
Hi,

We have a web application that extends the Nimbus LaF library with custom painters for various controls. The applet is built against JDK 6u27, and runs as expected against JRE 6.x, however we have run into issues when running it against JRE 7u4. The issue appears to be that the AbstractRegionPainter.PaintContext class cannot be found at runtime and causes the virtual machine to hang. We realise that Nimbus has been moved into javax.swing in Java 7, and that com.sun.java.swing.plaf.nimbus.AbstractRegionPainter (which we import) now inherits from javax.swing.plaf.nimbus.AbstractRegionPainter, however surely we should still be able to instantiate a PaintContext in our Painter class at runtime?! When calling "this.ctx = new PaintContext(insets, dims, inverted);" in our Painter's constructor, I see the following callstack in Eclipse:

Thread [AWT-EventQueue-2] (Suspended)
InvocationEvent.dispatch() line: not available
EventQueue.dispatchEventImpl(AWTEvent, Object) line: not available
EventQueue.access$000(EventQueue, AWTEvent, Object) line: not available
EventQueue$3.run() line: not available
EventQueue$3.run() line: not available
AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]
ProtectionDomain$1.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext, AccessControlContext) line: not available
EventQueue.dispatchEvent(AWTEvent) line: not available
EventDispatchThread.pumpOneEventForFilters(int) line: not available
EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: not available
EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: not available
EventDispatchThread.pumpEvents(int, Conditional) line: not available
EventDispatchThread.pumpEvents(Conditional) line: not available
EventDispatchThread.run() line: not available

Using the current thread's Class Loader I have been able to confirm that Class.forName("com.sun.java.swing.plaf.nimbus.AbstractRegionPainter$PaintContext"...) returns null, but Class.forName("javax.swing.plaf.nimbus.AbstractRegionPainter$PaintContext"...) returns a valid class. Using this class I have been able to instantiate a PaintContext manually, however I get a VM hang when casting and/or assigning it to the Painter's PaintContext member variable.

If we remove all Nimbus custom painters the applet works as expected, however this is not an acceptable solution. We are concerned that as our clients start to update their Java installations to version 7 they will be unable to run our applet. Has anyone encountered this before or might have any suggestions about how we can proceed here?

Thanks,
Mark.

====== EDIT
Thought I'd attach the console dump in case it helps diagnose this issue:

Java Plug-in 10.4.1.255
Using JRE version 1.7.0_04-b22 Java HotSpot(TM) Client VM
network: Cache entry not found [url: https://localhost/webiress2_local/com/sun/java/swing/plaf/nimbus/AbstractRegionPainter$PaintContext.class, version: null]
network: Connecting https://localhost/webiress2_local/com/sun/java/swing/plaf/nimbus/AbstractRegionPainter$PaintContext.class with proxy=DIRECT
network: Connecting https://localhost/webiress2_local/com/sun/java/swing/plaf/nimbus/AbstractRegionPainter$PaintContext.class with cookie <snip>
Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: com/sun/java/swing/plaf/nimbus/AbstractRegionPainter$PaintContext
at webiress.ctrls.laf.WebiressNimbusTheme.setup(WebiressNimbusTheme.java:33)
at webiress.ctrls.GraphicsUtil.setNimbusLookAndFeel(GraphicsUtil.java:1061)
at webiress.ctrls.GraphicsUtil.setTheme(GraphicsUtil.java:1082)
at webiress.ctrls.GraphicsUtil.setTheme(GraphicsUtil.java:1013)
at webiress.base.ControllerPanel.init(ControllerPanel.java:429)
at webiress.base.ControllerApplet.guiInit(ControllerApplet.java:95)
at webiress.base.ControllerApplet$1.run(ControllerApplet.java:78)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.sun.java.swing.plaf.nimbus.AbstractRegionPainter$PaintContext
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 21 more

REGRESSION.  Last worked in version 6u31

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
(1) create an application that uses the Nimbus LaF.
(2) create a custom Painter class that extends AbstractRegionPainter
(3) inside Painter constructor create a PaintContext instance, assign to member variable (ie. PaintContext m_ctx = new PaintContext(insets, dims, inverted)
(3) build application against JDK 6u27
(4) run application against JRE 7u4
(6) observe AbstractRegionPainter$PaintContext class not found exception in debug log

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
PaintContext class should be found.

We note that com.sun.java.swing.plaf.nimbus.AbstractRegionPainter extends from javax.swing.plaf.niimbus.AbstractRegionPainter in Java7, but there is no similar treatment for subclasses of AbstractRegionPainter.
ACTUAL -
Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: com/sun/java/swing/plaf/nimbus/AbstractRegionPainter$PaintContext

Caused by: java.lang.ClassNotFoundException: com.sun.java.swing.plaf.nimbus.AbstractRegionPainter$PaintContext
	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
==================================================
// AbstractRegionPainterBug.java
==================================================
import javax.swing.JFrame;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class AbstractRegionPainterBug extends JFrame {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		LookAndFeel nimbus = new com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel();
		NimbusExt.setup(nimbus.getDefaults());
		try
		{
			UIManager.setLookAndFeel(nimbus);
		} catch (UnsupportedLookAndFeelException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

==================================================
// NimbusExt.java
==================================================
import java.awt.Dimension;
import java.awt.Insets;

import javax.swing.UIDefaults;

public class NimbusExt {
	public static void setup(UIDefaults defaults)
	{
		defaults.put("Button[Default].backgroundPainter", new Painter(Painter.BACKGROUND_DEFAULT, new Insets(7, 7, 7, 7), new Dimension(104, 33), false));
	}
	
}

==================================================
// Painter.java
==================================================
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Insets;

import javax.swing.JComponent;

import com.sun.java.swing.plaf.nimbus.AbstractRegionPainter;

public class Painter extends AbstractRegionPainter {

    static final int BACKGROUND_DEFAULT = 1;

    private int state; //refers to one of the static final ints above
    private PaintContext ctx;

    public Painter(int state, Insets insets, Dimension dims, boolean inverted) {
        super();
        this.state = state;
        this.ctx = new PaintContext(insets, dims, inverted);
    }

	@Override
	protected void doPaint(Graphics2D arg0, JComponent arg1, int arg2,
			int arg3, Object[] arg4) {
		// TODO Auto-generated method stub

	}

	@Override
	protected PaintContext getPaintContext() {
		// TODO Auto-generated method stub
		return null;
	}
}


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
The only workaround that we have found is to disable all Nimbus painter extension classes.  This breaks our per-client customisation of our applet and so is not a viable option for us.

                                    

Comments
not a regression for 8 and 9
                                     
2014-12-12
 - this is an issue reported against 7(7u),
 - there are now affected version 9 filed for this issue
 - 7u issues are transferred to Sustaining
Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9
or
7u specific escalations might be reopen to Sustaining
                                     
2014-08-10
 - this is an issue reported against 7(7u),
 - there are now affected version 9 filed for this issue
 - 7u issues are transferred to Sustaining
Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9
or
7u specific escalations might be reopen to Sustaining
                                     
2014-08-10



Hardware and Software, Engineered to Work Together