Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4072197

EventSetDescriptor should test for null listenerMethodName string

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2beta2
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Description



      Name: dsC58869 Date: 08/15/97



      EventSetDescriptor(Class,String,Class,String listenerMethodNames[],String,String)
      works wrong when one of the listenerMethodNames elements is null.

      It creates an EventSetDescriptor object but a call to
      getListenerMethodDescriptors() results in NullPointerException.

      This constructor should either throw a NullPointerException or
      ignore null listenerMethodNames elements.

      Other constructors work the same way.

      ==== Here is the test demonstrating the bug ====
       import java.beans.*;
       import java.lang.reflect.*;
       import java.awt.event.ActionListener;

       class SourceClass {
          public void addActionListener(ActionListener foo) {
          }

          public void removeActionListener(ActionListener foo) {
          }
        }

        class Listener {
          public void action(java.util.EventObject e) {};
          public void event(java.util.EventObject e) {};
          public void dummy(java.util.EventObject e) {};
        }

       public class Test1 {
           public static void main(String[] args){
              Class souceClass = SourceClass.class;
              String eventSetName = "action";
              Class listenerType = Listener.class;
              String listenerMethods[] = {"action","event",null,"dummy"};
              String addListenerMethodName = "addActionListener";
              String removeListenerMethodName = "removeActionListener";
              EventSetDescriptor esd;
      try{
                esd = new EventSetDescriptor(souceClass,
                               eventSetName, listenerType, listenerMethods,
                               addListenerMethodName,removeListenerMethodName);
      } catch (IntrospectionException ie) {
                  System.out.println(ie);
                  return;
              }
              try{
                 MethodDescriptor[] mds = esd.getListenerMethodDescriptors();
              } catch (NullPointerException npe) {
                   npe.printStackTrace();
              }
           }
       }
       
      ==== Here is the output of the test ====

      %java Test1
      java.lang.NullPointerException
      at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:39)
      at java.beans.EventSetDescriptor.getListenerMethodDescriptors(EventSetDescriptor.java:217)
      at Test1.main(Test1.java:37)


      ======================================================================

      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ghamiltosunw Graham Hamilton (Inactive)
              Reporter:
              dsilaev Dmitri Silaev
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: