Firebase null pointer exception. Attached stacktrace down below
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase(java.util.Locale)' on a null object reference
at com.firebase.tubesock.WebSocketHandshake.verifyServerHandshakeHeaders(WebSocketHandshake.java:96)
at com.firebase.tubesock.WebSocket.runReader(WebSocket.java:365)
at com.firebase.tubesock.WebSocket.access$000(WebSocket.java:30)
at com.firebase.tubesock.WebSocket$2.run(WebSocket.java:108)
at java.lang.Thread.run(Thread.java:818)
Version : latest (2.5.2+) as of 3-may-2016
Device Details : LGE - lgls770 running android 6.0 and Non-Rooted
The code snippet below is the implementation of verifyServerhandshakeHeaders
method found in WebSocketHandshake.java
.
public void verifyServerHandshakeHeaders(HashMap<String, String> headers) {
if (!headers.get("Upgrade").toLowerCase(Locale.US).equals("websocket")) {
throw new WebSocketException("connection failed: missing header field in server handshake: Upgrade");
} else if (!headers.get("Connection").toLowerCase(Locale.US).equals("upgrade")) {
throw new WebSocketException("connection failed: missing header field in server handshake: Connection");
}
}
As you can see, if the server does not include an Upgrade HTTP header in the response of the opening handshake (RFC 6455, 4. Opening Handshake), this code throws NullPointerException
.
In addition, because the headers
instance given to this method is created by new HashMap<String, String>()
(WebSocket.java:360
), HTTP headers sent from the server must be case-sensitive although the HTTP specification says "Field names are case-insensitive" (RFC 2616, 4.2 Message Headers). Therefore, for example, if a server sends an Upgrade HTTP header in all capital letters like UPGRADE
, TubeSock throws NullPointerException
although the server's behavior is correct.
headers
instance should be created by
new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER)
as I pointed out at a certain place.
TubeSock's WebSocket implementation does not even verify Sec-WebSocket-Accept
header although the verification is required by RFC 6455. See RFC 6455, 4.1. Client Requirements for details.
If you are using the previous version of firebase then update your library version of firebase.
In my case i was using the the firebase analytics
compile 'com.google.android.gms:play-services-analytics:9.8.0'
Then I updated that with
compile 'com.google.android.gms:play-services-analytics:10.2.4'
Everything is now working fine in my case.still if you have problem let me know.
if my answer will help you then don't forgot to increase my answer vote.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With