Uploaded image for project: 'Byteman'
  1. Byteman
  2. BYTEMAN-155

VerifyError when accessing variable in static method

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 1.5.2
    • 1.5.1
    • Trigger Injection
    • None

    Description

      The following class and byteman rule work correctly (printing 1):

      public class BmTest {
      public static void main(String[] args)

      { new BmTest().run(); }

      public void run() { int i = 1; i = 2; // line 8 }
      }

      RULE example
      CLASS BmTest
      METHOD run()
      AT LINE 8
      IF TRUE
      DO System.out.println($i)
      ENDRULE


      If the run method is made static, then it results in "Exception in thread "main" java.lang.VerifyError: (class: BmTest, method: run signature: ()V) Register 0 contains wrong type". I'm using java version "1.6.0_20", OpenJDK Runtime Environment (IcedTea6 1.9.7) (fedora-52.1.9.7.fc14-x86_64)

      public class BmTest {
      public static void main(String[] args) { new BmTest().run(); }

      public static void run()

      { int i = 1; i = 2; // line 8 }
      }


      The slightly more convoluted version which calls the static method from an instance method does work however:

      public class BmTest {
      public static void main(String[] args) { new BmTest().foo(); }

      public static void run() { int i = 1; i = 2; // line 8 }

      public void foo()

      { run(); }

      }

      Calling the static method after an instance method doesn't though:

      public class BmTest {
      public static void main(String[] args)

      { new BmTest().foo().run(); }

      public static void run()

      { int i = 1; i = 2; // line 8 }

      public BmTest foo()

      { return this; }

      }

      I haven't done further testing, but it looks like it fails when the current call stack only contains static methods.

      Attachments

        Activity

          People

            rhn-engineering-adinn Andrew Dinn
            rhn-support-jlivings James Livingston (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: