From 02bc8a979c192707efc5d6e1f424812e36f6369f Mon Sep 17 00:00:00 2001 From: Amir Hossein Shekari Date: Tue, 30 Jan 2024 13:22:42 +0330 Subject: [PATCH] fix: Fix `NullPointerException` in `initFrameProcessorPlugin` if plugin is not found (#2454) * fix: fix the null exception * Add `Nullable` and `NonNull` annotations --------- Co-authored-by: Marc Rousavy --- .../camera/frameprocessor/FrameProcessorPluginRegistry.java | 4 ++-- .../com/mrousavy/camera/frameprocessor/VisionCameraProxy.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package/android/src/main/java/com/mrousavy/camera/frameprocessor/FrameProcessorPluginRegistry.java b/package/android/src/main/java/com/mrousavy/camera/frameprocessor/FrameProcessorPluginRegistry.java index 84f6966c14..1448ed264c 100644 --- a/package/android/src/main/java/com/mrousavy/camera/frameprocessor/FrameProcessorPluginRegistry.java +++ b/package/android/src/main/java/com/mrousavy/camera/frameprocessor/FrameProcessorPluginRegistry.java @@ -36,7 +36,7 @@ public static void addFrameProcessorPlugin(String name, PluginInitializer plugin @DoNotStrip @Keep - public static FrameProcessorPlugin getPlugin(String name, VisionCameraProxy proxy, Map options) { + public static @Nullable FrameProcessorPlugin getPlugin(String name, VisionCameraProxy proxy, Map options) { Log.i(TAG, "Looking up Frame Processor Plugin \"" + name + "\"..."); PluginInitializer initializer = Plugins.get(name); if (initializer == null) { @@ -48,6 +48,6 @@ public static FrameProcessorPlugin getPlugin(String name, VisionCameraProxy prox } public interface PluginInitializer { - FrameProcessorPlugin initializePlugin(@NonNull VisionCameraProxy proxy, @Nullable Map options); + @NonNull FrameProcessorPlugin initializePlugin(@NonNull VisionCameraProxy proxy, @Nullable Map options); } } diff --git a/package/android/src/main/java/com/mrousavy/camera/frameprocessor/VisionCameraProxy.kt b/package/android/src/main/java/com/mrousavy/camera/frameprocessor/VisionCameraProxy.kt index 8189963c3b..928198f12c 100644 --- a/package/android/src/main/java/com/mrousavy/camera/frameprocessor/VisionCameraProxy.kt +++ b/package/android/src/main/java/com/mrousavy/camera/frameprocessor/VisionCameraProxy.kt @@ -71,7 +71,7 @@ class VisionCameraProxy(context: ReactApplicationContext) { @DoNotStrip @Keep - fun initFrameProcessorPlugin(name: String, options: Map): FrameProcessorPlugin = + fun initFrameProcessorPlugin(name: String, options: Map): FrameProcessorPlugin? = FrameProcessorPluginRegistry.getPlugin(name, this, options) // private C++ funcs