Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingMethodException when accessing fields without explicit @ #1452

Closed
kriegaex opened this issue Mar 27, 2022 · 3 comments
Closed

MissingMethodException when accessing fields without explicit @ #1452

kriegaex opened this issue Mar 27, 2022 · 3 comments
Assignees
Labels

Comments

@kriegaex
Copy link
Contributor

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
    event.@name.length() == 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

@kriegaex kriegaex added the bug label Mar 27, 2022
@leonard84
Copy link
Member

leonard84 commented Jun 29, 2022

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, protected or private)

AndreasTu added a commit to AndreasTu/spock that referenced this issue Jul 31, 2023
The test "Access protected fields Issue spockframework#1452" covers the
"MissingMethodException when accessing fields without explicit @" issue.

This fixes spockframework#1452
@AndreasTu
Copy link
Member

#1729 would fix this issue.

AndreasTu added a commit to AndreasTu/spock that referenced this issue Aug 3, 2023
The test "Access protected fields Issue spockframework#1452" covers the
"MissingMethodException when accessing fields without explicit @" issue.

This fixes spockframework#1452
AndreasTu added a commit to AndreasTu/spock that referenced this issue Aug 3, 2023
The test "Access protected fields Issue spockframework#1452" covers the
"MissingMethodException when accessing fields without explicit @" issue.

This fixes spockframework#1452
leonard84 pushed a commit to AndreasTu/spock that referenced this issue Aug 4, 2023
The test "Access protected fields Issue spockframework#1452" covers the
"MissingMethodException when accessing fields without explicit @" issue.

This fixes spockframework#1452
AndreasTu added a commit to AndreasTu/spock that referenced this issue Aug 6, 2023
The test "Access protected fields Issue spockframework#1452" covers the
"MissingMethodException when accessing fields without explicit @" issue.

This fixes spockframework#1452
AndreasTu added a commit to AndreasTu/spock that referenced this issue Aug 9, 2023
The test "Access protected fields Issue spockframework#1452" covers the
"MissingMethodException when accessing fields without explicit @" issue.

This fixes spockframework#1452
@AndreasTu AndreasTu self-assigned this Aug 14, 2023
AndreasTu added a commit to AndreasTu/spock that referenced this issue Aug 21, 2023
The test "Access protected fields Issue spockframework#1452" covers the
"MissingMethodException when accessing fields without explicit @" issue.

This fixes spockframework#1452
AndreasTu added a commit to AndreasTu/spock that referenced this issue Aug 25, 2023
The Groovy 3 & 4 runtime expects to have the @internal annotation on the MOP methods from GroovyObject.
That AbstractCallSite.createGroovyObjectGetPropertySite() processes it as GroovyObject.
So the ByteBuddyMockFactory now adds the @internal annotation to the intercepted MOP methods.

After that the "Unable to access protected constant when spying instances" problems are gone,
because we take the normal Groovy route.

Also some strange inconsistencies for Groovy  2 <=> 3,4 are now gone,
but a new inconsistency appeared Groovy 4 prefers is over get for boolean.
But this is not a Spock issue, because in Groovy only code the same thing happens.
See tests in JavaMocksForGroovyClasses.

The test "Access protected fields Issue spockframework#1452" covers the
"MissingMethodException when accessing fields without explicit @" issue.

This fixes spockframework#1145, spockframework#1452, spockframework#1501, spockframework#1608

Co-authored-by: Björn Kautler <[email protected]>
AndreasTu added a commit to AndreasTu/spock that referenced this issue Aug 25, 2023
The Groovy 3 & 4 runtime expects to have the @internal annotation on the MOP methods from GroovyObject.
That AbstractCallSite.createGroovyObjectGetPropertySite() processes it as GroovyObject.
So the ByteBuddyMockFactory now adds the @internal annotation to the intercepted MOP methods.

After that the "Unable to access protected constant when spying instances" problems are gone,
because we take the normal Groovy route.

Also some strange inconsistencies for Groovy  2 <=> 3,4 are now gone,
but a new inconsistency appeared Groovy 4 prefers is over get for boolean.
But this is not a Spock issue, because in Groovy only code the same thing happens.
See tests in JavaMocksForGroovyClasses.

The test "Access protected fields Issue spockframework#1452" covers the
"MissingMethodException when accessing fields without explicit @" issue.

This fixes spockframework#1145, spockframework#1452, spockframework#1501, spockframework#1608

Co-authored-by: Björn Kautler <[email protected]>
leonard84 added a commit that referenced this issue Sep 15, 2023
#1729)

The Groovy 3 & 4 runtime expects to have the `@Internal` annotation on the MOP methods from `GroovyObject`. That `AbstractCallSite.createGroovyObjectGetPropertySite()` processes it as `GroovyObject`. So the `ByteBuddyMockFactory` now adds the `@Internal` annotation to the intercepted MOP methods.

After that the "Unable to access protected constant when spying instances" problems are gone, because we take the normal Groovy route.

Also some strange inconsistencies for Groovy  2 <=> 3,4 are now gone, but a new inconsistency appeared Groovy 4 prefers is over get for boolean. But this is not a Spock issue, because in Groovy only code the same thing happens. See tests in JavaMocksForGroovyClasses.

This fixes #1501, #1452, #1608 and #1145.

Co-authored-by: Björn Kautler <[email protected]>
Co-authored-by: Leonard Brünings <[email protected]>
@AndreasTu
Copy link
Member

Was fixed by #1729

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants