Announcement Announcement Module
No announcement yet.
Custom Scope, JPanel and AOP scoped-bean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom Scope, JPanel and AOP scoped-bean

    I am trying to use a custom scope and it seems to work fine when simple POJO's are configured to use the scope, but if I use anything that is or derives from JPanel I suddenly get the following exception:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at javax.swing.BufferStrategyPaintManager.flushAccumulatedRegion(
    	at javax.swing.BufferStrategyPaintManager.endPaint(
    	at javax.swing.RepaintManager.endPaint(
    	at javax.swing.JComponent.paint(
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException
    	at java.util.Arrays.mergeSort(
    	at java.util.Arrays.sort(
    	at java.util.Collections.sort(
    This is a swing-related error so I am wondering if there are issues with CGLIb and Swing but I can't find anything on the net about it.

    My applicationContext.xml looks like this:
    	<bean id="mainWindow" class="MainWindow" init-method="init">
    		<property name="display"><ref bean="display1"/></property>
    	<bean id="display1" class="javax.swing.JPanel">
    		<aop:scoped-proxy />
    And here is the code for MainWindow:
    public class MainWindow extends JFrame {
    	private JPanel display;
    	public void init() {
    		setLayout(new BorderLayout());
    		setSize(200, 200);
    		add(display, BorderLayout.CENTER);
    	public JPanel getDisplay() {
    		return display;
    	public void setDisplay(JPanel display) {
    		this.display = display;
    It's about as simple as it gets but it throws the exception.

    If I comment out "add(display, BorderLayout.CENTER)" code, the exception doesn't occur.

    If I remove <aop:scoped-proxy> from the applicationContext.xml, then the panel works as normal but obviously my custom scope will not work.

    I have tried <aop:scoped-proxy proxy-target-class="false"/> which still causes an exception, but a different one:
    Caused by: java.lang.IllegalAccessError: class javax.swing.$Proxy0 cannot access its superinterface javax.swing.TransferHandler$HasGetTransferHandler
    	at java.lang.reflect.Proxy.defineClass0(Native Method)
    	at java.lang.reflect.Proxy.getProxyClass(
    	at java.lang.reflect.Proxy.newProxyInstance(
    	at org.springframework.aop.framework.JdkDynamicAopProxy.getProxy(
    I am not familiar with Spring AOP - I am just using it to get custom scopes to work. Am I doing something wrong?

    Paul Drummond