Skip to content

NullPointerException in loadArtBitmap when artUri is null #1152

@danielgomezrico

Description

@danielgomezrico

Bug report

Describe the bug

When creating a MediaItem with artUri: null, the app crashes with a NullPointerException in AudioService.loadArtBitmap(). The crash occurs because LruCache.put() does not accept null values.

Steps to reproduce

  1. Create a MediaItem with artUri set to null:
MediaItem(
  id: 'some-id',
  title: 'Title',
  artist: 'Artist',
  artUri: null,  // <-- This causes the crash
);
  1. Play the media item
  2. App crashes

Stack trace

java.lang.NullPointerException: key == null || value == null
	at android.util.LruCache.put(LruCache.java:169)
	at com.ryanheise.audioservice.AudioService.loadArtBitmap(AudioService.java:242)
	at com.ryanheise.audioservice.AudioService.setMetadata(AudioService.java:790)
	at com.ryanheise.audioservice.AudioServicePlugin$AudioHandlerInterface.lambda$onMethodCall$2$com-ryanheise-audioservice-AudioServicePlugin$AudioHandlerInterface(AudioServicePlugin.java:842)
	at com.ryanheise.audioservice.AudioServicePlugin$AudioHandlerInterface$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
	at java.lang.Thread.run(Thread.java:1012)

Expected behavior

The library should gracefully handle null artUri without crashing. Media items without artwork are a valid use case.

Suggested fix

In AudioService.java, add a null check before caching the bitmap:

Bitmap bitmap = loadArtBitmap(artUri);
if (bitmap != null && artUri != null) {
    artBitmapCache.put(artUri, bitmap);
}

Environment

  • audio_service version: latest
  • Platform: Android

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