MissingMethodException when accessing fields without explicit `@`
Describe the bug
In order write this Stack Overflow answer, I implemented a test demonstrating data pipes. It works nicely on Spock 1.3. Then I copied it into GWC, and it started failing, complaining about missing getters in lines using field access. Then same happens locally in the latest Spock version:
event.id > 0
| |
| groovy.lang.MissingMethodException: No signature of method: de.scrum_master.stackoverflow.q71631373.FirstEvent.getId() is applicable for argument types: () values: []
| Possible solutions: getAt(java.lang.String), wait(), init(), find(), grep(), wait(long)
| at de.scrum_master.stackoverflow.q71631373.DynamicBaseClassTest.basic event class functionality(DynamicBaseClassTest.groovy:18)
de.scrum_master.stackoverflow.q71631373.FirstEvent$SpockMock$1692978949@3e595da3
To Reproduce
This GWC example works. Now simply remove the @ characters.
// '.id' and '.name' should be enough, but on Spock 2.1 there is a problem
// when not explicitly using the '@' notation for direct field access.
event.@id > 0
[email protected]() == 10
Expected behavior
The test passes without the .@id field access notation under Spock 2.x, just like under 1.3.
Actual behavior
Spock complains about missing getters.
Java version
17
Buildtool version
Maven
What operating system are you using
Windows
Dependencies
x
Additional context
x
Looking at the example code, I see that the fields are protected. If you make them public, it works without the .@field access.
https://groovy-lang.org/objectorientation.html#properties
You can define a property with:
- an absent access modifier (no
public,protectedorprivate)
#1729 would fix this issue.
Was fixed by #1729