oghenez / mycila

Automatically exported from code.google.com/p/mycila
0 stars 0 forks source link

JSR250 @PreDestroy should invoke methods in sub class before those in super class #30

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The invocation order for @PostConstruct should be from top to bottom, super 
class before sub class. For @PreDestroy it should be the other way around.

Consider this example:

public class SuperClass {
    @PostConstruct
    private void init() {
        // Establish a database connection
    }
    @PreDestroy
    private void destroy() {
        // Release the database connection
    }
}

public class InheritingClass extends SuperClass {
    @PostConstruct
    private void init() {
        // Read something from database using the connection
    }
    @PreDestroy
    private void destroy() {
        // Write possible changed something to database using the connection
    }
}

I have written a failing test case, source for it is here: 
http://pastie.org/2172732

// Tobias

Original issue reported on code.google.com by totobobi...@gmail.com on 6 Jul 2011 at 3:14

GoogleCodeExporter commented 8 years ago
Hi,

Thank you I'll fix it before the end of the week !

Mathieu.

Original comment by mathieu....@gmail.com on 6 Jul 2011 at 3:22

GoogleCodeExporter commented 8 years ago
Hi,

I've fixed the order for the @PostConstruct also: according to your test. 
@PostConstruct should invoke methods of super classes first and then subclasses.

@PreDestroy should thus do the inverse job.

But i have an issue with private methods: in your test you have

assertLifeCycleSequence(LifecycleSameNamePrivateMethods.class, "ED", "DE");

E is the subclass and D the superclass. With @PosConstruct, i am more expecting 
DE as the start sequence and ED as the stop sequence. Is is right ? Can you 
confirm that both sequences can be inverted ?

Thank you !

Original comment by mathieu....@gmail.com on 7 Aug 2011 at 5:12

GoogleCodeExporter commented 8 years ago

Original comment by mathieu....@gmail.com on 7 Aug 2011 at 7:23

GoogleCodeExporter commented 8 years ago

Original comment by mathieu....@gmail.com on 7 Aug 2011 at 7:45

GoogleCodeExporter commented 8 years ago
Yes, that's correct, it should be DE ED.

Original comment by totobobi...@gmail.com on 9 Aug 2011 at 8:13