[英]Firebase crash due to null pointer exception
Firebase null pointer exception. Firebase空指针异常。 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 版本:2016年3月3日最新(2.5.2 +)
Device Details : LGE - lgls770 running android 6.0 and Non-Rooted 设备详细信息:LGE - 运行android 6.0和非Root的lgls770
The code snippet below is the implementation of verifyServerhandshakeHeaders
method found in WebSocketHandshake.java
. 下面的代码片段是WebSocketHandshake.java
的verifyServerhandshakeHeaders
方法的实现。
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
. 如您所见,如果服务器在打开握手的响应中没有包含Upgrade HTTP标头(RFC 6455,4。 打开握手 ),则此代码将抛出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 ). 此外,因为为此方法提供的headers
实例是由new HashMap<String, String>()
( WebSocket.java :360
)创建的,所以从服务器发送的HTTP头必须区分大小写,尽管HTTP规范说“字段名称” 不区分大小写“ (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. 因此,例如,如果服务器以UPGRADE
等全部大写字母发送Upgrade HTTP标头,则尽管服务器的行为正确,但TubeSock仍会抛出NullPointerException
。
headers
instance should be created by headers
实例应该由。创建
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. 虽然RFC 6455要求验证,但TubeSock的WebSocket实现甚至不验证Sec-WebSocket-Accept
标头。请参阅RFC 6455,4.1 。 Client Requirements for details. 客户要求详情。
If you are using the previous version of firebase then update your library version of firebase. 如果您使用的是以前版本的firebase,请更新您的库版本的firebase。
In my case i was using the the firebase analytics 就我而言,我使用的是firebase分析
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. 如果我的回答会帮助你,那么不要忘记增加我的答案投票。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.