-
1. Re: $proceed($$) for private methods
aarontdixon Jun 9, 2012 7:59 PM (in response to aarontdixon)Clarification:
Javassist fails when the private method that is invoked is *static private*.
Is this a defect?
-
2. Re: $proceed($$) for private methods
settimer Jan 31, 2013 6:44 PM (in response to aarontdixon)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 moreThe 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.
-
3. Re: $proceed($$) for private methods
yanic Feb 28, 2013 11:00 AM (in response to settimer)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.
-
4. Re: $proceed($$) for private methods
enielsen Dec 15, 2014 7:28 PM (in response to aarontdixon)I was having the same problem. In my case I was trying to call a private method in a superclass, which is of couse impossible to do!