Skip to content

NullPointerException for SSL Connection on Android #413

Closed
@tobiasrohloff

Description

@tobiasrohloff

Hi,

I'm using the WebSocketClient in an Android app and I receive the following NullPointerException from some users:

java.lang.NullPointerException: ssl == null
	at com.android.org.conscrypt.NativeCrypto.SSL_read_BIO(Native Method)
	at com.android.org.conscrypt.OpenSSLEngineImpl.unwrap(OpenSSLEngineImpl.java:477)
	at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:1014)
	at org.java_websocket.SSLSocketChannel2.unwrap(SSLSocketChannel2.java:150)
	at org.java_websocket.SSLSocketChannel2.processHandshake(SSLSocketChannel2.java:123)
	at org.java_websocket.SSLSocketChannel2.write(SSLSocketChannel2.java:192)
	at org.java_websocket.SocketChannelIOHelper.writeBlocking(SocketChannelIOHelper.java:76)
	at org.java_websocket.client.WebSocketClient$WebsocketWriteThread.run(WebSocketClient.java:440)
	at java.lang.Thread.run(Thread.java:818)

The exception was thrown on different devices and different versions of Android. I use the following configuration to initiate the secured WebSocket connection:

webSocketClient = new WebSocketClient(uri, new Draft_10(), headers, 0) {
    ...
}

try {
    SSLContext sc = SSLContext.getInstance("TLS");
    sc.init(null, null, null);
    webSocketClient.setWebSocketFactory(new DefaultSSLWebSocketClientFactory(sc));
    webSocketClient.connect();
} catch (Exception e) {
    ...
}

I couldn't reproduce the issue on my debug devices. Any idea how I can avoid this or why it crashes sometimes? Can I catch the exception somehow? Looks like it is deeply nested in the library or Android itself.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions