java-null-safety

Enforce JSpecify null-safety contracts with @NullMarked, @Nullable, and @NonNull annotations.

4|Updated Jan 11, 2026
One-click install
npx skills add https://github.com/cuioss/plan-marshall --skill java-null-safety
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: java-null-safety
Source: https://github.com/cuioss/plan-marshall/tree/main/marketplace/bundles/pm-dev-java/skills/java-null-safety
Command: npx skills add https://github.com/cuioss/plan-marshall --skill java-null-safety

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The Java Null Safety Skill helps teams prevent null-related bugs by applying JSpecify annotations and package-level configuration to enforce a default non-null contract throughout codebases.

Core Features & Use Cases

  • Enforce non-null by default using @NullMarked at the package level.
  • Explicitly mark nullable types with @Nullable and non-null types with @NonNull.
  • Ensure safe return semantics and guide migration from legacy code to Optional where appropriate.
  • Use package-info.java conventions to maintain consistent null-safety across modules.
  • Use in real-world scenarios like data validation, API boundaries, and defensive API design.

Quick Start

Annotate your package with @NullMarked and begin using @Nullable and @NonNull to enforce non-null by default.

Frequently Asked Questions about java-null-safety

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce null-safety in Java using JSpecify annotations?

To enforce null-safety in Java, apply JSpecify annotations like @NullMarked at the package level using package-info.java to establish a default non-null contract across your codebase. You then explicitly mark exceptions using @Nullable and @NonNull.

What is the best way to make a Java package non-null by default?

The best way to make a Java package non-null by default is to apply the @NullMarked annotation within your package-info.java file. This configuration ensures all types default to non-null without needing individual annotations.

How do I migrate legacy Java code to use Optional for null-safety?

To migrate legacy Java code for null-safety, enforce non-null returns and guide transitions to Optional where appropriate. Using JSpecify package-level configuration helps validate these boundaries during migration.

When do I need @Nullable annotations in a @NullMarked Java package?

You need @Nullable annotations in a @NullMarked Java package when a method return type or parameter can legitimately be null. Since the package defaults to non-null, @Nullable explicitly flags controlled nullability exceptions.

Can I apply JSpecify null-safety configuration across multiple modules?

Yes, you can apply JSpecify null-safety configuration across multiple modules by maintaining consistent package-info.java conventions. This validates non-null returns and controlled nullability boundaries throughout your project.