Skip to content

ClassCastException: ArrayList cannot be cast to String on channelstate field in StatusEvent with Asterisk 20 #793

@phoneben

Description

@phoneben

Bug Description

When connected to an Asterisk 20 server via AMI, asterisk-java throws a
ClassCastException when processing a StatusEvent where the channelstate
field is received as a list (e.g. [6, 6]) instead of a single String value.

Stack Trace

ERROR: Unable to set property 'channelstate' to '[6, 6]' on
org.asteriskjava.manager.event.StatusEvent
class java.util.ArrayList cannot be cast to class java.lang.String

java.lang.ClassCastException: class java.util.ArrayList cannot be cast to
class java.lang.String (java.util.ArrayList and java.lang.String are in
module java.base of loader 'bootstrap')
at org.asteriskjava.manager.util.EventAttributesHelper.parseInteger(EventAttributesHelper.java:150)
at org.asteriskjava.manager.util.EventAttributesHelper.setAttributes(EventAttributesHelper.java:124)
at org.asteriskjava.manager.internal.EventBuilderImpl.buildEvent(EventBuilderImpl.java:232)
at org.asteriskjava.manager.internal.CustomEventBuilderImpl.buildEvent(CustomEventBuilderImpl.java:23)
at org.asteriskjava.manager.internal.ManagerReaderImpl.buildEvent(ManagerReaderImpl.java:364)
at org.asteriskjava.manager.internal.ManagerReaderImpl.run(ManagerReaderImpl.java:215)

Effect

The exception causes the AsyncEventPump to stop and the AMI connection to
drop. The application then reconnects, hits the same event, and crashes again
in a continuous restart loop.

Environment

  • asterisk-java version: 3.41.0
  • Asterisk version: Asterisk 20 (Call Manager 9.0.0)
  • Java version: 13.0.2

Expected Behavior

EventAttributesHelper.parseInteger() should handle the case where the value
is already a List/ArrayList instead of a String, either by taking the first
element or by gracefully skipping the field instead of throwing an exception
that kills the connection.

Suggested Fix

In EventAttributesHelper.parseInteger(), add a check:
if (value instanceof List) {
// take first element or skip gracefully
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions