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

Final field caching issues in inherited field.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Not A Problem
    • Affects Version/s: 2.5.4
    • Fix Version/s: None
    • Component/s: groovy-runtime
    • Labels:
      None

      Description

      Note: *this seems to be a quite major issue*, kindly look at this one with emphasis.

      Please see the below test case:
      SubClass extends the SuperClass and overrides the field "inheritedField".

      class OtherClass {
          String otherField
          OtherClass(String otherField) {
              this.otherField = otherField
          }
          String toString() {
              return otherField
          }
      }
      class SuperClass {
          final OtherClass inheritedField = new OtherClass("Super Class String")
      }
      class SubClass extends SuperClass {
          final OtherClass inheritedField = new OtherClass("Sub Class String")
      }
      SuperClass superClass = new SuperClass()
      SubClass subClass = new SubClass()
      assert subClass.inheritedField.toString() == "Sub Class String"
      

      Actual result: assertion fails
      Expected result: assertion should pass
      Note: If "final" modifier is removed, assertion passes as expected.
      This seems an issue with final field caching.

      Assertion error text:

      Assertion failed: 
      assert subClass.inheritedField.toString() == "Sub Class String"
             |        |              |          |
             |        |              |          false
             |        |              'Super Class String'
             |        Super Class String
             SubClass@5b4b841f
      	at ConsoleScript11.run(ConsoleScript11:18)
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              anton.pryamostanov Anton Pryamostanov
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: