6 Replies Latest reply on Nov 12, 2010 11:54 AM by jaikiran

    Private field access in rule action

    jaikiran

      I have this rule:

       

      RULE EjbContainer_popEnc
      CLASS ^org.jboss.ejb3.EJBContainer
      METHOD popEnc
      AT ENTRY
      IF TRUE
      DO System.out.println("EncFactory is " + $0.encFactory)
      ENDRULE

       

       

      The EJBContainer has a private encFactory field, which I am printing in the rule action. However, when I run this through byteman, I see this exception:

       

      19:45:02,496 INFO  [STDOUT] org.jboss.byteman.rule.exception.TypeException: FieldExpresssion.typeCheck : invalid field reference encFactory file /home/jpai/bytemanrule.txt line 6
      19:45:02,496 INFO  [STDOUT]     at org.jboss.byteman.rule.expression.FieldExpression.typeCheck(FieldExpression.java:160)
      19:45:02,496 INFO  [STDOUT]     at org.jboss.byteman.rule.expression.StringPlusExpression.typeCheck(StringPlusExpression.java:52)
      19:45:02,497 INFO  [STDOUT]     at org.jboss.byteman.rule.expression.MethodExpression.typeCheck(MethodExpression.java:211)
      19:45:02,497 INFO  [STDOUT]     at org.jboss.byteman.rule.Action.typeCheck(Action.java:106)
      19:45:02,497 INFO  [STDOUT]     at org.jboss.byteman.rule.Rule.typeCheck(Rule.java:482)
      19:45:02,497 INFO  [STDOUT]     at org.jboss.byteman.rule.Rule.ensureTypeCheckedCompiled(Rule.java:419)
      19:45:02,497 INFO  [STDOUT]     at org.jboss.byteman.rule.Rule.execute(Rule.java:620)
      19:45:02,497 INFO  [STDOUT]     at org.jboss.byteman.rule.Rule.execute(Rule.java:601)
      19:45:02,497 INFO  [STDOUT]     at org.jboss.ejb3.EJBContainer.popEnc(EJBContainer.java:461)
      
      

       

       

      Looking at the byteman code, it appears that only public fields are allowed for access. But I don't any mention of not using private fields, in the documentation. Is it expected that only public fields are accessible?

        • 1. Re: Private field access in rule action
          adinn

          Hi Jaikiran,

          jaikiran pai wrote:

           

          Looking at the byteman code, it appears that only public fields are allowed for access. But I don't any mention of not using private fields, in the documentation. Is it expected that only public fields are accessible?

          Yes, this is what is expected. Byteman rules cannot break normal access rules. Perhaps this needs stating explicitly somewhere in the docs.

           

          It might be possible to introduce special access depending upon the security model in use but this has been avoided up to now -- mainly because it is a lot of work. Do you realy need this? If so raise a JIRA and I will look at what is needed to make it work.

           

          regards,

           

           

          Andrew Dinn

          • 2. Re: Private field access in rule action
            jaikiran

            The usecase I am trying, involves a method which accesses a (private) field and does some operations on it:

             

            public void doSomething()
            {
               this.somePrivateFieldWhoseValueIamInterestedIn = // some value;
            }
            

             

            The rule I am trying to write is one which wants to know the value of that field. That private field doesn't have any public getter method, so I can't rely on that either.

             

            I guess, this one is a pretty common usecase. So something like this would be handy:

             

            RULE some_rule
            CLASS blah.Blah
            METHOD doSomething
            AT ENTRY
            IF TRUE
            DO System.out.println("Value of field is " + $0.somePrivateFieldWhoseValueIamInterestedIn)
            ENDRULE
            

             

            If this sounds like a valid feature request, then I'll create a JIRA for this.

            • 3. Re: Private field access in rule action
              adinn

              Hi Jaikiran,

               

              Yes, please raise a JIRA. Thanks.

               

               

              Andrew Dinn

              • 4. Re: Private field access in rule action
                jaikiran
                • 5. Re: Private field access in rule action
                  adinn

                  jaikiran pai wrote:

                   

                  Created https://jira.jboss.org/jira/browse/BYTEMAN-99

                  Hi Jaikiran. Just in case you had not spotted the details in the Byteman 1.4.0 release notes this JIRA has been fixed. It is now possible to access private fields (and prvate methods) in the body of a Byteman rule.

                  • 6. Re: Private field access in rule action
                    jaikiran

                    Thanks Andrew for adding this feature! I did notice the release notes and am going to try it out the next time I use Byteman