Skip to content

JurenIvan/jspecify-exercise

Repository files navigation

🧩 JSpecify Nullness Exercise

Motivation

This project is a hands-on introduction to JSpecify — the emerging standard for nullness annotations in Java.
The goal is to get comfortable with @NullMarked, @Nullable, and the semantics behind them, while learning how tools like Error Prone interpret null-safety contracts.

You’ll start from partially annotated code, fill in the missing pieces, and verify your understanding by comparing your work with the provided solution.


Setup

The repository has two branches:

Branch Description
main Starting point — incomplete or incorrectly annotated code
solutions Fully annotated, correct version for comparison

Your task is to complete the annotations (and in a few spots, small method implementations) so that the build passes under Error Prone.

💡 IntelliJ may only show warnings, but the Gradle build is configured to fail if nullness issues are detected.


Plan

  1. Read the JSpecify documentation
    👉 https://jspecify.dev

  2. Clone and open the project

    git clone https://github.com/JurenIvan/jspecify-exercise.git
    cd jspecify-exercise
  3. Check out the starting branch

    git checkout main
  4. Run the build

    ./gradlew build

    It should pass.

  5. Add nullness annotations
    Fix the nullness issues by applying the correct @NullMarked, @Nullable, and related annotations.
    Some classes may also require a tiny implementation of methods. It's could give you the feel for guardrails JSpecify provides.

  6. Commit your solution

    git checkout -b my-solution
    git commit -am "My JSpecify solution"
    git push origin my-solution
  7. Create a Merge Request
    Open a Merge Request (or Pull Request) to the solutions branch.
    You’ll then see a clear diff against the reference solution to check your work.


Style considerations

Project uses intelliJs defaults for formatting, importing etc. When implementing:

  • Try to use minimal number of annotations (to have code as concise as possible)
  • Consider each class as a separate entity (don't do package-info.java)

To avoid having unnecessary diff to the solution branch.


Build Configuration

The project uses Gradle with Error Prone and NullAway enabled.
They enforce nullness correctness — builds fail when annotations are missing, misplaced, or inconsistent.

If you have any issues running it. Help me streamline this exercise.


Good luck! 🍀

Take your time to read the JSpecify docs (I found their userguide to be amazing!), reason about null contracts carefully — it’s excellent practice for writing robust, null-safe Java.
When you’re done, open your MR and compare your work against the solutions branch.
You’ll know exactly how close you got. 🚀

About

JSpecify Nullness Exercise

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages