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

Type resolution fails for static member class causing NPE under Rule.requiresAccess

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.0.15, 4.0.7
    • 3.0.14, 4.0.6
    • Parser/Type Checker
    • None
    • Hide

      Define a BMUnit test class with a static inner class that extends Helper and add a simple public method as a builtin..
      Use the inner class as a rule helper for a rule injected into a test method.
      Invoke the builtin method belonging to the helper in the rule's DO clause.

      The type check of the builtin call should blow up under the call to Rule.requiresAccess(Type). The Type instance passes to requiresAccess is non-null. However, its targetClass field ( a Class<?>) will be null.

      Show
      Define a BMUnit test class with a static inner class that extends Helper and add a simple public method as a builtin.. Use the inner class as a rule helper for a rule injected into a test method. Invoke the builtin method belonging to the helper in the rule's DO clause. The type check of the builtin call should blow up under the call to Rule.requiresAccess(Type). The Type instance passes to requiresAccess is non-null. However, its targetClass field ( a Class<?>) will be null.

      When the type checker encounters a type name during type checking of some given rule it creates an internal Type object which holds a name String and Class<?> instance as fields. The name may already be associated with a Class<?> or it may need to be resolved by a class loader lookup. Types are stored in a TypeGroup which allows previous lookups to be reused. In some cases the name may not resolve and the type checker normally detects this and throws a type error.

      Type instances are, on occasions, created using a name obtained from a Class<?> accessed through reflection. In such cases a loader lookup may still be performed even though the originating class was known. The type checker does notexpect these lookups to fail.

      Inner classes modelled via this latter route are being modelled up using their canonical name, e.g. in the format org.my.Foo.Bar, instead of the format required for a successful lookup, which e.g. would be org.my.Foo$Bar. As a result the classloader lookup silently fails and the resulting Type instance has a null reference its class. The subsequent check to see if the class for that Type is publicly accessible blows up with NPE.

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

                Created:
                Updated:
                Resolved: