Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-663

JavaBean code generator produces incorrect setter methods

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 0.2
    • 0.3
    • Java - Compiler
    • None
    • Patch Available

    Description

      The original Thrift JavaBean generator produced set* methods for a property 'foo' that looked like:

      public void setFoo(int foo) {
      this.foo = foo;
      }

      The more recent code in the 0.2.0 release now returns a value:

      public MyStruct setFoo(int foo) {
      this.foo = foo;
      return this;
      }

      I can imagine this was possibly desired by someone to implement a "chaining" style of coding, but this is no longer a correct JavaBean. The JavaBean spec requires that the return type of set* functions be 'void', and various tools and frameworks enforce this requirement. For example, the Stripes web UI toolkit thinks that a field is read-only if the set* function doesn't return 'void'.

      I'll attach a trivial patch to restore this to the previous behavior. If a chaining-style setter is desired by others, I'd recommend making this a separate method on the bean rather than replacing the standard setter. E.g.:

      public MyStruct setChainFoo(int foo) { ...

      Or something like that.

      Attachments

        1. java-setter.diff
          0.8 kB
          Dave Engberg
        2. thrift-663.patch
          2 kB
          Bryan Duxbury

        Activity

          People

            bryanduxbury Bryan Duxbury
            engberg Dave Engberg
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: