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

InvocationHandler.invoke gets null argument list if 0 parameters in call

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.3.0
    • core-libs
    • generic
    • generic



      Name: tb29552 Date: 01/27/2000


      /*
      java version "1.3beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
      Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)

      If InvocationHandler is invoked by a proxy-call to a method with 0 arguments,
      then the argument list of the invoke call is null, instead of an object array of
      0(zero) length.
      */
      import java.lang.reflect.InvocationHandler;
      import java.lang.reflect.Proxy;
      import java.lang.reflect.Method;

      public class Main
      {
         public static void main(String[] args)
            throws Exception
         {
            // Invocationhandler
            InvocationHandler handler = new InvocationHandler()
            {
               public Object invoke(Object proxy,
                                    Method method,
                                    Object[] args)
                             throws Throwable
              {
                 System.out.println("This, "+args+", should be a zero length array instead");
                 return null;
              }
            };
            
            // Create proxy
            Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(),
                                                 new Class[] { Foo.class },
                                                 handler);
                                                 
            // Call Foo
            f.doSomething();
         }
         
         interface Foo
         {
            public void doSomething();
         }
      }

      (Review ID: 100408)
      ======================================================================

            peterjones Peter Jones (Inactive)
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: