Skip to content

mContext is useless when location is explicit in getBook() #200

@Mino260806

Description

@Mino260806

the current Paper.init(Context) forces you to provide a context. However there's a case where mContext in Paper is not used at all: when location is explicit in getBook().

private static Book getBook(String location, String name) {
        if (mContext == null) {
            throw new PaperDbException("Paper.init is not called");
        }
        String key = (location == null ? "" : location) + name;
        synchronized (mBookMap) {
            Book book = mBookMap.get(key);
            if (book == null) {
                if (location == null) {
                    book = new Book(mContext, name, mCustomSerializers);
                } else {
                    // In this case, mContext is not used, so operation will succeed even if mContext == null
                    book = new Book(location, name, mCustomSerializers); 
                }
                mBookMap.put(key, book);
            }
            return book;
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions