JDK-4086065 : rfe: Method.invoke() is difficult to debug
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.1.3
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-10-14
  • Updated: 1998-02-06
  • Resolved: 1998-02-06
Related Reports
Duplicate :  
Description

Name: joT67522			Date: 10/14/97


import java.lang.reflect.Method;

/**
 * Test ease of debugging exceptions in deep invocations.
 * Invocation is useful in loosely coupled systems where
 * method calls are parameter driven services.
 *
 * Note that in the exception stack trace there is no
 * mention of where the initial exception occured. This
 * makes it very hard to debug deep invocations, as one
 * must resort to embedding print() to isolate the bug.
 *
 *      SUGGESTION:
 * Since the Method must be created before invoke(), the
 * greatest exception risk is already past when invoke()
 * is called. One solution would be to add:
 *      Method.invokeNoCatch(Object obj, Object args[])
 * which throws no exceptions but does throw errors.
 *
 * @author Jack Harich - 8/30/97 - ###@###.###
 */
public class TestInvoke {

//---------- Private Fields ------------------------------
// (none)

//---------- Initialization ------------------------------
public static void main(String args[]) {
    new TestInvoke();
}
public TestInvoke() {
    try {
        // Create method
        Class[] classes = { }; // No arg
        Method method = this.getClass().getMethod("logonRequested", classes);

        // Call method
        Object[] args = { }; // No arg
        method.invoke(this, args);

    } catch(Exception ex) {
        print("TestInvoke exception");
        ex.printStackTrace();
    }
}
//---------- Public Methods ------------------------------
public void logonRequested() {
    print("TestInvoke.logonRequested() - entered");
    // Create test exception
    int divisor = 0;
    int test = 5 / divisor; // <-----<<< EXCEPTION
}
//---------- Private Methods -----------------------------
//--- Std
private static void print(String text) {
    System.out.println(text);
}

} // End class
company - Consultant , email - ###@###.###
======================================================================

Comments
WORK AROUND Name: joT67522 Date: 10/14/97 ======================================================================
11-06-2004