Map constructor doesn't work on destroy()
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
If I try to use Map constructor on domain class after app destroy, the fields are not set (stay null). Happens only on domain classes, POJOs work fine.
### Steps to Reproduce
**Domain class:**
`class TestDestroy {
String x
}`
**Service:**
```
class TestDestroyService implements DisposableBean {
@Override
void destroy() throws Exception {
println("Destroying from disposable bean ....")
TestDestroy objFromMap = new TestDestroy(x: "x")
TestDestroy objSetter = new TestDestroy()
objSetter.x = "x"
TestDestroyPojo pojo = new TestDestroyPojo(x: "x")
println("DisposableBean: Domain Map constructor has correct props: ${objFromMap.x == "x"}")
println("DisposableBean: Domain setter has correct props: ${objSetter.x == "x"}")
println("DisposableBean: Pojo has correct props: ${pojo.x == "x"}")
}
}
```
When you shutdown the web application the output is:
> 2016-08-23 11:38:29.165:INFO:t.1:Destroying Spring FrameworkServlet 'grails'
> Destroying from disposable bean ....
> DisposableBean: Domain Map constructor has correct props: false
> DisposableBean: Domain setter has correct props: true
> DisposableBean: Pojo has correct props: true
> 2016-08-23 11:38:29.558:INFO:t.1:Closing Spring root WebApplicationContext
### Expected Behaviour
The output should be:
> DisposableBean: Domain Map constructor has correct props: true
Since the map constructor should set the field.
Note: when the destroy method is called from `Bootstrap.destroy{}`, it works fine. I could reproduce the problem only with Spring's DisposableBean interface.
### Environment Information
- **Grails Version:** 2.4.4
- **JDK Version:** 1.7.0_79
- **Container Version:** jetty-8.1.9
### Example Application
- link to github: https://github.com/tomasbartalos/grailsDestroyBug
- link to SO: http://stackoverflow.com/questions/39076268/map-constructor-doesnt-work-on-app-destroy
Contributor guide
Research direction
Start with the DisposableBean destroy() callback and compare its behavior with Bootstrap.destroy{}, where the map constructor works. Reproduce the Grails 2.4.4 case using the linked example application and verify that TestDestroy(x: "x") sets x during application shutdown without breaking setter or POJO construction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, spring
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100