Uploaded image for project: 'Corda'
  1. CORDA-1945

ClassCarpenter fails when superclass has double-size primitive field (e.g. long, double)

    Details

    • Type: Bug
    • Status: Done (View workflow)
    • Priority: Medium
    • Resolution: Done
    • Affects versions: Corda 3.2
    • Fix versions: Corda 3.3
    • Components: None
    • Labels:
      None

      Description

      The following test fails, because the `ClassCarpenter` incorrectly calculates the stack size of fields if there are double-size primitive fields (e.g. long or double) in a superclass constructor:

          @Test
          fun `superclasses with double size constructor parameters`() {
              val schema1 = ClassSchema(
                      "gen.A",
                      mapOf("a" to NonNullableField(Long::class.javaPrimitiveType!!)))
      
              val schema2 = ClassSchema(
                      "gen.B",
                      mapOf("b" to NonNullableField(String::class.java)),
                      schema1)
      
              val clazz = cc.build(schema2)
              val i = clazz.constructors[0].newInstance(1L, "xb") as SimpleFieldAccess
              assertEquals(1L, i["a"])
              assertEquals("xb", i["b"])
              assertEquals("B{a=1, b=xb}", i.toString())
          }
      

      The fault is in ClassWriter.generateClassConstructor, and the solution is to sum the sizes of the fields in the superclass constructor and make sure this value is used to set the initial stack slot correctly for the parameters.

        Attachments

          Activity

            People

            • Assignee:
              Dominic.Fox Dominic.Fox@r3.com
              Reporter:
              Dominic.Fox Dominic.Fox@r3.com
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: