-
Notifications
You must be signed in to change notification settings - Fork 42
Description
I’m encountering a crash in the Ably Java/Android SDK related to HttpHelpers.getUrlString.
Issue
When getUrlString calls new String(getUrl(...)), if getUrl returns null (e.g. empty response, network error), this results in:
Fatal Exception: java.lang.NullPointerException
Attempt to get length of null array
at java.lang.StringFactory.newStringFromBytes(StringFactory.java:46)
at io.ably.lib.http.HttpHelpers.getUrlString(HttpHelpers.java:45)
Stack trace
io.ably.lib.http.HttpHelpers.getUrlString(HttpHelpers.java:45)
io.ably.lib.transport.ConnectionManager.checkConnectivity
io.ably.lib.transport.ConnectionManager.checkFallback
io.ably.lib.transport.ConnectionManager.onTransportUnavailable
io.ably.lib.transport.WebSocketTransport$WsClient.onError
org.java_websocket.client.WebSocketClient.onWebsocketError
...
Analysis
getUrlString doesn’t check for null before passing the byte array to new String(...).
This can happen if HttpCore.Response.body is null.
We observed this during network failures or fallback host issues.
Suggested fix
In getUrlString, add a check:
public static String getUrlString(HttpCore httpCore, String url) throws AblyException {
byte[] bytes = getUrl(httpCore, url);
if (bytes == null) {
throw AblyException.fromErrorInfo(new ErrorInfo("Empty response body", 50000, 500));
}
return new String(bytes);
}
or similar logic.