-
1. Re: when the class's access modifier is not public, byteman will failed
jaikiran Nov 1, 2011 1:18 AM (in response to swimablefish)Not that my answer is going to help you in any way, but it's always better to post the relevant part of the error logs instead of attaching a screenshot. Posting the text part helps other users when they run into the same error, since unlike the screenshots, the text is indexed and available in search results.
-
2. Re: when the class's access modifier is not public, byteman will failed
swimablefish Nov 1, 2011 2:44 AM (in response to jaikiran)ok, the exception message:
trace read local : org.jboss.byteman.rule.exception.ExecuteException: MethodExpression.interpret : exception invoking method method2 file rules.btm line 6
Exception in thread "main" org.jboss.byteman.rule.exception.ExecuteException: MethodExpression.interpret : exception invoking method method2 file rules.btm line 6
at org.jboss.byteman.rule.expression.MethodExpression.interpret(MethodExpression.java:326)
at org.jboss.byteman.rule.binding.Binding.interpret(Binding.java:133)
at org.jboss.byteman.rule.Event.interpret(Event.java:292)
at org.jboss.byteman.rule.helper.InterpretedHelper.bind(InterpretedHelper.java:155)
at org.jboss.byteman.rule.helper.InterpretedHelper.execute0(InterpretedHelper.java:135)
at org.jboss.byteman.rule.helper.InterpretedHelper.execute(InterpretedHelper.java:100)
at org.jboss.byteman.rule.Rule.execute(Rule.java:682)
at org.jboss.byteman.rule.Rule.execute(Rule.java:651)
at testApp.method1(testApp.java)
at testApp.main(testApp.java:21)
Caused by: java.lang.IllegalAccessException: Class org.jboss.byteman.rule.expression.MethodExpression can not access a member of class testApp with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.reflect.Method.invoke(Method.java:588)
at org.jboss.byteman.rule.expression.MethodExpression.interpret(MethodExpression.java:315)
... 9 more
-
3. Re: when the class's access modifier is not public, byteman will failed
adinn Nov 1, 2011 5:54 AM (in response to swimablefish)Hmm, interesting.
Firstly, here is what happens when I run this example on Linux. I chanegd the classname to upper case and completed themissing elements of the rule and methods as follows:
TestApp.java:
class TestApp {
public void method1() {
System.out.println("In method1()");
}
private int method2() {
System.out.println("In method2()"); return 0;
}
public static void main(String[] args) {
TestApp a = new TestApp();
a.method1();
}
}
rule.btm
RULE test a
CLASS TestApp
METHOD method1
AT ENTRY
BIND app1 = $0;
m2 = app1.method2()
IF true
DO traceln("in rule m2 = " + m2);
ENDRULE
Now here is the result of executing it
[adinn@localhost access]$ java -javaagent:$BYTEMAN_HOME/lib/byteman.jar=script:rule.btm TestApp
In method2()
in rule m2 = 0
In method1()
[adinn@localhost access]$
Ok, so now I tried rerunning this on my Windows (XP) box
C:\tmp\byteman\access>java -javaagent:C:\tmp\byteman\byteman-download-1.6.0\lib\byteman.jar=script:rule.btm TestApp
In method2()
in rule m2 = 0
In method1()
C:\tmp\byteman\access>
So, it also allows me to access private methods.
What I suspect is happening is that you are using a Java installation which is imposing a restrictive security policy. On my Windows installation I am using the Sun JDK version 1.6.0_27 downloaded from Oracle's web site. I execute it from a DOS shell after explicitly adding the bin subdirectory of the unzipped download directory to my Windows PATH. If I don'tuse this explicit PATH setting and instead rely on the java program obtained from 1.6.0_29 JRE which is installed for my webbrowser to use then the programdoesnot run properly I don't see your error but I get a FiileNotFound exception during JVM startup when the agent tries to open the script file rule.btm. This is because trhe default JRE is configuredto disallow access to most of the file system.
I suggest you tinker with the configuration of your installed JDK/JRE runtime to see whether you can loosen the security policy enough to allow the method access to proceed. Of course you had better be careful if you are doing this with the Java runtime used by your web browser or other applications which execute code downloaded from the internet. That is why I only ever run progreams with Byteman using an independent JDK installation.
-
4. Re: when the class's access modifier is not public, byteman will failed
rachmato Aug 7, 2015 10:22 AM (in response to adinn)I'm seeing the same problem:
Exception in thread "main" org.jboss.byteman.rule.exception.ExecuteException: MethodExpression.interpret : exception invoking method getModule file /home/nrla/java/byteman/jboss-ejb-client.btm line 69
at org.jboss.byteman.rule.expression.MethodExpression.interpret(MethodExpression.java:379)
at org.jboss.byteman.rule.binding.Binding.interpret(Binding.java:154)
at org.jboss.byteman.rule.Event.interpret(Event.java:292)
[snip]
Caused by: java.lang.IllegalAccessException: Class org.jboss.byteman.rule.expression.MethodExpression can not access a member of class org.jboss.ejb.client.naming.ejb.EjbJndiIdentifier with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:109)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:261)
at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:253)
at java.lang.reflect.Method.invoke(Method.java:599)
at org.jboss.byteman.rule.expression.MethodExpression.interpret(MethodExpression.java:368)
with the following rule:
RULE EjbNamingContext.createEjbProxy() tracing
CLASS org.jboss.ejb.client.naming.ejb.EjbNamingContext
METHOD createEjbProxy
AT ENTRY
BIND
moduleName:String = $identifier.getModule();
selector = org.jboss.ejb.client.EJBClientContext.SELECTOR;
context:EJBClientContext = selector.getCurrent();
IF
true
DO
traceln("*** ejb: namespace createEjbProxy() called ***");
traceln("*** module = " + moduleName + " ***");
traceln("*** context instance = " + context + " ***")
ENDRULE
where identifier is an instance of the class EjbJndiIdentifier which is a private class with public method getModule().
This exception occurs using a separately downloaded jdk-1.7.0_45.
If I change the class modifier from no modifier to public, the rule executes successfully.
If I run the example TestApp (see previous post) using the same JDK installation, the rule in the example executes successfully.
Can you offer any guidance on how to check the security configuration for elements that would cause these errors?
-
5. Re: when the class's access modifier is not public, byteman will failed
adinn Aug 7, 2015 11:54 AM (in response to rachmato)Hi Richard,
Can you please provide more details of your execution environment and how you are running your app.I'm not really sure what might be causing this problem but it might help if I know what is actually being run andin what configuration.
-
6. Re: when the class's access modifier is not public, byteman will failed
adinn Aug 11, 2015 4:55 AM (in response to rachmato)Hi Richard,
This may possibly relate to use of the policy:true optopn on the -javaagent comman line argument (as explained in this related thread). Could you report back on whether or not that works?
-
7. Re: when the class's access modifier is not public, byteman will failed
gaol Apr 29, 2016 5:06 AM (in response to swimablefish)Another possible reason is that your defined class: testApp is not public, the same for EjbJndiIdentifier