groovy
  1. groovy
  2. GROOVY-4979

@ToString creates additional unneeded field

    Details

    • Number of attachments :
      0

      Description

      Using @ToString(includeNames = true) inserts a field called $print$names into the class. This field is neither transient nor static, which causes havoc when using XStream.

      Example XStream output:

      [
        {
          "name": "み +()[]{}.mp3",
          "size": 690037,
          "outputSize": 0,
          "format": {
            "codec": "mp3",
            "name": "mp3",
            "bitDepth": "s16le",
            "samplingRate": 44100,
            "channels": 2,
            "$print$names": true
          }
        }
      ]
      

      I don't understand why the field is there in the first place since printNames is a compile-time thing.

        Activity

        Hide
        Paul King added a comment -

        Yes, with Roshan's published workaround I would recommend closing the issue if Johann agrees. We might as a separate activity want to deprecate the use of '$print$names' but that is a separate issue.

        Show
        Paul King added a comment - Yes, with Roshan's published workaround I would recommend closing the issue if Johann agrees. We might as a separate activity want to deprecate the use of '$print$names' but that is a separate issue.
        Hide
        Johann Burkard added a comment -

        The issue I think about here is that of annotations creating non-static fields. People can say "Groovy is slow" and that's one (largely irrelevant) thing but if they say "Groovy is slow and its memory usage is completely unpredictable and therefore, it cannot scale," that's unacceptable.

        In other words, if I didn't know it, I wouldn't expect Groovy to add fields to my classes. The fields it adds today are thankfully static so it's not really an issue but per-instance fields might be.

        Show
        Johann Burkard added a comment - The issue I think about here is that of annotations creating non-static fields. People can say "Groovy is slow" and that's one (largely irrelevant) thing but if they say "Groovy is slow and its memory usage is completely unpredictable and therefore, it cannot scale," that's unacceptable. In other words, if I didn't know it, I wouldn't expect Groovy to add fields to my classes. The fields it adds today are thankfully static so it's not really an issue but per-instance fields might be.
        Hide
        Paul King added a comment -

        I'm going to go ahead and close this issue. The internal $print$names field has been removed from Groovy 2.0 in any case. In general, annotations don't add fields (static or otherwise) without careful consideration. It would only be because such a field was required for the functionality of the annotation.

        Show
        Paul King added a comment - I'm going to go ahead and close this issue. The internal $print$names field has been removed from Groovy 2.0 in any case. In general, annotations don't add fields (static or otherwise) without careful consideration. It would only be because such a field was required for the functionality of the annotation.
        Hide
        Paul King added a comment -

        I just looked at the code changes I made for this for 2.0-beta-2 and they didn't seem to be committed - I presume I stuffed up the git command at this end. Re-applying shortly and I'll bump the fix version appropriately.

        Show
        Paul King added a comment - I just looked at the code changes I made for this for 2.0-beta-2 and they didn't seem to be committed - I presume I stuffed up the git command at this end. Re-applying shortly and I'll bump the fix version appropriately.
        Hide
        Paul King added a comment -

        fixed glitch

        Show
        Paul King added a comment - fixed glitch

          People

          • Assignee:
            Paul King
            Reporter:
            Johann Burkard
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: