From a8d9e4c37b2aa7b10170b1d5c1865d71f795bdbf Mon Sep 17 00:00:00 2001 From: Cliff Chung <116232729+cliffamzn@users.noreply.github.com> Date: Wed, 26 Oct 2022 14:08:30 -0700 Subject: [PATCH] Catch UnsatisfiedLinkError when load native library (#23286) When the native library cannot be loaded, catch the exception so that the logs can be parsed later on. This makes this issue a bit easier to debug. --- .../src/chip/setuppayload/SetupPayloadParser.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/setup_payload/java/src/chip/setuppayload/SetupPayloadParser.java b/src/setup_payload/java/src/chip/setuppayload/SetupPayloadParser.java index 89601ac18a3cdc..1f035253c27d4a 100644 --- a/src/setup_payload/java/src/chip/setuppayload/SetupPayloadParser.java +++ b/src/setup_payload/java/src/chip/setuppayload/SetupPayloadParser.java @@ -1,8 +1,13 @@ package chip.setuppayload; +import java.util.logging.Level; +import java.util.logging.Logger; + /** Parser for scanned QR code or manual entry code. */ public class SetupPayloadParser { + private static final Logger LOGGER = Logger.getLogger(SetupPayloadParser.class.getSimpleName()); + /** * Returns {@link SetupPayload} parsed from the QR code string. If an invalid element is included * in the QRCode Parse result, SetupPayloadException occurs. Refer to {@link SetupPayload} for the @@ -69,7 +74,11 @@ private native SetupPayload fetchPayloadFromManualEntryCode( throws InvalidEntryCodeFormatException, SetupPayloadException; static { - System.loadLibrary("SetupPayloadParser"); + try { + System.loadLibrary("SetupPayloadParser"); + } catch (UnsatisfiedLinkError e) { + LOGGER.log(Level.SEVERE, "Cannot load library.", e); + } } public static class UnrecognizedQrCodeException extends Exception {