PicoContainer
  1. PicoContainer
  2. PICO-387

JavaEE5LifecycleStrategy works only on accessible methods, that are annotated with @PostConstruct and @PreDestroy

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.14.1
    • Fix Version/s: 3.0
    • Component/s: PicoContainer (Java)
    • Labels:
      None
    • Number of attachments :
      0

      Description

      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

        People

        • Assignee:
          Michael Rimov
          Reporter:
          Olaf Krische
        • Votes:
          0 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved:

            Time Tracking

            Estimated:
            Original Estimate - 5 minutes
            5m
            Remaining:
            Remaining Estimate - 5 minutes
            5m
            Logged:
            Time Spent - Not Specified
            Not Specified