You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Alexander Simbirtsev (JIRA)" <ji...@apache.org> on 2007/02/08 12:11:06 UTC

[jira] Commented: (HARMONY-2630) [classlib][swing] javax.swing.JMenu.createActionChangeListener(null) throws unspecified NPE while RI does not

    [ https://issues.apache.org/jira/browse/HARMONY-2630?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12471281 ] 

Alexander Simbirtsev commented on HARMONY-2630:
-----------------------------------------------

Here's the code that demonstrates that the listener returned by the RI doesn't work (and it could be expected) for item+action to which it is installed. It doesn't change the property of the item:

import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

public class Test {

    public static void main(String args[]) {
        TestJMenu menu = new TestJMenu();
        JMenuItem item = new JMenuItem();
        final PropertyChangeListener actionChangeListener = menu.createActionChangeListener(null);
        final AbstractAction action = new AbstractAction("1111") {
            public void actionPerformed(ActionEvent e) {
            }
            
            public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
                if (listener == actionChangeListener) {
                    super.addPropertyChangeListener(listener);
                }
            }
        };
        item.setAction(action);
        action.addPropertyChangeListener(actionChangeListener);
        System.err.println("Before: " + item.getText());
        action.putValue(Action.NAME, "2222");
        System.err.println("After: " + item.getText());
    }

    static class TestJMenu extends JMenu {
        public PropertyChangeListener createActionChangeListener(JMenuItem item) {
            return super.createActionChangeListener(item);
        }
    }
}

So to follow RI's behavior we can just return PropertyChangeListener that does nothing when null is passed to the method.

> [classlib][swing] javax.swing.JMenu.createActionChangeListener(null) throws unspecified NPE while RI does not
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2630
>                 URL: https://issues.apache.org/jira/browse/HARMONY-2630
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Pavel Dolgov
>            Priority: Minor
>
> Test case:
> --------------
> import java.beans.PropertyChangeListener;
> import javax.swing.JMenu;
> import javax.swing.JMenuItem;
> import junit.framework.TestCase;
> public class TheTest extends TestCase {
>     public static void main(String args[]) {
>         junit.textui.TestRunner.run(TheTest.class);
>     }
>     public void testcase1() {
>         TestJMenu jm = new TestJMenu();
>         jm.createActionChangeListener(null);
>     }
>     static class TestJMenu extends JMenu {
>         public PropertyChangeListener createActionChangeListener(JMenuItem arg0) {
>             return super.createActionChangeListener(arg0);
>         }
>     }
> }
> Harmony output:
> ----------------
> .E
> Time: 0.982
> There was 1 error:
> 1) testcase1(TheTest)java.lang.NullPointerException
> 	at javax.swing.JMenu.createActionChangeListener(JMenu.java:172)
> 	at TheTest$TestJMenu.createActionChangeListener(TheTest.java)
> 	at TheTest.testcase1(TheTest.java:15)
> 	at java.lang.reflect.VMReflection.invokeMethod(Native Method)
> 	at TheTest.main(TheTest.java:11)
> FAILURES!!!
> Tests run: 1,  Failures: 0,  Errors: 1

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.