From bc816f1dace6f355d701b2b575c27c2f582215f6 Mon Sep 17 00:00:00 2001 From: Sietse Ringers Date: Tue, 10 Aug 2021 09:24:17 +0200 Subject: [PATCH] fix: don't attempt to read empty string when parsing CM response --- .../privacybydesign/sms/smssender/CMGatewaySender.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/foundation/privacybydesign/sms/smssender/CMGatewaySender.java b/src/main/java/foundation/privacybydesign/sms/smssender/CMGatewaySender.java index 1d048bc..4360cff 100644 --- a/src/main/java/foundation/privacybydesign/sms/smssender/CMGatewaySender.java +++ b/src/main/java/foundation/privacybydesign/sms/smssender/CMGatewaySender.java @@ -62,8 +62,8 @@ protected void sendMessage(String phone, String message) throws IOException { InputStream responseBody = connection.getInputStream(); String text; - try (Scanner scanner = new Scanner(responseBody, StandardCharsets.UTF_8.name())) { - text = scanner.useDelimiter("\\A").next(); + try (Scanner scanner = new Scanner(responseBody, StandardCharsets.UTF_8.name()).useDelimiter("\\A")) { + text = scanner.hasNext() ? scanner.next() : ""; } // CM returns empty string when the SMS is successfully sent