Skip to content

io7m-com/junreachable

Repository files navigation

junreachable

Maven Central Maven Central (snapshot) Codecov

com.io7m.junreachable

JVM Platform Status
OpenJDK (Temurin) Current Linux Build (OpenJDK (Temurin) Current, Linux)
OpenJDK (Temurin) LTS Linux Build (OpenJDK (Temurin) LTS, Linux)
OpenJDK (Temurin) Current Windows Build (OpenJDK (Temurin) Current, Windows)
OpenJDK (Temurin) LTS Windows Build (OpenJDK (Temurin) LTS, Windows)

junreachable

The junreachable package implements a set of exception types for unambiguously marking code that is supposed to be unreachable (but that the compiler cannot prove is unreachable).

Status

As the Java platform evolves, libraries that may have been necessary in the past can become unnecessary due to new platform features. The junreachable package falls into this category: There are now far fewer instances in the Java language where the compiler cannot determine that a given section of code is unreachable. In particular, switch expressions and sealed types eliminate many of the situations where unreachable code had to be explicitly marked.

This package is in maintenance mode and will not see any new functionality.

Features

  • Exceptions for marking unreachable code.
  • High coverage test suite.
  • OSGi-ready
  • JPMS-ready
  • ISC license.

Usage

Throw the UnreachableCodeException exception at lines of code that are expected to be unreachable, but that the compiler cannot prove are really unreachable. If this exception ends up being thrown, it will unambiguously signal that the code wasn't as unreachable as the developer thought; this is clearly a bug.

Throw the UnimplementedCodeException exception at lines of code that have yet to contain real implementations. If this exception ends up being thrown, it is immediately clear to users and developers alike what happened: The user tried to use some part of the code that hasn't yet been properly implemented.