[jboss-jira] [JBoss JIRA] Created: (JASSIST-100) Using CtBehavior.addCatch() on method that was already instrumented with ExprEditor results in unreachable code.

Martin Burger (JIRA) jira-events at lists.jboss.org
Thu Dec 3 07:32:29 EST 2009


Using CtBehavior.addCatch() on method that was already instrumented with ExprEditor results in unreachable code.
----------------------------------------------------------------------------------------------------------------

                 Key: JASSIST-100
                 URL: https://jira.jboss.org/jira/browse/JASSIST-100
             Project: Javassist
          Issue Type: Bug
    Affects Versions: 3.11.0.GA
            Reporter: Martin Burger
            Assignee: Shigeru Chiba


I want to instrument a method with CtBehavior.addCatch() after it was already modified by an ExprEditor. Unfortunately, this results in unreachable code.

Here is the original method:

            /**
             * Decompiled by jad - The Fast JAva Decompiler:
             * Original method.
             */
            public Object getObject() {
/*  74*/        return new Object();
            }

Using CtBehavior.addCatch() results in the expected modified code:

            /**
             * Decompiled by jad - The Fast JAva Decompiler:
             * Method instrumented via m.addCatch("{ System.out.println($e); throw $e; }", etype).
             */
            public Object getObject() {
/*  74*/        try {
/*  74*/            return new Object();
                }
/*  74*/        catch(Throwable throwable) {
/*  74*/            System.out.println(throwable);
/*  74*/            throw throwable;
                }
            }

If I only apply an ExprEditor alone, the modified code will look as expected as well:

            /**
             * Decompiled by jad - The Fast JAva Decompiler:
             * Method instrumented via ExprEditor.edit(NewExpr ne):
             * ne.replace("{ System.out.println(\"Constructor call.\"); $_ = $proceed($$); }");
             */
            public Object getObject() {
/*  74*/        Object obj = null;
/*  74*/        Object obj1 = null;
/*  74*/        System.out.println("Constructor call.");
/*  74*/        obj1 = new Object();
/*  74*/        return obj1;
            }

However, if I use both, the instrumented code contains an unreachable part:

            /**
             * Decompiled by jad - The Fast JAva Decompiler:
             * Method first instrumented via ExprEditors, afterwards via addCatch(...) as shown above.
             */
            public Object getObject() {
/*  74*/        Object obj = null;
/*  74*/        Object obj1 = null;
/*  74*/        System.out.println("Constructor call.");
/*  74*/        obj1 = new Object();
/*  74*/        return obj1;
                Throwable throwable;
/*  74*/        throwable;
/*  74*/        System.out.println(throwable);
/*  74*/        throw throwable;
            }

I would expect something like that:

            /**
             * Expected result.
             */
            public Object getObject() {
/*  74*/        try {
/*  74*/            System.out.println("Constructor call.");
/*  74*/            return new Object();
                }
/*  74*/        catch(Throwable throwable) {
/*  74*/            System.out.println(throwable);
/*  74*/            throw throwable;
                }
            }

Currently, method CtBehavior.addCatch() seems to not work on code that was modified before.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list