Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9369

Unable to distinguish foo.x and foo.getProperty("x") in call interceptor

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Task
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.0.0-rc-2, 3.0.0-rc-3
    • Fix Version/s: None
    • Component/s: groovy-runtime
    • Labels:
      None

      Description

      TL;TR. It is problematic in Groovy 3 to distinguish go.x and go.getProperty("x") in a call (at the level of an interceptor for a mocking system)?

      A ticket to track problem raised using the mailing list . Quoted original concerns:

      Working on the Spock adjustment to Groovy 3 I spotted that Groovy 3
      started for a property access go.x (go - some GroovyObject instance with
      a field "x") to call go.getProperty("x") instead of go.getX() directly
      (as it took place in Groovy 2). This broke tests for mocking with a
      property call (getX() is stubbed, but go.x is called) and forced me to
      detect getProperty("x") calls in a mock interceptor - to analyze deeper
      and check which method (here getter) is being called and if has been
      stubbed.

      However, in addition, it should be possible to just stub direct
      go.getProperty("x") calls [1]. To do that, currently, I have to analyze
      a stack trace to detect groovy.lang.GroovyObject$getProperty.call() at
      the position -3 [2] (for direct go.getProperty("x") calls) and deeper
      process only the other calls (go.x). It seems to work, but it's quite
      ugly and fragile. I wonder, how to reliably differentiate those two
      types of calls?
      [1] - https://github.com/spockframework/spock/blob/1dd24a2251afe3151e04b50af8afb6285b236c76/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaMocksForGroovyClasses.groovy#L75-L81
      [2] - https://github.com/spockframework/spock/commit/1dd24a2251afe3151e04b50af8afb6285b236c76

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              szpak Marcin Zajaczkowski

              Dates

              • Created:
                Updated:

                Issue deployment