skiptools / skiptools/skip-ui

NullPointerException: null cannot be cast to non-null type skip.ui.PreferenceKeyCompanion<Value of skip.ui.Preference>

Open
#310 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
330
Forks
76
Avg merge
3h 6m
Merged PRs (30d)
1

Description

We have updated Skip packages in a recent release (Skip 1.6.36, Skip UI 1.46.0) and are beginning to see this issue crash some apps on startup.

It seems to be happening surrounding the storage of our colorScheme, which is declared in our main RootView:

public struct RootView : View {    
    @AppStorage(Theme.storageKey) private var theme: String = Theme.SYSTEM.rawValue
    var preferredColorScheme: ColorScheme? {
        switch theme {
        case Theme.DARK.rawValue:
            return .dark
        case Theme.LIGHT.rawValue:
            return .light
        default:
            // nil allows for user's system setting default colour scheme to prevail
            return nil
        }
    }

Digging a bit deeper in our stacktrace shows it may also be coming from Skips templated Main.kt file:

@Composable
internal fun PresentationRootView(context: ComposeContext) {
    val colorScheme = if (isSystemInDarkTheme()) ColorScheme.dark else ColorScheme.light
    PresentationRoot(defaultColorScheme = colorScheme, context = context) { ctx ->
        val contentContext = ctx.content()
        Box(modifier = ctx.modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
            RootView().Compose(context = contentContext)
        }
    }
}

What is confusing me a bit is that we are providing default values for all @AppStorage variables throughout the app.

I did notice this somewhat similar issue, which seems to indicate that preference keys should not be declared private, which we have done.

https://github.com/skiptools/skip-ui/issues/243

Is this as simple as now needing to declare @AppStorage vars as the default public? Anything else at play? Thank you. -Gavyn

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the startup stacktrace and compare RootView's private @AppStorage declaration with the templated Main.kt PresentationRootView entry point. Review the related skip-ui issue 243 for context on preference key visibility. Done means the crash trigger is isolated and a regression check confirms startup no longer raises the reported NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin, swift
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.