From 47c85011ded213eeb896d53e294d90bf3730f0d7 Mon Sep 17 00:00:00 2001 From: Mino260806 Date: Thu, 21 Jul 2022 19:35:50 +0100 Subject: [PATCH] Fix Paper.init when Context is not needed --- paperdb/src/main/java/io/paperdb/Paper.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/paperdb/src/main/java/io/paperdb/Paper.java b/paperdb/src/main/java/io/paperdb/Paper.java index 3edc427..d04adf1 100644 --- a/paperdb/src/main/java/io/paperdb/Paper.java +++ b/paperdb/src/main/java/io/paperdb/Paper.java @@ -50,6 +50,17 @@ public static void init(@NonNull Context context) { mContext = context.getApplicationContext(); } + /** + * Alternative to {@link #init(Context)} when {@link #book()} method is not needed. + * + *

+ * Do not use this constructor unless you are explicitely specifying location by using {@link #bookOn(String)} + * or {@link #bookOn(String, String)}. + * + */ + public static void init() { + } + /** * Returns book instance with the given name * @@ -94,8 +105,9 @@ public static void init(@NonNull Context context) { } private static Book getBook(String location, String name) { - if (mContext == null) { - throw new PaperDbException("Paper.init is not called"); + if (location == null && mContext == null) { + throw new PaperDbException("Paper.init(Context) is not called. If you are calling Paper.init(), " + + "please call Paper.init(Context) instead."); } String key = (location == null ? "" : location) + name; synchronized (mBookMap) {