chesterbr / minitruco-android

A popular Brazilian card game (Truco) running on Android.
https://play.google.com/store/apps/details?id=me.chester.minitruco&pli=1&hl=pt
BSD 3-Clause "New" or "Revised" License
87 stars 36 forks source link

NPE ao receber infos da mesa no cliente Bluetooth #170

Open chesterbr opened 1 year ago

chesterbr commented 1 year ago

Na 2.5.3, essa exceção aparece de vez em quando:

Exception java.lang.ArrayIndexOutOfBoundsException: length=3; index=-1
  at me.chester.minitruco.android.multiplayer.bluetooth.ServidorBluetoothActivity.verificaVersaoCompativel (ServidorBluetoothActivity.java:188)
  at me.chester.minitruco.android.multiplayer.bluetooth.ServidorBluetoothActivity.run (ServidorBluetoothActivity.java:162)
  at java.lang.Thread.run (Thread.java:1012)

Tudo indica que, de alguma forma, o split dos parâmetros está falhando nessa linha:

https://github.com/chesterbr/minitruco-android/blob/5df4da9f39e530b0297a3ce40df1c11463fc0229/app/src/main/java/me/chester/minitruco/android/multiplayer/bluetooth/ClienteBluetoothActivity.java#L162-L169

Sanitização

Isso só se explicaria se tivesse um espaço em algum deles - o que é sanitizado no servidor:

Aqui é onde o servidor garante que seu próprio nome não tem espaços:

https://github.com/chesterbr/minitruco-android/blob/5df4da9f39e530b0297a3ce40df1c11463fc0229/app/src/main/java/me/chester/minitruco/android/multiplayer/bluetooth/ServidorBluetoothActivity.java#L373-L380

e aqui ele garante que os nomes dos clientes também não tem:

https://github.com/chesterbr/minitruco-android/blob/5df4da9f39e530b0297a3ce40df1c11463fc0229/app/src/main/java/me/chester/minitruco/android/multiplayer/bluetooth/ServidorBluetoothActivity.java#L266-L267

chesterbr commented 1 year ago

Esses são alguns celulares em que o problema ocorreu (tipicamente, mas não sempre, o nome bluetooth default é o nome do celular):

samsung a13
Redmi spes
motorola hawaiip
xiaomi ginkgo
samsung a31
xiaomi lavender
Infinix Infinix-X6812B
POCO vayu
Redmi joyeuse
motorola caprip
motorola java
motorola nairo
samsung a12s
samsung m31
Redmi miel
Redmi tapas
motorola astro
motorola capri
motorola hawao
motorola malta
motorola rhode
motorola sanders_nt
samsung a10s
samsung a22
samsung a53x
samsung m53x
samsung r1q

Não parece ter um padrão de nenhum tipo aí, deve ser algum nome customizado que causa o problema