Watch
2
0
Fork
You've already forked jaffirm
0
Simple and fast contract checks.
  • Java 98.8%
  • Shell 1.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Mark Raynsford ded78bd5a0
Some checks are pending
main-RHEL10-x86_64-jdk25 / Build (push) Waiting to run
main-RHEL10-x86_64-jdk26 / Build (push) Waiting to run
main-RHEL9-x86_64-jdk25 / Build (push) Waiting to run
main-RHEL9-x86_64-jdk26 / Build (push) Waiting to run
Update workflows.
2026-07-31 18:42:53 +01:00
.forgejo Update workflows. 2026-07-31 18:42:53 +01:00
com.io7m.jaffirm.core Use junit BOM. 2024-09-29 20:22:40 +00:00
com.io7m.jaffirm.tests Use junit BOM. 2024-09-29 20:22:40 +00:00
src/site/resources Update site metadata. 2025-08-09 15:06:48 +00:00
.gitignore Update .gitignore. 2024-05-07 16:01:42 +00:00
doc7m-books.json Add doc7m-books.json 2026-07-31 18:36:44 +01:00
pom.xml Migrate project. 2026-06-27 09:09:19 +01:00
README-CHANGES.xml Close release. 2024-05-05 15:42:08 +00:00
README-LICENSE.txt Update LICENSE 2023-08-13 21:07:23 +00:00
README.in Update README. 2026-06-27 09:11:29 +01:00
README.md Update README. 2026-06-27 09:11:29 +01:00

jaffirm

Maven Central Maven Central (snapshot) Java Version

com.io7m.jaffirm

jaffirm

The jaffirm package provides simple and fast pre/postcondition and invariant checking functions.

Features

  • Static invocation, zero-allocation code paths for the common case of non-failing contracts.
  • Specialized and generic variants of all functions for use in low-latency software.
  • Detailed contract failure messages by construction.
  • Written in pure Java 17.
  • High coverage test suite.
  • OSGi-ready
  • JPMS-ready
  • ISC license.

Usage

Declare preconditions with the Preconditions class. Declare postconditions with the Postconditions class. Declare invariants with the Invariants class.

import static com.io7m.jaffirm.core.Contracts.conditionI;
import static com.io7m.jaffirm.core.Preconditions.checkPreconditionI;
import static com.io7m.jaffirm.core.Preconditions.checkPreconditionsI;

int exampleSingles(final int x)
{
  checkPreconditionI(x, x > 0,      i -> "Input " + i + " must be > 0");
  checkPreconditionI(x, x % 2 == 0, i -> "Input " + i + " must be even");
  return x * 2;
}

int exampleMultis(final int x)
{
  checkPreconditionsI(
    x,
    conditionI(i -> i > 0,      i -> "Input " + i + " must be > 0"),
    conditionI(i -> i % 2 == 0, i -> "Input " + i + " must be even"));
  return x * 2;
}

> exampleSingles(0)
Exception in thread "main" com.io7m.jaffirm.core.PreconditionViolationException: Precondition violation.
  Received: 0
  Violated conditions:
    [0]: Input 0 must be > 0

> exampleSingles(1)
Exception in thread "main" com.io7m.jaffirm.core.PreconditionViolationException: Precondition violation.
  Received: 1
  Violated conditions:
    [0]: Input 1 must be even

> exampleMultis(-1)
Exception in thread "main" com.io7m.jaffirm.core.PreconditionViolationException: Precondition violation.
  Received: -1
  Violated conditions:
    [0]: Input -1 must be > 0
    [1]: Input -1 must be even