From a9bffd587807bd0c7cd3eb720ecee939fe34ae35 Mon Sep 17 00:00:00 2001 From: ne0fhyk Date: Mon, 16 Aug 2021 23:14:10 -0700 Subject: [PATCH] Fix possible null pointer exception. (cherry picked from commit e2bcdad43be4379383ab896fd6fa4f43e6b4f9d6) --- .../java/lib/src/org/godotengine/godot/GodotIO.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java index b25ad8e344a..37ccd257df2 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java @@ -43,6 +43,7 @@ import android.net.Uri; import android.os.Build; import android.os.Environment; import android.provider.Settings; +import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; import android.util.SparseArray; @@ -484,7 +485,11 @@ public class GodotIO { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { Log.w(TAG, "Shared storage access is limited on Android 10 and higher."); } - return Environment.getExternalStoragePublicDirectory(what).getAbsolutePath(); + if (TextUtils.isEmpty(what)) { + return Environment.getExternalStorageDirectory().getAbsolutePath(); + } else { + return Environment.getExternalStoragePublicDirectory(what).getAbsolutePath(); + } } else { return activity.getExternalFilesDir(what).getAbsolutePath(); }