From fe134a417262a770d524ca41f749661fe2ab2eb3 Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Sat, 25 Jan 2020 15:41:13 +0100 Subject: [PATCH] Auto logout on Garbage Collection --- src/main/java/ley/untis/UntisClient.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/ley/untis/UntisClient.java b/src/main/java/ley/untis/UntisClient.java index 9232b66..5dd3e3a 100644 --- a/src/main/java/ley/untis/UntisClient.java +++ b/src/main/java/ley/untis/UntisClient.java @@ -78,11 +78,19 @@ public class UntisClient { public void logout() throws APIRequestException { try { client.invoke("logout", new Object[0], Object.class); + auth = null; } catch (Throwable e) { throw new APIRequestException(e); } } + @Override + protected void finalize() throws Throwable { + if (auth != null) { + logout(); + } + } + /** * Get list of subjects * @return an ArrayList of subjects