Skip to content
Nullfree will fail your build if your project has a null.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets
gradle/wrapper Init commit Apr 15, 2019
lib #27 Add the threshold for nulls count Jun 16, 2019
plugin-gradle
plugin-maven #27 Update plugins and readme for threshold Jun 16, 2019
.codecov.yml
.travis.yml
LICENSE Travis, codecov, readme, license Apr 15, 2019
_config.yml
build.gradle
gradlew
gradlew.bat
readme.md
settings.gradle

readme.md

Nullfree

Elegant Objects Respected Here

nullfree status

Lib version Gradle plugin version Maven plugin version Build Status codecov

License: MIT

logo

What is it?

It is the service for analysing your project contains or not the null literal. With Nullfree you can add a badge to your project who looks like without nulls, if your project does not contain null, else if project contains at least one null it will looks like with nulls. There's even more, Nullfree will fail project build, if it contains a null.

For what?

Based on statistics from Overops NullPointerException is at the top of all exceptions in Java apps. It's simple: if there is no one null in a codebase, then NullPointerException will be gone. Let's stop using null!

Getting started

Gradle

Add the Nullfree plugin:

plugins {
    id 'com.nikialeksey.nullfree' version '1.4.0'
}

Invoke it:

./gradlew nullfree

Maven

Add the Nullfree plugin:

<plugin>
    <groupId>com.nikialeksey</groupId>
    <artifactId>nullfree-maven-plugin</artifactId>
    <version>1.4.0</version>
</plugin>

Invoke it:

mvn nullfree:nullfree

Add your nullfree badge to the project readme:

![nullfree status](https://iwillfailyou.com/nullfree/<your nickname>/<your repo>)

Suppress

You can suppress any null by @SuppressWarnings("nullfree") annotation:

@SuppressWarnings("nullfree")
class A {
    private final String a = null;
}

Method, field, variable suppresses are all available as well.

Other ways to ignoring nulls

Sometimes (usually in integrations with foreign libraries) it have to use null in comparisions:

if (some != null) { ... }
if (other == null) { ... }

It's ok, if you use it, NullPointerException does not throw in this place, so you can add option to Nullfree plugin for skipping such nulls:

Gradle plugin

nullfree {
    skipComparisions = true
}

Maven plugin

<plugin>
    <groupId>com.nikialeksey</groupId>
    <artifactId>nullfree-maven-plugin</artifactId>
    <version>1.4.0</version>
    <configuration>
        <skipComparisions>true</skipComparisions>
    </configuration>
</plugin>

Nulls threshold

You can the nulls threshold to allow project has a few nulls, but there would be only few.

Gradle plugin

nullfree {
    threshold = 5
}

Maven plugin

<plugin>
    <groupId>com.nikialeksey</groupId>
    <artifactId>nullfree-maven-plugin</artifactId>
    <version>1.4.0</version>
    <configuration>
        <threshold>5</threshold>
    </configuration>
</plugin>

Changelog

1.4.0 - Threshold for nulls count

1.3.0 - Send null descriptions to the API instead of badge url

1.2.0 - Fail build if it contains a null

1.1.0 - Skip nulls in comparisions expressions ability

1.0.0 - Changed API of nullfree lib, null suppression ability

0.0.2 - First version of service and plugin, self checking nullfree badge

You can’t perform that action at this time.