spockframework / spockframework/spock
@Shared property that is overridden in derived class causes problems
Open
Nobody has claimed this yet.
Module-Core
Type-Defect
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 483
- PR merge metrics
- No merged PRs in 30d
Description
Originally reported on Google Code with ID 81
class CleanInsertXSpec extends Specification {
@Shared
@Inject
Things thingFactory
...
void setup() {
thingFactory.xxxxxx --> NullPointerException()
}
....
}
class Y extends CleanInsertXSpec {
ThingFactory thingFactory = new ThingFactory()
}
@Shared turns field access thingFactory.xxx into property access, and getter is overridden
in
derived class. Thus we end up accessing the wrong field (and that field isn't initialized
yet). One
(brute force) way around this might be to make getter/setter of @Shared properties
private.
Reported by pniederw on 2010-03-09 19:08:46
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the CleanInsertXSpec and Y inheritance example from the issue, focusing on how @Shared field access and generated properties behave when a derived class declares the same property. Trace the @Shared property handling entry point and add a regression test for the overridden-field case. Done means accessing thingFactory in the base specification no longer reaches the derived class's uninitialized field.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100