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

Inconsistencies in method values in calls to InvocationHandler.invoke()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.4.0
    • core-libs
    • beta2
    • x86
    • windows_2000
    • Verified



      Name: bsC130419 Date: 06/19/2001


      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

      1. Compile and run the sample code

      You should see:

      Invoking public abstract boolean java.util.List.removeAll(java.util.Collection"

      printed in the console

      2. Comment out line "add( new JLabel("Test") );" from test2 constructor.
      3. Compile and run

      Now, the console will show:

      Invoking public abstract boolean java.util.Collection.removeAll
      (java.util.Collection)

      The method values passed to the invoke function in sample runs are
      inconsistent. The second value is plain wrong, in both cases, the method value
      should be java.util.List.removeAll(...)

      -------------------------------------------------------------------

      import java.lang.reflect.*;
      import java.util.*;
      import javax.swing.*;

      public class test2 extends JPanel
      {
         private List l = (List)ListModelAdapter.create( Collections.synchronizedList
      ( new ArrayList() ) );

         public static void main( String[] args )
         {
            new test2();
         }

         public test2()
         {
            l.add("1");
            l.add("2");
            
            l.removeAll(l);

            add( new JLabel("Test") );
         }

         public static class ListModelAdapter extends AbstractListModel
            implements javax.swing.ListModel, InvocationHandler
         {
            private List list;
            
            private static Method List_removeAll;
            
            static
            {
               try
               {
                  List_removeAll = List.class.getMethod( "removeAll", new Class[]
      {Collection.class} );
               }
               catch( NoSuchMethodException ex )
               {
                  throw new NoSuchMethodError(ex.getMessage());
               }
            }
            
            public static MyListModel create( List list )
            {
               MyListModel proxy = (MyListModel)Proxy.newProxyInstance(
                                MyListModel.class.getClassLoader(),
                                new Class[] {MyListModel.class},
                                new ListModelAdapter( list ) );
               
               return proxy;
            }
            
            private ListModelAdapter( List list )
            {
               this.list = list;
            }
            
            public Object getElementAt( int index )
            {
               return list.get(index);
            }
            
            public int getSize()
            {
               return list.size();
            }
            
            public Object invoke( Object proxy, Method method, Object[] args )
               throws Throwable
            {
               if( method.getDeclaringClass() == javax.swing.ListModel.class )
               {
                  return method.invoke( this, args );
               }
               else
               {
                  Object result = method.invoke(list, args);
                  
                  if( method.getName().equals("removeAll") )
                  {
                     System.out.println( "Invoking " + method );
                  }
          
                  return result;
               }
            }
         }

         public static interface MyListModel extends ListModel, List
         {
         }


      }
      (Review ID: 125023)
      ======================================================================

            kbr Kenneth Russell (Inactive)
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: