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

Non annotated evolution missed constructors when generics get involved

    Details

      Description

      Adding a non-nullable parameter to a class should work IFF a constructor is provided annotated with the <AT>DeprecatedConstructgorForSerialization annotation. This constructor provides defaults for the properties not present when the class may have been serialized allowing instances of it to be deserialized.

      However, something like this was breaking it

       data class NetworkParametersExample(
                      val minimumPlatformVersion: Int,
                      val notaries: List<String>,
                      val maxMessageSize: Int,
                      val maxTransactionSize: Int,
                      val modifiedTime: Instant,
                      val epoch: Int,
                      val whitelistedContractImplementations: Map<String, List<Int>>)
      

      when changed to something like this

              data class NetworkParametersExample(
                      val minimumPlatformVersion: Int,
                      val notaries: List<String>,
                      val maxMessageSize: Int,
                      val maxTransactionSize: Int,
                      val modifiedTime: Instant,
                      val epoch: Int,
                      val whitelistedContractImplementations: Map<String, List<Int>>,
                      /* to regenerate test class, comment out this element */
                      val eventHorizon: Int
              ) {
                  // when regenerating test class this won't be required
                  @DeprecatedConstructorForDeserialization(1)
                  @Suppress("UNUSED")
                  constructor (
                          minimumPlatformVersion: Int,
                          notaries: List<String>,
                          maxMessageSize: Int,
                          maxTransactionSize: Int,
                          modifiedTime: Instant,
                          epoch: Int,
                          whitelistedContractImplementations: Map<String, List<Int>>
                  ) : this(minimumPlatformVersion,
                          notaries,
                          maxMessageSize,
                          maxTransactionSize,
                          modifiedTime,
                          epoch,
                          whitelistedContractImplementations,
                          Int.MAX_VALUE)
              }
      

      Because there is the deprecated constructor this should be valid for reading instances of the class serialized as they were in the before time, in the long long ago.

      The actual problem is the generics and the way constructors are selected. The types of the serialized args are the generic type because we stripped all type info off of generics a while ago because ti just causes problems. However, the evolver code wasn't and it was seeing List and List<Int> as different

        Attachments

          Activity

            People

            • Assignee:
              Katelyn.Baker Katelyn Baker
              Reporter:
              Katelyn.Baker Katelyn Baker
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: