Skip to content

Commit 746e237

Browse files
committed
another crash due to server URL not yet configured
1 parent d1604c3 commit 746e237

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tinodesdk/src/main/java/co/tinode/tinodesdk/Tinode.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,16 +583,24 @@ public void networkProbe() {
583583
* @return Server URL.
584584
* @throws MalformedURLException thrown if server address is not yet configured.
585585
*/
586-
public URL getBaseUrl() throws MalformedURLException {
587-
return new URL(getHttpOrigin() + "/v" + PROTOVERSION + "/");
586+
public @NotNull URL getBaseUrl() throws MalformedURLException {
587+
String base = getHttpOrigin();
588+
if (base == null) {
589+
throw new MalformedURLException("server URL not configured");
590+
}
591+
return new URL(base + "/v" + PROTOVERSION + "/");
588592
}
589593

590594
/**
591595
* Get server address suitable for use as an Origin: header for CORS compliance.
592596
*
593597
* @return server internet address
594598
*/
595-
public String getHttpOrigin() {
599+
public @Nullable String getHttpOrigin() {
600+
if (mServerURI == null) {
601+
return null;
602+
}
603+
596604
boolean tls = mServerURI.getScheme().equals("wss");
597605
try {
598606
return new URL(tls ? "https" : "http", mServerURI.getHost(), mServerURI.getPort(), "").toString();

0 commit comments

Comments
 (0)