Skip to content

fix(clipboard): avoid NullPointerException in read() on Android when the clip or its description is null - #2612

Open
qliqdev wants to merge 1 commit into
ionic-team:mainfrom
qliqdev:fix/clipboard-android-null-clip
Open

qliqdev wants to merge 1 commit into
ionic-team:mainfrom
qliqdev:fix/clipboard-android-null-clip

Conversation

@qliqdev

@qliqdev qliqdev commented Oct 16, 2026 •

Copy link
Copy Markdown

Description

On Android, Clipboard.read() can crash the whole app:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.ClipDescription.hasMimeType(java.lang.String)' on a null object reference
    at com.capacitorjs.plugins.clipboard.Clipboard.read (Clipboard.java:56)
    at com.capacitorjs.plugins.clipboard.ClipboardPlugin.read (ClipboardPlugin.java:48)
    ...
    at com.getcapacitor.Bridge.lambda$callPluginMethod$0 (Bridge.java:856)

hasPrimaryClip() can return true while getPrimaryClipDescription() / getPrimaryClip() still return null (for example right after launch, before the activity has window focus, when Android 10+ restricts clipboard access). The exception is thrown on the plugin thread, so it cannot be caught from JS and the app is killed. In production we saw it on 14 of 29 Android users of one app (Android 11, OnePlus 8 Pro among others), with @capacitor/clipboard 8.0.1.

The fix reads the primary clip once and checks the clip, its item count and its description before using them. When nothing can be read, read() rejects with the existing "There is no data on the clipboard" error instead of crashing.

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation

Platforms Affected

  • Android
  • iOS
  • Web

Tests or Reproductions

./gradlew build test in clipboard/android and prettier --check pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant