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

Rule compilation fails with NPE when injecting rule code into bootstrap loaded classes

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 1.1.0
    • 1.0.3
    • None
    • None

    Description

      If compilation of bytecode is switched on by passing -Dorg.jboss.byteman.compileToBytecode to the JVM then this leads to a Null Pointer Exception when executing a rule injected into a method of a class loaded by the bootstrap class loader.

      The problem is that the Byteman Main and Transformer/Retransformer classes are loaded by the System class loader before the Main class has a chance to add the byteman jar to the bootstrap class path. Thsi is because Main uses static linkage to acces these clases (i.e. in mentions them explicitly by name). When an attempt is made to compile a transformed bootstrap class references to Transformer, Rule, ReturnException are resolved against the bootstrap loader (the System class loader's parent) causing these classes to be reloaded. This means that the Transformer static field theTransformer is null and this cause the compiler to fail with an NPE.

      This can be resolved by having Main explicitly load the Transformer class via Classloader.loadClass after updating the boot classpath. It then needs to invoke the constructor for ht etransformer instance via reflection. This ensures that its reference to any Byteman classes along wiht any subsequent references (other than Main, perhaps) resolve to a single version of the relevant class loaded via the boot classpath loader.

      Attachments

        Activity

          People

            rhn-engineering-adinn Andrew Dinn
            rhn-engineering-adinn Andrew Dinn
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: