Salve ragazzi.
Ho un problema. Sto eseguendo su un server due thread nei quali ricevo dal client una stringa di comando e successivamente in base al comando dato eseguo un azione.
In particolare ricevo dal client due file xml.
In un caso non ho nessun problema. Il file viene correttamente ricevuto.
Nell'altro caso invece ho un eccezione molto strana dato che è esattamente tutto uguale al primo caso:

il codice è il seguente:
if("TI INVIO LE AZIONI ESEGUITE".equals(str)){
System.out.println("S: CLIENT DICE: '" + str + "'");
//RICEZIONE NELLA CARTELLA DI LAVORO DEL FILE AZIONITOSERVER.xml DAL
//DISPOSITIVO MOBILE
byte [] mybytearray2 = new byte [filesize];
InputStream is2 = client.getInputStream();
FileOutputStream fos2 = new FileOutputStream("AZIONITOSERVER.xml");
BufferedOutputStream bos2 = new BufferedOutputStream(fos2);
bytesRead2 = is2.read(mybytearray2,0,mybytearray2.length);
current2 = bytesRead2;

do {
bytesRead2 = is2.read(mybytearray2, current2, (mybytearray2.length-current2));
if(bytesRead2 >= 0) current2 += bytesRead2;
} while(bytesRead2 > -1);

bos2.write(mybytearray2, 0 , current2);
bos2.flush();
long end = System.currentTimeMillis();
System.out.println("S: SERVER DICE: LOGAZIONITOSERVER.XML RICEVUTO");
System.out.println("TEMPO IMPIEGATO RICEZIONE DA PARTE DEL SERVER DEL FILE LOGAZIONITOSERVER.XML: "+(end-start));
bos2.close();


L'eccezione che mi capita è:

java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at java.io.BufferedOutputStream.write(Unknown Source)
at agenda.bean.TCPDesktopServer.run(TCPDesktopServer. java:104)
at java.lang.Thread.run(Unknown Source)

dove la riga TCPDesktopServer.java:104 è la seguente:
bos2.write(mybytearray2, 0 , current2);

La cosa strana è che se non eseguo il primo thread cioè l'altro identico a questo, questa eccezione non avviene e tutto funziona, solo che ho bisogno di eseguire entrambi i thread.
Mi sa tanto di bug.
Vi ringrazio per l'aiuto.
Ciao.