3 Replies Latest reply: Nov 1, 2011 5:54 AM by Andrew Dinn RSS

when the class's access modifier is not public, byteman will failed

swimablefish Newbie

here is the class

 

   class testApp {

          public void method1() {

                ....

         }

 

         private int method2() {

               ....

         }

 

         public static void main(String[] args) {

                testApp a = new testApp();

                 a.method1();

         }

   }

 

  and here is the rule

 

      RULE test a

      CLASS testApp

      METHOD method1

      AT ENTRY

      BIND app1 = $0;

               m2 = app1.method2()

      IF true

      DO   .....

      ENDRULE

 

    then, the byteman will print as follow:

      

 

C1ECE4BCD16096F8C6324F38D09561F9.JPG

but when i add "public" before class, it will run successfully. So how do i solve this kind of problem if the class isn't decoreated with public

  • 1. Re: when the class's access modifier is not public, byteman will failed
    jaikiran pai Master

    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 Newbie

    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
    Andrew Dinn Master

    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.