[jboss-jira] [JBoss JIRA] Created: (JASSIST-41) javassist.expr.NewExpr.replace(...) fails if created object is not assigned to variable

Martin Burger (JIRA) jira-events at lists.jboss.org
Wed Jan 16 08:30:57 EST 2008


javassist.expr.NewExpr.replace(...) fails if created object is not assigned to variable
---------------------------------------------------------------------------------------

                 Key: JASSIST-41
                 URL: http://jira.jboss.com/jira/browse/JASSIST-41
             Project: Javassist
          Issue Type: Bug
         Environment: Eclipse
            Reporter: Martin Burger
         Assigned To: Shigeru Chiba


I implemented a ExprEditor that replaces new expressions. However, if the editor should replace a constructor call whose return value (the newly created object) is not assigned to a local variable, the method javassist.expr.NewExpr.canReplace(...) throws a CannotCompileException "sorry, cannot edit NEW followed by no DUP".

The constructor has one parameter of type String, the method looks like that one:

public void trigger() {
    new C("some string");
}

In the byte code (Eclipse compiler) of the method that contains that constructor call is a LDC before the expected INVOKESPECIAL, so the method canReplace(...) fails:

NEW C
LDC "some string"
INVOKESPECIAL C.<init>(Ljava/lang/String;)V

If I add an assignment, there will be a DUP before the LDC:

public void trigger() {
    C c = new C("some string");
}

NEW C
DUP
LDC "some string"
INVOKESPECIAL C.<init>(Ljava/lang/String;)V


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

        



More information about the jboss-jira mailing list