forked from uber/NullAway
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 88bdd4a
Showing
62 changed files
with
9,265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Thanks for using NullAway. Before you create an issue, please consider the following points: | ||
|
||
- [ ] If you think you found a bug, please include a code sample that reproduces the problem. A test case that reproduces the issue is preferred. A stack trace alone is ok but may not contain enough context for us to address the issue. | ||
|
||
- [ ] Please include the library version number, including the minor and patch version, in the issue text. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Thank you for contributing to NullAway. Before pressing the "Create Pull Request" button, please provide the following: | ||
|
||
- [ ] A description about what and why you are contributing, even if it's trivial. | ||
|
||
- [ ] The issue number(s) or PR number(s) in the description if you are contributing in response to those. | ||
|
||
- [ ] If applicable, unit tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
###OSX### | ||
|
||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must ends with two \r. | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear on external disk | ||
.Spotlight-V100 | ||
.Trashes | ||
|
||
|
||
###Linux### | ||
|
||
*~ | ||
|
||
# KDE directory preferences | ||
.directory | ||
|
||
|
||
###Android### | ||
|
||
# Built application files | ||
*.apk | ||
*.ap_ | ||
|
||
# Files for ART and Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
.gradletasknamecache | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Lint | ||
lint-report.html | ||
lint-report_files/ | ||
lint_result.txt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.war | ||
*.ear | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
|
||
###IntelliJ### | ||
|
||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
|
||
###Eclipse### | ||
|
||
*.pydevproject | ||
.metadata | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
.settings/ | ||
.loadpath | ||
|
||
# External tool builders | ||
.externalToolBuilders/ | ||
|
||
# Locally stored "Eclipse launch configurations" | ||
*.launch | ||
|
||
# CDT-specific | ||
.cproject | ||
|
||
# PDT-specific | ||
.buildpath | ||
|
||
# sbteclipse plugin | ||
.target | ||
|
||
# TeXlipse plugin | ||
.texlipse | ||
|
||
# kotlin | ||
annotations/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: java | ||
|
||
jdk: | ||
- oraclejdk8 | ||
|
||
script: | ||
- ./gradlew build | ||
|
||
|
||
|
||
notifications: | ||
email: false | ||
|
||
sudo: false | ||
|
||
cache: | ||
directories: | ||
- $HOME/.gradle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Changelog | ||
========= | ||
|
||
Version 0.1.0 | ||
---------------------------- | ||
|
||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Contributing to Uber's Android Template | ||
======================= | ||
|
||
Uber welcomes contributions of all kinds and sizes. This includes everything from from simple bug reports to large features. | ||
|
||
Workflow | ||
-------- | ||
|
||
We love GitHub issues! | ||
|
||
For small feature requests, an issue first proposing it for discussion or demo implementation in a PR suffice. | ||
|
||
For big features, please open an issue so that we can agree on the direction, and hopefully avoid investing a lot of time on a feature that might need reworking. | ||
|
||
Small pull requests for things like typos, bug fixes, etc are always welcome. | ||
|
||
DOs and DON'Ts | ||
-------------- | ||
|
||
* DO follow our [coding style](https://github.com/uber/java-code-styles) | ||
* DO include tests when adding new features. When fixing bugs, start with adding a test that highlights how the current behavior is broken. | ||
* DO keep the discussions focused. When a new or related topic comes up it's often better to create new issue than to side track the discussion. | ||
|
||
* DON'T submit PRs that alter licensing related files or headers. If you believe there's a problem with them, file an issue and we'll be happy to discuss it. | ||
|
||
Guiding Principals | ||
------------------ | ||
|
||
* We allow anyone to participate in our projects. Tasks can be carried out by anyone that demonstrates the capability to complete them | ||
* Always be respectful of one another. Assume the best in others and act with empathy at all times | ||
* Collaborate closely with individuals maintaining the project or experienced users. Getting ideas out in the open and seeing a proposal before it's a pull request helps reduce redundancy and ensures we're all connected to the decision making process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2017 Uber Technologies, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
## NullAway: Fast Annotation-Based Null Checking for Java [![Build Status](https://travis-ci.org/uber/NullAway.svg?branch=master)](https://travis-ci.org/uber/NullAway) | ||
|
||
NullAway is a tool to help eliminate `NullPointerException`s (NPEs) in your Java code. To use NullAway, first add `@Nullable` annotations in your code wherever a field, method parameter, or return value may be `null`. Given these annotations, NullAway performs a series of type-based, local checks to ensure that any pointer that gets dereferenced in your code cannot be `null`. NullAway is similar to the type-based nullability checking in the Kotlin and Swift languages, and the [Checker Framework](https://checkerframework.org/) and [Eradicate](http://fbinfer.com/docs/eradicate.html) null checkers for Java. | ||
|
||
NullAway is *fast*. It is built as a plugin to Error Prone and can run on every single build of your code. In our measurements, the build-time overhead of running NullAway is usually less than 10%. NullAway is also *practical*: it does not prevent all possible NPEs in your code, but it catches most of the NPEs we have observed in production while imposing a reasonable annotation burden, giving a great "bang for your buck." At Uber, we combine NullAway with [RAVE](https://github.com/uber-common/rave) to obtain thorough protection against NPEs in our Android apps. | ||
|
||
## Installation | ||
|
||
### Overview | ||
|
||
NullAway requires that you build your code with [Error Prone](http://errorprone.info), version 2.1.1 or higher. See the [Error Prone documentation](http://errorprone.info/docs/installation) for instructions on getting started with Error Prone and integration with your build system. The instructions below assume you are using the Gradle build system; integration with other systems should require similar steps. | ||
|
||
### Gradle | ||
To integrate NullAway into your project add the following to your `build.gradle` file: | ||
|
||
``` | ||
buildscript { | ||
repositories { | ||
maven { | ||
url "https://plugins.gradle.org/m2/" | ||
} | ||
} | ||
dependencies { | ||
classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.11" | ||
classpath "net.ltgt.gradle:gradle-apt-plugin:0.11" | ||
} | ||
} | ||
apply plugin: "java" | ||
apply plugin: "net.ltgt.errorprone" | ||
apply plugin: "net.ltgt.apt" | ||
configurations.errorprone { | ||
resolutionStrategy.force "com.google.errorprone:error_prone_core:2.1.1" | ||
} | ||
dependencies { | ||
apt "com.uber:nullaway:0.1.0" | ||
compile "com.google.code.findbugs:jsr305:3.0.2" | ||
} | ||
compileJava { | ||
options.compilerArgs += ["-Xep:NullAway:ERROR", "-XepOpt:NullAway:AnnotatedPackages=com.uber"] | ||
} | ||
``` | ||
|
||
Let's walk through this script step by step. The `buildscript` section of the script pulls in the [Gradle Error Prone plugin](https://github.com/tbroyer/gradle-errorprone-plugin) for Error Prone integration, and the [Gradle APT plugin](https://github.com/tbroyer/gradle-apt-plugin) to ease specification of annotation processor dependencies for a build. We need the latter since Error Prone loads plugin checkers from the annotation processor path. Note that the Gradle APT plugin is appropriate for Java projects; for Android projects, use an `annotationProcessor` dependence with the [Android Gradle plugin](https://developer.android.com/studio/releases/gradle-plugin.html). The `apply plugin` lines load the relevant plugins. The `configurations.errorprone` section forces our desired Error Prone version. | ||
|
||
In `dependencies`, the `apt` line loads NullAway, and the `compile` line loads a [JSR 305](https://jcp.org/en/jsr/detail?id=305) library which provides a suitable `@Nullable` annotation (`javax.annotation.Nullable`). NullAway allows for any `@Nullable` annotation to be used, so, e.g., `@Nullable` from the Android support or IntelliJ annotations is also fine. | ||
|
||
Finally, in the `compileJava` section, we pass some configuration options to NullAway as compiler arguments. The first argument `-Xep:NullAway:ERROR` is a standard Error Prone argument that sets NullAway issues to the error level; by default NullAway emits warnings. The second argument, `-XepOpt:NullAway:AnnotatedPackages=com.uber`, tells NullAway that source code in packages under the `com.uber` namespace should be checked for null dereferences and proper usage of `@Nullable` annotations, and that class files in these packages should be assumed to have correct usage of `@Nullable` (see [the docs](https://github.com/uber/NullAway/wiki/Configuration) for more detail). NullAway requires at least the `AnnotatedPackages` configuration argument to run, in order to distinguish between annotated and unannotated code. See [the configuration docs](https://github.com/uber/NullAway/wiki/Configuration) for other useful configuration options. | ||
|
||
## Code Example | ||
|
||
Let's see how NullAway works on a simple code example: | ||
```java | ||
static void log(Object x) { | ||
System.out.println(x.toString()); | ||
} | ||
static void foo() { | ||
log(null); | ||
} | ||
``` | ||
This code is buggy: when `foo()` is called, the subsequent call to `log()` will fail with an NPE. You can see this error in the NullAway sample app by running: | ||
``` | ||
cp sample/src/main/java/com/uber/mylib/MyClass.java.buggy sample/src/main/java/com/uber/mylib/MyClass.java | ||
./gradlew build | ||
``` | ||
|
||
By default, NullAway assumes every method parameter, return value, and field is _non-null_, i.e., it can never be assigned a `null` value. In the above code, the `x` parameter of `log()` is assumed to be non-null. So, NullAway reports the following error: | ||
``` | ||
warning: [NullAway] passing @Nullable parameter 'null' where @NonNull is required | ||
log(null); | ||
^ | ||
``` | ||
We can fix this error by allowing `null` to be passed to `log()`, with a `@Nullable` annotation: | ||
```java | ||
static void log(@Nullable Object x) { | ||
System.out.println(x.toString()); | ||
} | ||
``` | ||
With this annotation, NullAway points out the possible null dereference: | ||
``` | ||
warning: [NullAway] dereferenced expression x is @Nullable | ||
System.out.println(x.toString()); | ||
^ | ||
``` | ||
We can fix this warning by adding a null check: | ||
```java | ||
static void log(@Nullable Object x) { | ||
if (x != null) { | ||
System.out.println(x.toString()); | ||
} | ||
} | ||
``` | ||
With this change, all the NullAway warnings are fixed. | ||
|
||
For more details on NullAway's checks, error messages, and limitations, see [our detailed guide](https://github.com/uber/NullAway/wiki). | ||
|
||
## Contributors | ||
|
||
We'd love for you to contribute to our open source projects. Before we can accept your contributions, we kindly ask you to sign our [Uber Contributor License Agreement](https://docs.google.com/a/uber.com/forms/d/1pAwS_-dA1KhPlfxzYLBqK6rsSWwRwH95OCCZrcsY5rk/viewform). | ||
|
||
- If you **find a bug**, open an issue or submit a fix via a pull request. | ||
- If you **have a feature request**, open an issue or submit an implementation via a pull request | ||
- If you **want to contribute**, submit a pull request. | ||
|
||
## License | ||
|
||
NullAway is licensed under the MIT license. See the LICENSE.txt file for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Releasing | ||
========= | ||
|
||
1. Change the version in `gradle.properties` to a non-SNAPSHOT version. | ||
2. Update the `CHANGELOG.md` for the impending release. | ||
3. Update the `README.md` with the new version. | ||
4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version) | ||
5. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version) | ||
6. `./gradlew clean uploadArchives` | ||
7. Update the `gradle.properties` to the next SNAPSHOT version. | ||
8. `git commit -am "Prepare next development version."` | ||
9. `git push && git push --tags` | ||
10. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2017. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
subprojects { | ||
buildscript { | ||
repositories { | ||
jcenter() | ||
maven { | ||
url "https://plugins.gradle.org/m2/" | ||
} | ||
} | ||
} | ||
|
||
repositories { | ||
jcenter() | ||
} | ||
|
||
} | ||
|
||
apply from: 'gradle/dependencies.gradle' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0"?> | ||
|
||
<!DOCTYPE suppressions PUBLIC | ||
"-//Puppy Crawl//DTD Suppressions 1.1//EN" | ||
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd"> | ||
|
||
<suppressions> | ||
<suppress checks="JavadocType" files="[\\/]test[\\/]" /> | ||
<suppress checks="JavadocMethod" files="[\\/]test[\\/]" /> | ||
</suppressions> |
Oops, something went wrong.