3 Replies Latest reply: Mar 1, 2012 10:33 AM by Andrew Dinn RSS

    NPE in the RuleGeneratorAdapter

    Anton Ryabtsev Newbie

      Hi,

       

      I got  an exception in the next scenario:

       

       

      public class Foo {
      
          public void bar(Map input) {
              final long start = System.currentTimeMillis();
              String s;
              try {
                  s =  new String("test");
              } catch(Exception exc) {
                  s = new String("fail");
              }
              System.out.println(s);
          }
      
      }
      

       

       

       

      RULE rule

      CLASS Foo

      METHOD bar

      AT EXIT

      IF true

      DO traceln("yes, it works!" + $s)

      ENDRULE

       

      Exception:

      java.lang.NullPointerException

          at org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.loadLocal(RuleGeneratorAdapter.java:1483)

          at org.jboss.byteman.agent.adapter.RuleTriggerMethodAdapter.doArgLoad(RuleTriggerMethodAdapter.java:477)

          at org.jboss.byteman.agent.adapter.RuleTriggerMethodAdapter.injectTriggerPoint(RuleTriggerMethodAdapter.java:1115)

          at org.jboss.byteman.agent.adapter.ExitTriggerAdapter$ExitTriggerMethodAdapter.visitInsn(ExitTriggerAdapter.java:79)

          at org.jboss.byteman.objectweb.asm.tree.InsnNode.accept(Unknown Source)

          at org.jboss.byteman.objectweb.asm.tree.InsnList.accept(Unknown Source)

          at org.jboss.byteman.objectweb.asm.tree.MethodNode.accept(Unknown Source)

          at org.jboss.byteman.objectweb.asm.commons.JSRInlinerAdapter.visitEnd(Unknown Source)

          at org.jboss.byteman.objectweb.asm.ClassReader.accept(Unknown Source)

          at org.jboss.byteman.objectweb.asm.ClassReader.accept(Unknown Source)

          at org.jboss.byteman.agent.Transformer.transform(Transformer.java:746)

       

      Can someone suggest a workaround to run the rule successfully?

        • 1. Re: NPE in the RuleGeneratorAdapter
          Andrew Dinn Master

          Hi Anton,

           

          Anton Ryabtsev wrote:

           

          Hi,

           

          I got  an exception in the next scenario:

           

          
          public class Foo {
          
              public void bar(Map input) {
                  final long start = System.currentTimeMillis();
                  String s;
                  try {
                      s =  new String("test");
                  } catch(Exception exc) {
                      s = new String("fail");
                  }
                  System.out.println(s);
              }
          
          }
          

           

           

           

          RULE rule

          CLASS Foo

          METHOD bar

          AT EXIT

          IF true

          DO traceln("yes, it works!" + $s)

          ENDRULE

           

          I think this is a bug in the injection code to do with counting local variable slots. If you change the program to this

           

               . . .
               public void bar(Map input) {
                  final int start = (int)System.currentTimeMillis();
                  String s;
                  . . .

           

          then it works ok.

           

          I will raise a JIRA for this and try to patch it for the next (2.0.1) release.

          • 3. Re: NPE in the RuleGeneratorAdapter
            Andrew Dinn Master

            This is now fixed in trunk