Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException for SSL Connection on Android #413

Closed
tobiasrohloff opened this issue Nov 21, 2016 · 13 comments
Closed

NullPointerException for SSL Connection on Android #413

tobiasrohloff opened this issue Nov 21, 2016 · 13 comments

Comments

@tobiasrohloff
Copy link

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

@erobic
Copy link

erobic commented Jan 30, 2017

We are having this exact same issue!

@yasserf
Copy link

yasserf commented Mar 7, 2017

Same, any idea on why this happens?

@marci4
Copy link
Collaborator

marci4 commented Mar 19, 2017

Hello @yasserf,

could you provide me with a test application where I can try to fix this problem.

Greetings
marci4

@marci4
Copy link
Collaborator

marci4 commented Apr 15, 2017

possible cause #424

@marci4
Copy link
Collaborator

marci4 commented May 11, 2017

@erobic @rhlff could you provide me a test application?

@tobiasrohloff
Copy link
Author

Unfortunately, I couldn't reproduce the issue on any of my debug devices or the emulator yet. I got the error logs from the Google Play Console.

@marci4
Copy link
Collaborator

marci4 commented May 28, 2017

Hello @rhlff,

I changed some code with #488.

Hope to resolve those issues with these changes!

Greetings
marci4

@tobiasrohloff
Copy link
Author

Hi @marci4,

I already updated our app to version 1.3.3 and I will monitor if the issue will appear again. Hope for the best :)

@arpitjoshi08
Copy link

arpitjoshi08 commented Jul 29, 2017

i am using socket 0.9 connection and for that i am using https://github.com/Gottox/socket.io-java-client with javewebsocket 1.3.3 jar and getting issue is some devices ;

Fatal Exception: java.lang.NullPointerExceptionssl == null Raw Text

  | com.android.org.conscrypt.NativeCrypto.SSL_write_BIO (NativeCrypto.java)
  | javax.net.ssl.SSLEngine.wrap (SSLEngine.java:1093)
  | org.java_websocket.SSLSocketChannel2.wrap (SSLSocketChannel2.java:141)
  | org.java_websocket.SSLSocketChannel2.write (SSLSocketChannel2.java:195)
  | org.java_websocket.SocketChannelIOHelper.writeBlocking (SocketChannelIOHelper.java:76)
  | org.java_websocket.client.WebSocketClient$WebsocketWriteThread.run (WebSocketClient.java:440)

i am not getting the reason why is it happening , can anyone help for that to resolved this?
and using 1.3.4 getting other issue like many time disconnect connection of node.
getting this issue;

07-29 02:43:50.077 7325-8261/com.sockettollnate W/System.err: at com.sockettollnate.socket.WebsocketTransport.onMessage(WebsocketTransport.java:188)
07-29 02:43:50.077 7325-8261/com.sockettollnate W/System.err: at org.java_websocket.client.WebSocketClient.onWebsocketMessage(WebSocketClient.java:339)
07-29 02:43:50.077 7325-8261/com.sockettollnate W/System.err: at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:448)
07-29 02:43:50.077 7325-8261/com.sockettollnate W/System.err: at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:201)
07-29 02:43:50.077 7325-8261/com.sockettollnate W/System.err: at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:276)
07-29 02:43:50.077 7325-8261/com.sockettollnate W/System.err: at java.lang.Thread.run(Thread.java:841)

@marci4
Copy link
Collaborator

marci4 commented Jul 31, 2017

Hello @arpitjoshi08,

first of all I have no idea if https://github.com/Gottox/socket.io-java-client is implementing the websocket protocol correctly. So there also may be issues there?

Could you please tell me on what specific device versions you are getting this error? Does this only happen in production or also in the emulator?

1.3.4 introduces a feature which detects if the other endpoint is not reachable any more (due to dropped internet etc), so in short all the connections got lost but the underlaying runtime did not detect it on its own.

Greetings
marci4

@arpitjoshi08
Copy link

arpitjoshi08 commented Aug 1, 2017

hii @marci4 , i am getting issue in samsung SM-G570F (6.0) device (with 1.3.3). and if using 1.3.4 jar i am getting issue Gottox/socket.io-java-client#4 so thats why
i am using 1.3.3.
and is there any sample available to connect socket using this library if avail for android , please provide me link for that

@marci4
Copy link
Collaborator

marci4 commented Aug 2, 2017

Hello @arpitjoshi08,

I will try to test this in an emulator if I got the time on the weekend.

Apart from this, no there is no example application for the socket.io-java-client. Maybe get in contact to the maintainer to help you with your issue!

Greetings
marci4

@marci4
Copy link
Collaborator

marci4 commented Nov 5, 2017

No feedback!

If you still ave this issue, please open a separate issue!
Greetings
marci4

@marci4 marci4 closed this as completed Nov 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants