tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Quintin Beukes (JIRA)" <j...@apache.org>
Subject [jira] Updated: (OPENEJB-1070) LocalInitialContextFactory can't be extended
Date Thu, 10 Sep 2009 13:24:57 GMT

     [ https://issues.apache.org/jira/browse/OPENEJB-1070?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Quintin Beukes updated OPENEJB-1070:
------------------------------------

    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.

  was:
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);

I attached a patch for this.



> LocalInitialContextFactory can't be extended
> --------------------------------------------
>
>                 Key: OPENEJB-1070
>                 URL: https://issues.apache.org/jira/browse/OPENEJB-1070
>             Project: OpenEJB
>          Issue Type: Bug
>    Affects Versions: 3.1.2
>            Reporter: Quintin Beukes
>            Priority: Trivial
>             Fix For: 3.1.2
>
>
> 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message