From 88cf0d3cad8b8f2abd641f029c0b37ce74c86ded Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Tue, 8 Dec 2020 12:10:46 +0700 Subject: [PATCH] Bug fix: crash when validating account --- .../kdt/mojangauth/yggdrasil/YggdrasilAuthenticator.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/kdt/mojangauth/yggdrasil/YggdrasilAuthenticator.java b/app/src/main/java/com/kdt/mojangauth/yggdrasil/YggdrasilAuthenticator.java index 8695d321e..49a9138f2 100644 --- a/app/src/main/java/com/kdt/mojangauth/yggdrasil/YggdrasilAuthenticator.java +++ b/app/src/main/java/com/kdt/mojangauth/yggdrasil/YggdrasilAuthenticator.java @@ -34,20 +34,23 @@ public class YggdrasilAuthenticator { if (os != null) { os.close(); } + int statusCode = conn.getResponseCode(); if (statusCode != 200) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } - IOUtils.copy(is, bos); + if (is != null) { + IOUtils.copy(is, bos); try { is.close(); } catch (Exception e) { throw e; } } + String outString = new String(bos.toByteArray(), Charset.forName("UTF-8")); if (statusCode == 200 || statusCode == 204){ Log.i("Result", "Task " + endpoint + " successful"); @@ -58,6 +61,7 @@ public class YggdrasilAuthenticator { } else { Log.i("Result", "Task " + endpoint + " failure"); } + if (responseClass == null) { return new NetworkResponse(statusCode, outString); }