NPE in TimeoutInputStream
* Android version: 10 * Briar version: 1.4.20 (6b20b03) * Phone model: SPRD ums512_1h10_Natv Stacktrace: ``` java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.InputStream.read(byte[], int, int)' on a null object reference at org.briarproject.bramble.io.TimeoutInputStream.read(TimeoutInputStream.java:52) at org.briarproject.bramble.util.IoUtils.read(IoUtils.java:95) at org.briarproject.bramble.connection.Connection.readTag(Connection.java:59) at org.briarproject.bramble.connection.Connection.recogniseTag(Connection.java:49) at org.briarproject.bramble.connection.IncomingDuplexSyncConnection.run(IncomingDuplexSyncConnection.java:44) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:919) ``` Edited log: ``` 02-16 17:40:19.815 I/BaseActivity: Pausing ConversationActivity 02-16 17:40:19.842 I/BaseActivity: Creating ConnectViaBluetoothActivity 02-16 17:40:19.870 I/BaseActivity: Starting ConnectViaBluetoothActivity 02-16 17:40:19.872 I/BaseActivity: Resuming ConnectViaBluetoothActivity 02-16 17:40:20.349 I/BaseActivity: Stopping ConversationActivity 02-16 17:40:22.536 I/BaseActivity: Pausing ConnectViaBluetoothActivity 02-16 17:40:22.679 I/BaseActivity: Resuming ConnectViaBluetoothActivity 02-16 17:40:22.690 I/BaseActivity: Pausing ConnectViaBluetoothActivity 02-16 17:40:22.781 I/AndroidBluetoothPlugin: Scan mode: Discoverable 02-16 17:40:22.822 I/BluetoothConnectionLimiterImpl: Limiting started 02-16 17:40:22.833 I/BaseActivity: Resuming ConnectViaBluetoothActivity 02-16 17:40:22.873 I/AndroidBluetoothPlugin: Discovery started 02-16 17:40:25.153 I/BaseActivity: Pausing ConnectViaBluetoothActivity 02-16 17:40:25.310 I/BaseActivity: Resuming ConnectViaBluetoothActivity 02-16 17:40:31.235 I/PollerImpl: Polling plugin org.briarproject.bramble.bluetooth 02-16 17:40:31.239 I/ConnectionRegistryImpl: 0 contacts connected or better: org.briarproject.bramble.bluetooth 02-16 17:40:31.239 I/BluetoothConnectionLimiterImpl: Can't open contact connection while limiting 02-16 17:40:32.850 I/AndroidBluetoothPlugin: Cancelling discovery 02-16 17:40:32.853 I/AndroidBluetoothPlugin: Could not connect to any devices 02-16 17:40:37.857 W/ConnectViaBluetoothViewModel: Failed to connect 02-16 17:40:37.858 I/BluetoothConnectionLimiterImpl: Limiting ended 02-16 17:40:37.894 I/BaseActivity: Pausing ConnectViaBluetoothActivity 02-16 17:40:37.935 I/BaseActivity: Starting ConversationActivity 02-16 17:40:37.938 I/BaseActivity: Resuming ConversationActivity 02-16 17:40:38.418 I/BaseActivity: Stopping ConnectViaBluetoothActivity 02-16 17:40:38.422 I/BaseActivity: Destroying ConnectViaBluetoothActivity 02-16 17:40:43.489 I/BaseActivity: Pausing ConversationActivity 02-16 17:40:43.516 I/BaseActivity: Creating ConnectViaBluetoothActivity 02-16 17:40:43.536 I/BaseActivity: Starting ConnectViaBluetoothActivity 02-16 17:40:43.538 I/BaseActivity: Resuming ConnectViaBluetoothActivity 02-16 17:40:44.003 I/BaseActivity: Stopping ConversationActivity 02-16 17:40:44.794 I/BaseActivity: Pausing ConnectViaBluetoothActivity 02-16 17:40:44.824 I/AndroidBluetoothPlugin: Scan mode: Discoverable 02-16 17:40:44.828 I/BluetoothConnectionLimiterImpl: Limiting started 02-16 17:40:44.836 I/BaseActivity: Resuming ConnectViaBluetoothActivity 02-16 17:40:44.879 I/AndroidBluetoothPlugin: Discovery started 02-16 17:40:47.692 I/AndroidBluetoothPlugin: Discovered AC:[scrubbed]:72 02-16 17:40:50.144 I/AndroidBluetoothPlugin: Discovered 30:[scrubbed]:50 02-16 17:40:51.531 I/AndroidBluetoothPlugin: Discovered AC:[scrubbed]:72 02-16 17:40:52.154 I/AndroidBluetoothPlugin: Discovered AC:[scrubbed]:72 02-16 17:40:52.890 I/AndroidBluetoothPlugin: Discovered CC:[scrubbed]:85 02-16 17:40:53.437 I/AndroidBluetoothPlugin: Discovered CC:[scrubbed]:85 02-16 17:40:54.092 I/AndroidBluetoothPlugin: Discovered AC:[scrubbed]:72 02-16 17:40:54.844 I/AndroidBluetoothPlugin: Cancelling discovery 02-16 17:40:54.848 I/AndroidBluetoothPlugin: Connecting to 30:[scrubbed]:50 02-16 17:40:54.850 I/BluetoothConnectionLimiterImpl: Connection opened, 1 open 02-16 17:40:54.850 I/ConnectViaBluetoothViewModel: Could connect, handling connection 02-16 17:40:54.850 I/BluetoothConnectionLimiterImpl: Limiting ended 02-16 17:40:54.867 I/DuplexOutgoingSession: Generated ack: false 02-16 17:40:54.878 I/DuplexOutgoingSession: Generated batch: false 02-16 17:40:54.880 I/DuplexOutgoingSession: Generated offer: false 02-16 17:40:54.881 I/DuplexOutgoingSession: Generated request: false 02-16 17:40:54.882 I/BaseActivity: Pausing ConnectViaBluetoothActivity 02-16 17:40:54.925 I/BaseActivity: Starting ConversationActivity 02-16 17:40:54.929 I/BaseActivity: Resuming ConversationActivity 02-16 17:40:55.410 I/BaseActivity: Stopping ConnectViaBluetoothActivity 02-16 17:40:55.413 I/BaseActivity: Destroying ConnectViaBluetoothActivity 02-16 17:41:01.986 I/AbstractBluetoothPlugin: Connection received 02-16 17:41:01.986 I/BluetoothConnectionLimiterImpl: Connection opened, 2 open ``` As far as I can tell, this device is the head unit in a car. The log shows an outgoing Bluetooth connection being made, then an incoming connection being received. Perhaps the Bluetooth stack doesn't support multiple connections (or doesn't support incoming and outgoing connections with the same device). In any case, BluetoothSocket#getInputStream() returns null for the second connection. We should check this (and also for the output stream) and throw an IOException rather than crashing.
issue