j256 / ormlite-android

ORMLite Android functionality used in conjunction with ormlite-core
http://ormlite.com/
ISC License
1.59k stars 367 forks source link

Null variable AndroidLogBackend causes "Could not construct instance of helper class" #127

Closed sanderderks closed 3 years ago

sanderderks commented 3 years ago
    private final String className;

    // we do this because supposedly Log.isLoggable() always does IO
    private volatile int levelCacheC = 0;
    private final boolean levelCache[];

    public AndroidLogBackend(String className) {
        // get the last part of the class name
        String simpleName = LoggerFactory.getSimpleClassName(className);
        // make sure that our tag length is not too long
        int length = simpleName.length();
        if (length > MAX_TAG_LENGTH) {
*****           simpleName = this.className.substring(length - MAX_TAG_LENGTH, length);
        }
        this.className = simpleName;
        // find the maximum level value
        int maxLevel = 0;
        for (Level level : Level.values()) {
            int androidLevel = levelToAndroidLevel(level);
            if (androidLevel > maxLevel) {
                maxLevel = androidLevel;
            }
        }
        levelCache = new boolean[maxLevel + 1];
        refreshLevelCache();
    }

Above this.className in com.j256.ormlite.android.AndroidLogBackend line 60 is always null and causes a NullPointerException. Because of this, I cannot instantiate a DatabaseHelper! I'm running ormlite-android v5.4 and ormlite-core v5.4.

https://github.com/j256/ormlite-android/blob/59c1b237df2ae1819db915f9a2525b182816ed7a/src/main/java/com/j256/ormlite/android/AndroidLogBackend.java#L60

j256 commented 3 years ago

Fixed by #128

j256 commented 3 years ago

This was pushed out in version 5.5 @sanderderks . Thanks again.