apache / apache/grails-core

Service Integration Spec yielding nullpointer exception on de-referencing service autowired field from within where: block

Open
#11,420 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Task List

- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)

### Steps to Reproduce

1. git clone https://github.com/vineeln/gthree
2. grails test-app gthree ExampleSpec
3. Exception thrown with following stacktrace
```
gthree.ExampleSpec > test something FAILED
java.lang.NullPointerException at ExampleSpec.groovy:47

1 test completed, 1 failed
:integrationTest FAILED
:mergeTestReports

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':integrationTest'.
> There were failing tests. See the results at: file:///Users/shiraz/Project/gthree/build/test-results/integrationTest/

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED
```

### Expected Behaviour

Service Integration Spec should have a valid auto-wired reference and derefrencing should invoke service method from within where: block

### Actual Behaviour

Service Integration Spec yielding null-pointer exception on de-referencing service auto-wired field from within where: block.

From the sample app
[obj] << _staticBookService.getAuthors();
staticBookService.getAuthors() should not throw nullpointer exception on de-referencing _staticBookService

### Environment Information

- **Operating System**: Linux
- **Grails Version:** grails 3.3.7
- **JDK Version:** java 1.8
- **Container Version (If Applicable):** grails 3.3.4

### Example Application

- https://github.com/vineeln/gthree

It seems to me a SPOCK issue but curious why this works in grails 2.2.4 and throws nullpointer in 3.3.7

Will appreciate your response on this.

Best Regards,
Shiraz Zaidi

Contributor guide

Open the contributing guide

Research direction

Clone the linked gthree example and run `grails test-app gthree ExampleSpec`. Start at `ExampleSpec.groovy:47` and inspect the service autowiring used inside the `where:` block, then trace the integration-test setup in Grails 3.3.7. Done means the service reference is valid and `staticBookService.getAuthors()` no longer raises a null-pointer exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.