Class scala.Int$ cannot be cast to class java.lang.Integer when querying/exercising choices

Greetings!

I am currently experimenting with OSS Daml 3.3.x and the integration with it via the ledger-json-api. So far it had worked quite well, however, one of the latest updates to the daml model I’ve done seems to introduce an error that doesn’t immediately make sense.

To elaborate on the context, I have a “factory“ contract that can create more contracts of another type via a choice, and it also keeps track of the metadata for the issued assets within a Map.

I’ve constructed a ledger-json-api request to exercise the choice on the “factory” contract. I have iterated upon the content of the request in attempts to gather more information on the issue(including changing the daml model), but the final version of a sample request looks like:

{
  "commands": [
    {
      "ExerciseCommand": {
        "templateId": "{{packageId}}:{{module}}:{{template}}",
        "contractId": "{{tokenFactoryCid}}",
        "choice": "Issue",
        "choiceArgument": {
          "id"            : "{{asset.id}}",
          "amount"        : "{{asset.amount}}",
          "to"            : "{{recipient}}"
        }
      }
    }
  ],
  "commandId": "{{$randomUUID}}",
  "userId": "{{actor}}",
  "applicationId": "{{applicationId}}",
  "actAs": [
    "{{actor}}"
  ]
}

However, submitting this request to the api yields the following result:

{
  "code": "LEDGER_API_INTERNAL_ERROR",
  "cause": "class scala.Int$ cannot be cast to class java.lang.Integer (scala.Int$ is in unnamed module of loader 'app'; java.lang.Integer is in module java.base of loader 'bootstrap')",
  "correlationId": null,
  "traceId": null,
  "context": {
    "throwableO": "Some(java.lang.ClassCastException: class scala.Int$ cannot be cast to class java.lang.Integer (scala.Int$ is in unnamed module of loader 'app'; java.lang.Integer is in module java.base of loader 'bootstrap'))"
  },
  "resources": [],
  "errorCategory": 4,
  "grpcCodeValue": 13,
  "retryInfo": null,
  "definiteAnswer": false
}

I can confirm that this response is irrelevant to the contents of the choice arguments, as the ledger json api yields the same result regardless of what type the each individual choice argument is (e.g. the type of the amount argument is irrelevant, tested with Int, Decimal and Text).

While debugging, I can confirm that this issue persists in versions from 3.2.x to 3.4.x. Version of java is irrelevant to the issue

Another observation that may be relevant to the case, is that this request can still be performed via daml script. The contract will be created (verified via participant.testing.acs_search), however, querying acs via POST v2/state/active-contracts yields the same error, if activeAtOffset is later than the offset at which the contract was created.

Do you have any suggestions as to where I could obtain a deeper insight into the nature of this error?
If any additional information is required, let me know.

Thanks!

I have attempted to reduce the example even further, while still reproducing the error, and I managed to boil it down to serialisation of the Date type.

It seems that ledger json api is unable to deserialise the Date type from the arguments, or serialise a Date field of an existing contract

The simplest possible daml model that still reproduces the issue:

template Dummy
  with 
    owner: Party
    date: Date
  where
    signatory owner

And the respective ledger-json-api request:

POST /v2/commands/submit-and-wait

{
  "commands": [
    {
      "CreateCommand": {
        "templateId": "{{packageId}}:{{module}}:Dummy",
        "createArguments": {
          "owner": "{{owner}}",
          "date": "2025-01-01"
        }
      }
    }
  ],
  "commandId": "{{$randomUUID}}",
  "userId": "{{owner}}",
  "applicationId": "{{applicationId}}",
  "actAs": [
    "{{owner}}"
  ]
}

Thank you for doing the work to reproduce this with minimal code. I was able to replicate your results. Then, I found that…

This was fixed a few days ago and has simply not made it into a release yet.

1 Like

Great to hear!

When it makes to a release, could you leave a message here for future reference? Thanks!