Skip to content

Fix document picker null name crash#34

Merged
marcprux merged 3 commits into
skiptools:mainfrom
FourFourSoftware:fix-document-picker-null-name
Jun 11, 2026
Merged

Fix document picker null name crash#34
marcprux merged 3 commits into
skiptools:mainfrom
FourFourSoftware:fix-document-picker-null-name

Conversation

@Davedeji

@Davedeji Davedeji commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Thank you for contributing to the Skip project! Please use this space to describe your change and add any labels (bug, enhancement, documentation, etc.) to help categorize your contribution.

Please review the contribution guide at https://skip.dev/docs/contributing/ for advice and guidance on making high-quality PRs.

Skip Pull Request Checklist:

  • REQUIRED: I have signed the Contributor Agreement
  • REQUIRED: I have tested my change locally with swift test
  • OPTIONAL: I have tested my change on an iOS simulator or device
  • OPTIONAL: I have tested my change on an Android emulator or device

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.

Davedeji added 3 commits June 9, 2026 18:28
…nent

Some content providers (notably Downloads) omit DISPLAY_NAME, which made
`getColumnIndexOrThrow` throw and `selectedFilename.wrappedValue!` NPE.
Separately, building the destination via `URL.appendingPathComponent` hit
a NullPointerException inside skip.foundation.URL._appendingPathComponent
on inputs containing encoded whitespace.

- Use getColumnIndex (not …OrThrow) and tolerate -1 / null.
- Fall back to a UUID-derived filename when DISPLAY_NAME is null.
- Fall back to ContentResolver.getType for missing mime.
- Build the cache destination with java.io.File(cacheDir, safeName)
  to avoid Skip's URL helper entirely.
- Replace `resolver.openInputStream(uri)!` force-unwrap with a guard.
URL(fileURLWithPath:) feeds the raw path to java.net.URI, which rejects
unencoded spaces / parens. Picked files frequently have such characters
in DISPLAY_NAME ("African American Praise medley (Henrisoul).mp3"), so
the post-copy URL construction crashed with URISyntaxException at
"Illegal character in path at index N".

java.io.File.toURI() percent-encodes the path, so wrapping its result
with URL(platformValue:) gives a valid file URL on every input.
@marcprux

Copy link
Copy Markdown
Member

This looks good! Can you explain the circumstances around the crash that you were experiencing?

@Davedeji

Davedeji commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

This looks good! Can you explain the circumstances around the crash that you were experiencing?

Yeah, forgot to make a screen recording. pretty much my app allows users to upload audio files, while running on android I tried to upload files from the downloads folder and as soon as the file was selected the app would crash.
Crash Logs below similar to the original filed issue:

FATAL EXCEPTION: main
Process: com.livetrackz.android, PID: 6981
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1340283470, result=-1, data=Intent { dat=content://com.android.providers.downloads.documents/... flg=0x43 }} to activity {com.livetrackz.android/live.trackz.MainActivity}: java.lang.NullPointerException
	at android.app.ActivityThread.deliverResults(ActivityThread.java:5527)
	at android.app.ActivityThread.handleSendResult(ActivityThread.java:5566)
	at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:205)
	at android.os.Looper.loop(Looper.java:294)
	at android.app.ActivityThread.main(ActivityThread.java:8177)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Caused by: java.lang.NullPointerException
	at skip.foundation.URL._appendingPathComponent(URL.kt:322)
	at skip.foundation.URL.appendingPathComponent(URL.kt:325)
	at skip.kit.DocumentPickerKt.withDocumentPicker$lambda$0$0$0(DocumentPicker.kt:70)
	at skip.kit.DocumentPickerKt.$r8$lambda$Vm3zC9ewPCRJx8qmmgJErRWE_Rw(Unknown Source:0)
	at skip.kit.DocumentPickerKt$$ExternalSyntheticLambda2.invoke(D8$$SyntheticClass:0)
	at androidx.activity.compose.ActivityResultRegistryKt.rememberLauncherForActivityResult$lambda$4$0$0(ActivityResultRegistry.kt:104)
	at androidx.activity.compose.ActivityResultRegistryKt.$r8$lambda$3CvmGOvkwZLY6ksF4ULs20ma2UE(Unknown Source:0)
	at androidx.activity.compose.ActivityResultRegistryKt$$ExternalSyntheticLambda2.onActivityResult(D8$$SyntheticClass:0)
	at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.kt:350)
	at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.kt:311)
	at androidx.activity.ComponentActivity.onActivityResult(ComponentActivity.kt:788)
	at androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:152)
	at android.app.Activity.dispatchActivityResult(Activity.java:8943)
	at android.app.ActivityThread.deliverResults(ActivityThread.java:5520)
	at android.app.ActivityThread.handleSendResult(ActivityThread.java:5566) 
	at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67) 
	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45) 
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139) 
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96) 
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443) 
	at android.os.Handler.dispatchMessage(Handler.java:106) 
	at android.os.Looper.loopOnce(Looper.java:205) 
	at android.os.Looper.loop(Looper.java:294) 
	at android.app.ActivityThread.main(ActivityThread.java:8177) 
	at java.lang.reflect.Method.invoke(Native Method) 
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) 
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) 

@marcprux

Copy link
Copy Markdown
Member

Fixes #31

@marcprux marcprux merged commit b170bf7 into skiptools:main Jun 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants