Uploaded image for project: 'OpenEJB'
  1. OpenEJB
  2. OPENEJB-1070

LocalInitialContextFactory can't be extended

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 3.1.2
    • 3.1.2
    • None
    • None

    Description

      When extended org.apache.openejb.client.LocalInitialContextFactory you can't use it to create a new InitialContext. This is due to the way it constructs the LocalInitialContext object using reflection, ie.:
      Constructor constructor = localInitialContext.getConstructor(Hashtable.class, this.getClass());

      If you extend it this.getClass() returns the new classes identity, and there won't be such a constructor unless you override getInitialContext(Hashtable) and do it yourself. In most cases this is fine, though there might be cases where you override it for other purposes, and in these cases it becomes a problem.

      Also. Anyone who used it like this in previous versions who upgrade will receive NoSuchMethod exceptions.

      Since it's intended for this.getClass() to return a LocalInitialContextFactory always (since that's the only constructor provided by LocalInitialContext), you might as well reference the class object statically, like so:
      Constructor constructor = localInitialContext.getConstructor(Hashtable.class, LocalInitialContextFactory.class);

      This all happens in this file: container/openejb-core/src/main/java/org/apache/openejb/client/LocalInitialContextFactory.java

      Further, I assume for compatibility you still provide: ./container/openejb-core/src/main/java/org/openejb/client/LocalInitialContextFactory.java

      People who are using this file will also get an error, since it is simple an extension of the former, and thus the reflection won't work.

      I attached a patch to fix this problem as described.

      Attachments

        1. reflection.patch
          1 kB
          Quintin Beukes

        Activity

          People

            quintin@last.za.net Quintin Beukes
            quintin@last.za.net Quintin Beukes
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: