Firebase crash due to null pointer exception

Firebase null pointer exception. Attached stacktrace 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+) from May 3, 2016

Device Details: LGE - lgls770 running Android 6.0 and non-root

+7
android nullpointerexception websocket firebase
source share
2 answers

The code snippet below is an implementation of the 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 the Upgrade HTTP header in the response for opening a handshake (RFC 6455, 4. Opening a handshake ), this code raises a NullPointerException .

In addition, since the headers instance specified by this method creates a new HashMap<String, String>() ( WebSocket.java :360 ), the HTTP headers sent from the server must be case sensitive , although the HTTP specification says: "Field names case insensitive " (RFC 2616, 4.2 Message Headers ). Therefore, for example, if the server sends the Upgrade HTTP header in all uppercase letters such as UPGRADE , TubeSock throws a NullPointerException , although the server behavior is correct.

headers instance must be created

 new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER) 

as I indicated in a specific place.

The TubeSock WebSocket implementation does not even check the Sec-WebSocket-Accept header, although verification is required by RFC 6455. See RFC 6455, 4.1. Customer requirements .

+3
source share

If you are using a previous version of firebase, then upgrade your version of firebase for your library.

In my case, I used firebase analytics

 compile 'com.google.android.gms:play-services-analytics:9.8.0' 

Then I updated this with

 compile 'com.google.android.gms:play-services-analytics:10.2.4' 

Now everything works fine in my case. If you have a problem let me know.

if my answer helps you, then do not forget to increase the vote.

+3
source share

All Articles