Groovy
  1. Groovy
  2. GROOVY-3205

Cannot override toString() in a "mapOfClosures as AClass" implementation

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6-beta-2
    • Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
    • Component/s: None
    • Labels:
      None

      Description

      I am unable to override toString() when I coerce a map-of-closures as a class. This works on 1.5.8 but not on 1.6-rc-1 and 1.7-beta-1 branches. The code below highlights the issue:

      class GroovyXXXXBug extends GroovyTestCase {
      	def void testOverrideToStringInMapOfClosuresAsClass() {
      		def subObj = [ toString: { "Sub toString()" } ] as GroovyXXXXBugBase
      		assert subObj.toString() == "Sub toString()"
      	}
      }
      
      class GroovyXXXXBugBase {
         String toString() { "Base toString()" }
      }
      

      The code generated by ProxyGenerator for the overridden toString() method looks as below, which is not correct because of the extra args parameter and because of it the toString() gets overloaded and not overridden:

      def toString(Object[] args) {
              this.@closureMap['toString'] (*args)
      }
      

        Activity

        Roshan Dawrani created issue -
        Paul King made changes -
        Field Original Value New Value
        Assignee Paul King [ paulk_asert ]
        Hide
        Paul King added a comment -

        Spotted the issue. We specifically exclude java.lang.Object methods. It is easy to handle direct case where such methods are overriden. I'll add a change for that. I'll think a little further about such methods further up the inheritance hierarchy.

        Show
        Paul King added a comment - Spotted the issue. We specifically exclude java.lang.Object methods. It is easy to handle direct case where such methods are overriden. I'll add a change for that. I'll think a little further about such methods further up the inheritance hierarchy.
        Hide
        Paul King added a comment -

        Roshan, want to try trunk? See if you think it behaves OK.

        Show
        Paul King added a comment - Roshan, want to try trunk? See if you think it behaves OK.
        Hide
        Roshan Dawrani added a comment -

        Tried the changes done to trunk for this issue and it seems to be working fine now. Can override toString() again.

        Show
        Roshan Dawrani added a comment - Tried the changes done to trunk for this issue and it seems to be working fine now. Can override toString() again.
        Hide
        Guillaume Delcroix added a comment -

        So the issue should be closed now?

        Show
        Guillaume Delcroix added a comment - So the issue should be closed now?
        Hide
        Roshan Dawrani added a comment -

        The implementation on the trunk fixes the issue but:

        1) It has not been implemented on 1.6-rc-1 branch yet.

        2) Paul's comments on trunk say "initial fix - perhaps a more elaborate fix and test to come". If he wants to fix it more elaborately, you may want to leave it open for that.

        From my side, I see it fixed. As soon as it is marked fixed (indicating that from Paul's side it is done), I can close it from my side.

        Show
        Roshan Dawrani added a comment - The implementation on the trunk fixes the issue but: 1) It has not been implemented on 1.6-rc-1 branch yet. 2) Paul's comments on trunk say "initial fix - perhaps a more elaborate fix and test to come". If he wants to fix it more elaborately, you may want to leave it open for that. From my side, I see it fixed. As soon as it is marked fixed (indicating that from Paul's side it is done), I can close it from my side.
        Hide
        Guillaume Delcroix added a comment -

        Okie dokie, thanks Roshan for the clarifications.

        Show
        Guillaume Delcroix added a comment - Okie dokie, thanks Roshan for the clarifications.
        Hide
        Paul King added a comment -

        There is still a case not covered. If you have Parent extends Child and Child has an explicit Object method, e.g. toString(), it won't be overridden. I plan to have a look at that tonight.

        Show
        Paul King added a comment - There is still a case not covered. If you have Parent extends Child and Child has an explicit Object method, e.g. toString() , it won't be overridden. I plan to have a look at that tonight.
        Hide
        Paul King added a comment -

        Aligned behavior to be the same as for ConvertedMap behavior. Added test. Ported most of the behavior to the 1.5 branch.

        Show
        Paul King added a comment - Aligned behavior to be the same as for ConvertedMap behavior. Added test. Ported most of the behavior to the 1.5 branch.
        Paul King made changes -
        Fix Version/s 1.5.8 [ 14630 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Roshan Dawrani made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12732205 ] Default workflow, editable Closed status [ 12744030 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12970075 ] Default workflow, editable Closed status [ 12977836 ]
        Mark Thomas made changes -
        Assignee paulk_asert [ paulk_asert ] Paul King [ paulk ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        3d 7h 49m 1 Paul King 19/Dec/08 06:02
        Resolved Resolved Closed Closed
        8m 15s 1 Roshan Dawrani 19/Dec/08 06:10

          People

          • Assignee:
            Paul King
            Reporter:
            Roshan Dawrani
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development