Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Nullfree

It's deprecated now and won't be supported anymore. If you want to use this type of analysis in your project then use the iwillfailyou.com

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 which 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.5.1'
}

Invoke it:

./gradlew nullfree

Maven

Add the Nullfree plugin:

<plugin>
    <groupId>com.nikialeksey</groupId>
    <artifactId>nullfree-maven-plugin</artifactId>
    <version>1.5.1</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.5.1</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.5.1</version>
    <configuration>
        <threshold>5</threshold>
    </configuration>
</plugin>

Offline mode

You could use nullfree without badge and external service https://iwillfailyou.com/nullfree/ with offline mode

Gradle plugin

nullfree {
    offline = true
}

Maven plugin

<plugin>
    <groupId>com.nikialeksey</groupId>
    <artifactId>nullfree-maven-plugin</artifactId>
    <version>1.5.1</version>
    <configuration>
        <offline>true</offline>
    </configuration>
</plugin>

Changelog

1.4.3 - Suppress works with overrides

1.4.2 - Support all (from 1 to 12) java version syntax when parsing nulls

1.4.1 - Parsing error tips in exception message

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