From df065283fdebc7a228471a9120be8f3794148483 Mon Sep 17 00:00:00 2001 From: Frank Liu Date: Tue, 20 Jun 2023 14:33:56 -0700 Subject: [PATCH] [api] Avoid exception if SecurityManager is applied (#2665) --- api/src/main/java/ai/djl/util/Ec2Utils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/ai/djl/util/Ec2Utils.java b/api/src/main/java/ai/djl/util/Ec2Utils.java index c42e6f85d97..178c3d7efe7 100644 --- a/api/src/main/java/ai/djl/util/Ec2Utils.java +++ b/api/src/main/java/ai/djl/util/Ec2Utils.java @@ -51,7 +51,12 @@ private Ec2Utils() {} * @return true if the current environment is SageMaker */ public static boolean isSageMaker() { - return Files.exists(Paths.get(ENDPOINT_METADATA_FILE)); + try { + return Files.exists(Paths.get(ENDPOINT_METADATA_FILE)); + } catch (SecurityException e) { + logger.warn("Security manager doesn't allow access file"); + return false; + } } /**