Skip to content
Skills Library
Programming · Building & coding

null-handling

/null-handling

Make absence explicit in the type and resolve it at the edges so the interior never dereferences a surprise null. Use when designing return types, parsing external input, or chasing null-reference crashes.

Repository
AI-SKILLS ↗
Licence
MIT
Last repository change
05.09.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 05.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Make absence explicit in the type and resolve it at the edges so the interior never dereferences a surprise null. Use when designing return types, parsing external input, or chasing null-reference crashes.

Original author description

Make absence explicit in the type and resolve it at the edges so the interior never dereferences a surprise null. Use when designing return types, parsing external input, or chasing null-reference crashes.

How it works

  1. Method
  2. Signals
  3. Boundaries
Original SKILL.md headings · 52 lines, 412 words
SKILL.md preview
---
name: null-handling
description: Make absence explicit in the type and resolve it at the edges so the interior never dereferences a surprise null. Use when designing return types, parsing external input, or chasing null-reference crashes.
---

# Null handling

A null that reaches code expecting a value is the most common runtime crash
there is, and the stack trace points at the dereference, not the place the
null was born. The fix is to make absence explicit in the type and to
convert or reject nulls at the edges, so interior code never has to ask.

## Method

1. **Make absence a type, not a value.** Use `Optional<T>`, `T | null`
   under strict null checks, Rust's `Option`, Kotlin's `T?`, or Swift
   optionals, and turn on enforcement: TypeScript `strictNullChecks`,
   Kotlin null safety, mypy strict. The type now forces every caller to
   handle the empty case.
2. **Convert at the boundary, once.** Parse external input (JSON, DB rows,
   env vars) into a type where every field is present or explicitly
   optional. After that line, interior code never re-checks, because the
   boundary already decided.
3. **Use a null object where a neutral default is correct.** An empty
   collection, a `NullLogger`, a `Guest` user with no permissions: callers
   run the same path with no branch. Reserve this for cases where doing
   nothing is right, not where absence is a genuine error.
4. **Return empty collections, never null collections.** `return []`, not
   `return null`, from anything that yields a list, so callers iterate
   without guarding. A null list is a guard every caller must remember, and
   one eventually will not.
5. **Unwrap deliberately.** Thread through absence with `?.` and `??` (or
   `map`, `getOrElse`, `if let`); reserve force-unwrap (`!`, `.unwrap()`,
   `.get()`) for cases you have already proven non-null, and leave the
   comment with the proof.
6. **Distinguish normal absence from error absence.** `findUser` returning
   empty is routine; a required config key being absent is an error that
   deserves a thrown exception naming the key, not a silent `None` that
   surfaces three layers away.

## Signals

- Does the type of every field and return state whether null is possible?
- Is there a single place where external data becomes null-safe, or are the
  checks scattered through the interior?
- Does any public method return null where an empty list or a null object
  would let callers drop a branch?

## Boundaries

Languages without a real optional type (older Java, C) lean on annotations
(`@Nullable`, `@NonNull`) with tools like the Checker Framework or Infer;
the discipline holds even when the compiler is weaker. Database columns
that are genuinely nullable stay nullable: model the real domain, do not
paper a required field over an optional one.

Versions

The database has no other skills named null-handling.

Database snapshot: 13.11.2026 · package version 3336439339c1 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 95csharp-nullable-types
    Use when C# nullable reference types and value types for null safety, nullable annotations, and patterns for handling null values.
  • 100optional
    Use when implementing the Optional/Maybe pattern in C# to eliminate null reference exceptions and make value absence explicit in the type system. USE FOR: Optional<T> type implementation, null elimination patterns, monadic optional chaining, safe value access patterns, API…
  • 91csharp-nullable-types
    Use when C# nullable reference types, null safety patterns, and migration strategies. Use when ensuring null safety in C# code.
  • 86analyze-contribution-null-safety
    Null safety guidelines for analyze-contribution's calculations. ONLY use this skill when explicitly asked to do so.
  • 95yapyak-app
    App-code TypeScript: inferred return types, domain `null` vs UI `undefined` at the dispatcher, `window.*` timers. Use when writing app code under `docs/`.
  • 100dart-null-safety
    Sound null safety in Dart — nullable vs non-nullable types, flow analysis and type promotion, why fields don't promote (and the private-final exception), the ! operator, late and late final, ??, ??=, ?., ?.., null-aware elements (?item in collections), required named parameters,…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.