Discussion:
[jboss-user] [Javassist] - $proceed($$) for private methods
Aaron Dixon
2012-06-09 23:44:34 UTC
Permalink
Aaron Dixon [https://community.jboss.org/people/aarontdixon] created the discussion

"$proceed($$) for private methods"

To view the discussion, visit: https://community.jboss.org/message/740844#740844

--------------------------------------------------------------
I get a compile error when Javassist is trying to compile a method replacement when the method is private.

method.instrument(new ExprEditor() {
     public void edit(MethodCall m) throws CannotCompileException {
          m.replace("$_ = $proceed($$);");
     }
}

Is there a way I can get Javassist to compile invocations of private methods?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/740844#740844]

Start a new discussion in Javassist at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2062]
Aaron Dixon
2012-06-09 23:59:53 UTC
Permalink
Aaron Dixon [https://community.jboss.org/people/aarontdixon] created the discussion

"Re: $proceed($$) for private methods"

To view the discussion, visit: https://community.jboss.org/message/740845#740845

--------------------------------------------------------------
Clarification:

Javassist fails when the private method that is invoked is *static private*.

Is this a defect?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/740845#740845]

Start a new discussion in Javassist at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2062]
settimer
2013-01-31 23:44:21 UTC
Permalink
settimer [https://community.jboss.org/people/settimer] created the discussion

"Re: $proceed($$) for private methods"

To view the discussion, visit: https://community.jboss.org/message/795524#795524

--------------------------------------------------------------
I encoutered the same issue. Have you figured it out?

Below is a mored detailed description:

I try to instrument the call in the method:

    public static Currency getInstance(String currencyCode) {
        return getInstance(currencyCode, Integer.MIN_VALUE);
    }

, which is inside java/util/Currency.class. The call invokes "*private static* Currency getInstance(String, int)", which is enclosed in the same class as the caller.

I need to add some statements around the call "getInstance(currencyCode, Integer.MIN_VALUE);". So I used MethodCall.replace("{some statements; $_ = $proceed($$); other statements;}"), then I got the exception like below:

Caused by: compile error: Method getInstance is private
    at javassist.compiler.
MemberCodeGen.getAccessiblePrivate(MemberCodeGen.java:671)
    at javassist.compiler.MemberCodeGen.atMethodCallCore2(MemberCodeGen.java:612)
     at javassist.compiler.MemberCodeGen.atMethodCallCore(MemberCodeGen.java:575)
    at javassist.compiler.MemberCodeGen.atCallExpr(MemberCodeGen.java:523)
    at javassist.compiler.JvstCodeGen.atCallExpr(JvstCodeGen.java:244)
     at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
    at javassist.compiler.CodeGen.compileExpr(CodeGen.java:230)
    at javassist.compiler.Javac$2.doit(Javac.java:490)
    at javassist.compiler.JvstCodeGen.atCallExpr(JvstCodeGen.java:235)
     at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
    at javassist.compiler.CodeGen.atAssignCore(CodeGen.java:860)
    at javassist.compiler.CodeGen.atVariableAssign(CodeGen.java:793)
    at javassist.compiler.CodeGen.atAssignExpr(CodeGen.java:747)
     at javassist.compiler.CodeGen.atStmnt(CodeGen.java:332)
    at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
    at javassist.compiler.CodeGen.atStmnt(CodeGen.java:351)
    at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
     at javassist.compiler.Javac.compileStmnt(Javac.java:569)
    at javassist.expr.MethodCall.replace(MethodCall.java:235)
    ... 18 more

The bug can be reproduced. For example, in java.lang.securityManager, the method checkPackageAccess contains a call
"packageAccess = getPackages(tmpPropertyStr);", The call invokes "*private static* String[] getPackages(String p)".

In both cases, it involves invocations to "private static" methods.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/795524#795524]

Start a new discussion in Javassist at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2062]
Yanic Inghelbrecht
2013-02-28 16:01:03 UTC
Permalink
Yanic Inghelbrecht [https://community.jboss.org/people/yanic] created the discussion

"Re: $proceed($$) for private methods"

To view the discussion, visit: https://community.jboss.org/message/800108#800108

--------------------------------------------------------------
I had the same issue, please post the code fragment where you call makeClass on the ClassPool so I can check if it's the same case.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800108#800108]

Start a new discussion in Javassist at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2062]
Loading...