Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserAgent.hangup() throws ClassCastException: NameAddress cannot be cast to String #32

Open
walidzaaneun opened this issue Feb 20, 2025 · 3 comments

Comments

@walidzaaneun
Copy link

When attempting to call the hangup method in org.mjsip.ua.UserAgent, a ClassCastException is thrown. This seems to occur when the code attempts to cast a NameAddress object to a String. This error happens when calling hangup directly or when it is triggered by the auto hangup timer. However, hanging up a call that has not yet been accepted inside the public void onUaIncomingCall(UserAgent ua, NameAddress callee, NameAddress caller, MediaDesc[] media_descs) method is declined with no issue.

Exception Stack Trace:

java.lang.ClassCastException: class org.mjsip.sip.address.NameAddress cannot be cast to class java.lang.String (org.mjsip.sip.address.NameAddress is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
	at org.mjsip.sip.header.MultipleHeader.toHeader(MultipleHeader.java:258) ~[mjsip-sip-2.0.3.jar:na]
	at org.mjsip.sip.message.BasicSipMessage.addHeadersAfter(BasicSipMessage.java:575) ~[mjsip-sip-2.0.3.jar:na]
	at org.mjsip.sip.message.SipMessage.addRoutes(SipMessage.java:340) ~[mjsip-sip-2.0.3.jar:na]
	at org.mjsip.sip.message.BasicSipMessageFactory.createRequest(BasicSipMessageFactory.java:196) ~[mjsip-sip-2.0.3.jar:na]
	at org.mjsip.sip.message.SipMessageFactory.createByeRequest(SipMessageFactory.java:263) ~[mjsip-sip-2.0.3.jar:na]
	at org.mjsip.sip.dialog.InviteDialog.bye(InviteDialog.java:713) ~[mjsip-sip-2.0.3.jar:na]
	at org.mjsip.sip.call.Call.hangup(Call.java:324) ~[mjsip-sip-2.0.3.jar:na]
	at org.mjsip.ua.UserAgent.hangup(UserAgent.java:190) ~[mjsip-ua-2.0.3.jar:na]

Note: Hanging up a call that has not been accepted yet inside onUaIncomingCall works without issue.

Please let me know if you need more details. Thank you!

@haumacher
Copy link
Owner

I think I identified the problem: A header was constructed with a list of addresses instead of a list of string due to an unsafe cast.

See 3270920

Could you re-test this situation?

@walidzaaneun
Copy link
Author

@haumacher thank you so much for you effort again, I applied the fix from 3270920, but I’m still encountering an issue when calling hangup(). Now, instead of the ClassCastException, I’m getting a java.net.ConnectException: Connection refused.

It looks like the transport layer is unable to establish a connection when attempting to send the BYE request. The error occurs in SipTransportCO.sendMessage, which suggests that either the SIP server is unreachable, or there’s still an issue with the message construction.

Let me know if you have any suggestions, or if you need more details from my side. Thanks!

2025-02-24T21:20:05.934Z  WARN 166302 --- [pool-6-thread-2] org.mjsip.sip.provider.SipTransportCO    : Exception

java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.Net.connect0(Native Method) ~[na:na]
	at java.base/sun.nio.ch.Net.connect(Net.java:579) ~[na:na]
	at java.base/sun.nio.ch.Net.connect(Net.java:568) ~[na:na]
	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:593) ~[na:na]
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) ~[na:na]
	at java.base/java.net.Socket.connect(Socket.java:633) ~[na:na]
	at java.base/java.net.Socket.connect(Socket.java:583) ~[na:na]
	at java.base/java.net.Socket.<init>(Socket.java:507) ~[na:na]
	at java.base/java.net.Socket.<init>(Socket.java:319) ~[na:na]
	at org.zoolu.net.TcpSocket.<init>(TcpSocket.java:66) ~[mjsip-net-2.0.4.jar:na]
	at org.mjsip.sip.provider.TcpTransport.createTransportConnection(TcpTransport.java:138) ~[mjsip-sip-2.0.4.jar:na]
	at org.mjsip.sip.provider.SipTransportCO.addConnection(SipTransportCO.java:263) ~[mjsip-sip-2.0.4.jar:na]
	at org.mjsip.sip.provider.SipTransportCO.sendMessage(SipTransportCO.java:163) ~[mjsip-sip-2.0.4.jar:na]
	at org.mjsip.sip.provider.SipProvider.sendRawMessage(SipProvider.java:831) ~[mjsip-sip-2.0.4.jar:na]
	at org.mjsip.sip.provider.SipProvider.sendRawMessage(SipProvider.java:807) ~[mjsip-sip-2.0.4.jar:na]
	at org.mjsip.sip.provider.SipProvider.sendMessage(SipProvider.java:792) ~[mjsip-sip-2.0.4.jar:na]
	at org.mjsip.sip.provider.SipProvider.sendMessage(SipProvider.java:704) ~[mjsip-sip-2.0.4.jar:na]
	at org.mjsip.sip.transaction.TransactionClient.request(TransactionClient.java:92) ~[mjsip-sip-2.0.4.jar:na]
	at org.mjsip.sip.dialog.InviteDialog.bye(InviteDialog.java:730) ~[mjsip-sip-2.0.4.jar:na]
	at org.mjsip.sip.dialog.InviteDialog.bye(InviteDialog.java:714) ~[mjsip-sip-2.0.4.jar:na]
	at org.mjsip.sip.call.Call.hangup(Call.java:324) ~[mjsip-sip-2.0.4.jar:na]
	at org.mjsip.ua.UserAgent.hangup(UserAgent.java:190) ~[mjsip-ua-2.0.4.jar:na]
	at org.mjsip.ua.RegisteringMultipleUAS$AutoHangup.lambda$start$0(RegisteringMultipleUAS.java:128) ~[mjsip-ua-2.0.4.jar:na]
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[na:na]
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
	at java.base/java.lang.Thread.run(Thread.java:840) ~[na:na]

@haumacher
Copy link
Owner

I would suggest to verify that the correct address is contacted in TcpTransport.createTransportConnection(TcpTransport.java:138)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants