Re: ConcurrentModificationException whilst using SshClient.
Moshe Elisha <[email protected]> Tue, 31 Aug 2010 12:55:19 +0000 (UTC)
| Newsgroups | gmane.comp.java.sshtools.user |
|---|---|
| Message-ID | <[email protected]> |
I encountered the same problem with version 0.2.9 and I am publishing it here as
I could not find a solution anywhere.
The problem is when the connect method is called simultaneously from multiple
threads.
One possible scenario that might cause this ConcurrentModificationException is
(depends on the values passed to the methods):
The application calls one of the com.sshtools.j2ssh.SshClient#connect methods
which eventually calls connect(SshConnectionProperties properties,
HostKeyVerification hostVerification).
The connect calls
com.sshtools.j2ssh.transport.TransportProtocolCommon#startTransportProtocol
(TransportProvider provider, SshConnectionProperties properties)
startTransportProtocol creates a com.sshtools.j2ssh.SshThread with the
TransportProtocolCommon.
TransportProtocolCommon#run() calls
TransportProtocolCommon#startBinaryPacketProtocol which calls different methods
that some use SshMsgKexInit.toString() (such as
com.sshtools.j2ssh.transport.TransportProtocolCommon#onMsgKexInit)
com.sshtools.j2ssh.transport.SshMsgKexInit has members supportedEncryptCS and
supportedEncryptSC.
Both are initialized using the method
com.sshtools.j2ssh.transport.SshMsgKexInit#sortAlgorithmList and refer to the
same static ArrayList.
The sortAlgorithmList removes and adds from the ArrayList given and if someone
calls SshMsgKexInit.toString() at the same time you will get:
java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
at java.util.AbstractList$Itr.next(Unknown Source)
at java.util.AbstractCollection.toString(Unknown Source)
at com.sshtools.j2ssh.transport.SshMsgKexInit.toString(Unknown Source)
at
com.sshtools.j2ssh.transport.TransportProtocolClient.setLocalKexInit
(Unknown Source)
at
com.sshtools.j2ssh.transport.TransportProtocolCommon.sendKeyExchangeInit
(Unknown
Source)
at
com.sshtools.j2ssh.transport.TransportProtocolCommon.startBinaryPacketProtocol
(Unknown
Source)
at com.sshtools.j2ssh.transport.TransportProtocolCommon.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
My current solution is to put SshClient.connect invocation in an application
scope synchronized block.
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd