amitshekhariitbhu/Android-Debug-Database · error · NullPointerException

DebugDBInitProvider ProviderInfo cannot be null.

Error message

DebugDBInitProvider ProviderInfo cannot be null.

What it means

DebugDBInitProvider.attachInfo (debug-db module) throws NullPointerException when the Android framework supplies a null ProviderInfo during provider registration. DebugDB needs the resolved ProviderInfo (authority) to finish its initialization hook, so a null value is treated as a broken registration and fails immediately. This mirrors the guard in the encrypt variant of the library.

Solutions

  1. Check the merged manifest (app/build/intermediates/merged_manifests) contains com.amitshekhar.debug.DebugDBInitProvider with a valid android:authorities.
  2. Remove tools:node="remove" overrides or manifest filters that strip the library provider.
  3. If instantiating in tests, pass a real ProviderInfo: ProviderInfo info = new ProviderInfo(); info.authority = "test.authority"; provider.attachInfo(context, info);
  4. Declare the provider yourself with android:authorities="${applicationId}.DebugDBInitProvider" if you must override it.
  5. Clean and rebuild to eliminate stale manifest merger artifacts.

Example fix

// before (test code)
DebugDBInitProvider provider = new DebugDBInitProvider();
provider.attachInfo(context, null);

// after
ProviderInfo info = new ProviderInfo();
info.authority = "com.example.myapp.DebugDBInitProvider";
DebugDBInitProvider provider = new DebugDBInitProvider();
provider.attachInfo(context, info);
Defensive patterns

Strategy: validation

Validate before calling

// Verify the provider registration before touching DebugDB APIs
PackageManager pm = context.getPackageManager();
ProviderInfo info = pm.getProviderInfo(new ComponentName(context, "com.amitshekhar.debug.DebugDBInitProvider"), 0);
if (info == null || info.authority == null) {
    throw new IllegalStateException("DebugDBInitProvider is not properly merged into the manifest");
}

Type guard

boolean hasValidProviderInfo(ProviderInfo info) {
    return info != null && info.authority != null && !info.authority.isEmpty();
}

Try / catch

try {
    DebugDBInitialize.init(this);
} catch (NullPointerException | IllegalStateException e) {
    Log.e("DebugDB", "Init provider failed: " + e.getMessage());
}

Prevention

When it happens

Trigger: attachInfo(Context, ProviderInfo) is invoked with providerInfo == null (line 76 check) — e.g., the provider is instantiated manually in a test, or the merged manifest's provider entry for com.amitshekhar.debug.DebugDBInitProvider is missing/corrupted so the framework hands over no valid ProviderInfo.

Common situations: Unit tests calling new DebugDBInitProvider().attachInfo(context, null); manifest merger conflicts removing the library provider; app manifest overriding the provider without authorities; build variants excluding the debug-db manifest.

Related errors


AI-assisted analysis of amitshekhariitbhu/Android-Debug-Database@bf149df61f (2026-09-12). Data as JSON: /api/errors/ddb8e4cdd0f26f19. Report an issue: GitHub.

Appendix: source

Thrown at debug-db/src/main/java/com/amitshekhar/debug/DebugDBInitProvider.java:76

    @Override
    public Uri insert(Uri uri, ContentValues values) {
        return null;
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        return 0;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        return 0;
    }

    @Override
    public void attachInfo(Context context, ProviderInfo providerInfo) {
        if (providerInfo == null) {
            throw new NullPointerException("DebugDBInitProvider ProviderInfo cannot be null.");
        }
        // So if the authorities equal the library internal ones, the developer forgot to set his applicationId
        if ("com.amitshekhar.debug.DebugDBInitProvider".equals(providerInfo.authority)) {
            throw new IllegalStateException("Incorrect provider authority in manifest. Most likely due to a "
                    + "missing applicationId variable in application\'s build.gradle.");
        }
        super.attachInfo(context, providerInfo);
    }

}

View on GitHub (pinned to bf149df61f)