[jboss-jira] [JBoss JIRA] Commented: (JASSIST-132) Replacing an expression with a try-catch statement

Shigeru Chiba (JIRA) jira-events at lists.jboss.org
Thu Sep 9 20:46:50 EDT 2010


    [ https://jira.jboss.org/browse/JASSIST-132?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12550010#action_12550010 ] 

Shigeru Chiba commented on JASSIST-132:
---------------------------------------

Let me explain why a try-catch statement cannot substitute an expression.

While computing an expression, intermediate results are saved on a stack.
Then, if an exception is thrown, the JVM discards all the values on the stack.
To come back from a catch clause, the broken stack must be restored but it
is really difficult since the stack height (and the values there) is different
depending on when the exception is thrown.

A possible approach is this.

If the code is:

Utils.addStringError("s1", "s2") 

it should be transformed into:

Utils.addStringErrorTrap("s1", "s2")

      :
private void addStringErrorTrap(String s1, String s2) {
printf("Arguments: %s, %s\n", "s1", "s2"); 
try { 
String s = Utils.addStringError("s1", "s2") 
printf("Result: %s\n", s); 
} 
catch (Throwable t) {
printf("Error: %s\n", t.getMessage()); 
} 
}

A tip is to make a new method addStringErrorTrap.
An exception does not discard stack values used by other methods.

> Replacing an expression with a try-catch statement
> --------------------------------------------------
>
>                 Key: JASSIST-132
>                 URL: https://jira.jboss.org/browse/JASSIST-132
>             Project: Javassist
>          Issue Type: Bug
>    Affects Versions: 3.13.0.GA
>         Environment: JDK 1.6.0_18
>            Reporter: Thomas Mauch
>            Assignee: Shigeru Chiba
>             Fix For: 3.14.0.GA
>
>         Attachments: bug.zip
>
>
> Instrumenting fails with ArrayIndexOutOfBoundsException.
> I will upload a test case showing the issue.

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

        


More information about the jboss-jira mailing list