[picocontainer-scm] [jira] (PICO-387) JavaEE5LifecycleStrategy works only on accessible methods, that are annotated with @PostConstruct and @PreDestroy

"Olaf Krische (JIRA)" <jira-yCVjj/[email protected]> Thu, 12 Apr 2012 11:56:02 -0500 (CDT)
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <1965647259.65113.1334249762832.JavaMail.j2ee-jira@codehaus01.managed.contegix.com>
Olaf Krische created PICO-387:
---------------------------------

             Summary: JavaEE5LifecycleStrategy works only on accessible methods, that are annotated with @PostConstruct and @PreDestroy
                 Key: PICO-387
                 URL: https://jira.codehaus.org/browse/PICO-387
             Project: PicoContainer
          Issue Type: Bug
          Components: PicoContainer (Java)
    Affects Versions: 2.14.1
            Reporter: Olaf Krische
            Assignee: Paul Hammant


Hello,

the javadoc of PostConstruct/PreConstruct says:

- The method on which PostConstruct/PreDestroy is applied MAY be public, protected, package private or private.

The JavaEE5LifecycleStrategy works only with accessible methods.

A fixed strategy would probably call: method.setAccessible(true), before invoking it.

I ran into this exception, when someone changed a method from public to package private, which is  annotated with @PreDestroy

I consider this as a bug. 

If not already accessible, it should be made accessible at least for this single invoke. To comply with the expected behaviour from the javadoc.

What do you think? Offering a second strategy or patching it?

(Same anyhow with a default constructor injector, where implementations can not have private constructors. But this is another topic)

org.picocontainer.PicoLifecycleException: PicoLifecycleException: method 'void de.ecopatz.main.Clusters.destroy()', instance 'de.ecopatz.main.Clusters@29c73472, java.lang.IllegalAccessException: Class org.picocontainer.lifecycle.JavaEE5LifecycleStrategy can not access a member of class de.ecopatz.main.Clusters with modifiers ""
	at org.picocontainer.lifecycle.JavaEE5LifecycleStrategy.doLifecycleMethod(JavaEE5LifecycleStrategy.java:73)
	at org.picocontainer.lifecycle.JavaEE5LifecycleStrategy.doLifecycleMethod(JavaEE5LifecycleStrategy.java:54)
	at org.picocontainer.lifecycle.JavaEE5LifecycleStrategy.dispose(JavaEE5LifecycleStrategy.java:50)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.dispose(AbstractInjectionFactory.java:92)
	at org.picocontainer.behaviors.AbstractBehavior.dispose(AbstractBehavior.java:189)
	at org.picocontainer.behaviors.Stored$RealComponentLifecycle.dispose(Stored.java:151)
	at org.picocontainer.behaviors.Stored.dispose(Stored.java:55)
	at org.picocontainer.DefaultPicoContainer.disposeAdapters(DefaultPicoContainer.java:1056)
	at org.picocontainer.DefaultPicoContainer.dispose(DefaultPicoContainer.java:847)
	at de.ecopatz.main.AppContextImpl._shutdown(AppContextImpl.java:378)
	at de.ecopatz.main.AppContextImpl.shutdown(AppContextImpl.java:283)
	at de.ecopatz.main.App.shutdown(App.java:789)
	at de.ecopatz.main.AppTest.testApp(AppTest.java:30)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalAccessException: Class org.picocontainer.lifecycle.JavaEE5LifecycleStrategy can not access a member of class de.ecopatz.main.Clusters with modifiers ""
	at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:95)
	at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:261)
	at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:253)
	at java.lang.reflect.Method.invoke(Method.java:594)
	at org.picocontainer.lifecycle.JavaEE5LifecycleStrategy.doLifecycleMethod(JavaEE5LifecycleStrategy.java:69)
	... 35 more
@PreDestroy 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

<hr/>
<p>
To unsubscribe from this list please visit:
</p>
<p>
    <a href="http://xircles.codehaus.org/manage_email">http://xircles.codehaus.org/manage_email</a>
</p>