From 29bf91ee2675c2fc550a7fb8f41e8ed7a970a17a Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Wed, 24 May 2023 10:56:36 +0200 Subject: [PATCH] Fix #157 --- .../java/it/tdlight/util/NativeLibraryLoader.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tdlight-java/src/main/java/it/tdlight/util/NativeLibraryLoader.java b/tdlight-java/src/main/java/it/tdlight/util/NativeLibraryLoader.java index 995614d..3aa3f30 100644 --- a/tdlight-java/src/main/java/it/tdlight/util/NativeLibraryLoader.java +++ b/tdlight-java/src/main/java/it/tdlight/util/NativeLibraryLoader.java @@ -28,6 +28,7 @@ import java.io.OutputStream; import java.lang.reflect.Method; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.nio.file.FileSystemException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -263,20 +264,16 @@ public final class NativeLibraryLoader { // After we load the library it is safe to delete the file. // We delete the file immediately to free up resources as soon as possible, // and if this fails fallback to deleting on JVM exit. - try { - if (tmpFile != null && (!DELETE_NATIVE_LIB_AFTER_LOADING || !deleteIfExists(tmpFile))) { - tmpFile.toFile().deleteOnExit(); - } - } catch (IOException e) { - throw new RuntimeException(e); + if (tmpFile != null && (!DELETE_NATIVE_LIB_AFTER_LOADING || !deleteIfExists(tmpFile))) { + tmpFile.toFile().deleteOnExit(); } } } - private static boolean deleteIfExists(Path tmpFile) throws IOException { + private static boolean deleteIfExists(Path tmpFile) { try { return Files.deleteIfExists(tmpFile); - } catch (AccessDeniedException ex) { + } catch (IOException ex) { return false; } }