Skip to content

Commit

Permalink
Catch UnsatisfiedLinkError when load native library (#23286)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cliffamzn authored Oct 26, 2022
1 parent e3ed287 commit f14e882
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f14e882

Please sign in to comment.