ExternalTaskService.complete - Cannot construct instance of `org.camunda.bpm.client.impl.EngineRestExceptionDto` (although at least one Creator exists)

We currently notice in our logs that sometimes our ExternalTask can not be completed.

The following error is thrown:

TASK/CLIENT-01010 Exception while completing the external task: Connection could not be established with message: "Cannot construct instance of `org.camunda.bpm.client.impl.EngineRestExceptionDto` (although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (502)
 at [Source: (org.apache.http.conn.EofSensorInputStream); line: 1, column: 1]"
at org.camunda.bpm.client.topic.impl.TopicSubscriptionManager.handleExternalTask(TopicSubscriptionManager.java:155)
	at org.camunda.bpm.client.topic.impl.TopicSubscriptionManager.lambda$acquire$0(TopicSubscriptionManager.java:109)
	at java.base/java.util.Arrays$ArrayList.forEach(Unknown Source)
	at org.camunda.bpm.client.topic.impl.TopicSubscriptionManager.acquire(TopicSubscriptionManager.java:104)
	at org.camunda.bpm.client.topic.impl.TopicSubscriptionManager.run(TopicSubscriptionManager.java:88)
	at java.base/java.lang.Thread.run(Unknown Source)

We have just upgraded to Camunda platform 7.18. It seems that the 502 HTTP error cannot be mapped correctly to the EngineRestExceptionDto.

Do you have any suggestions on how we can fix this issue? Our External Tasks are retried, but retrying before “complete” is actually unfavorable.

Thank you for any help!

We were able to reproduce the bug with the following test:

def "test"() {
    def om = new ObjectMapper()
    //def content = '{"type": "string","message": "string","code": 0}'
    def content = '502'
    def is = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))

    def res = om.readValue(is, EngineRestExceptionDto)

    res != null

It seems that there is a bug in the process engine. Sometimes it returns just a number instead of a valid json, so that the error occurs. We noticed that this problem does not only occur at the complete request, but also f.e. with fetch and lock.