Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider supporting JSR 305 annotations #44

Open
cushon opened this issue Oct 31, 2014 · 4 comments
Open

Consider supporting JSR 305 annotations #44

cushon opened this issue Oct 31, 2014 · 4 comments

Comments

@cushon
Copy link
Collaborator

cushon commented Oct 31, 2014

Original issue created by aftandilian on 2012-09-20 at 05:44 PM


JSR 305 is abandoned but proposes several new annotations to help static analysis tools. Presumably anyone using these annotations would like to have a tool check for correctness. FindBugs and IntelliJ already do this.

http://jsr-305.googlecode.com/svn/trunk/javadoc/javax/annotation/package-summary.html

@cushon
Copy link
Collaborator Author

cushon commented Oct 31, 2014

Original comment posted by eaftan@google.com on 2013-02-11 at 09:33 PM


We added a check for @CheckReturnValue.

Consider adding support for this subset:
@CheckForNull
@Nonnegative
@Nonnull
@Nullable
@OverridingMethodsMustInvokeSuper
@ParametersAreNonnullByDefault
@ParametersAreNullableByDefault
@RegEx
@Syntax


Status: Accepted
Owner: eaftan@google.com
Labels: Type-Enhancement, Priority-Low

@vorburger
Copy link
Member

See also vaguely related #891, which proposes opening up null related annotations.

@dfabulich
Copy link

FYI, there's an Error Prone plugin, NullAway, that covers the stuff I most care about (@Nullable and @Nonnull).

https://github.com/uber/NullAway/wiki/Error-Messages

It's a bit of a hassle to hook it up with Bazel; I have a sample repository here that shows how to do it. https://github.com/dfabulich/bazel-checker-framework-bug/

WORKSPACE:

maven_jar(
	name='jsr305',
	artifact='com.google.code.findbugs:jsr305:3.0.2',
)

maven_jar(
	name="nullaway",
	artifact="com.uber.nullaway:nullaway:0.3.2"
)

maven_jar(
	name="guava",
	artifact="com.google.guava:guava:22.0",
)

BUILD:

java_library(
	name='x',
	srcs=['X.java'],
	deps=['@jsr305//jar'],
	plugins=['nullaway'],
	javacopts=[
		'-Xep:NullAway:ERROR',
		'-XepOpt:NullAway:AnnotatedPackages=com.example',
	],
)

java_plugin(
	name='nullaway',
	deps=[
		'@nullaway//jar',
		'@guava//jar',
	],
)

com.google.code.findbugs:jsr305 provides the javax.annotation.Nullable and Nonnull annotation classes. The dependency on Guava is unfortunate; I've filed a bug on that.

@jbduncan
Copy link
Contributor

jbduncan commented Feb 3, 2018

Another alternative is the Checker Framework, if you want an exhaustive null-checking type system. (AFAIK, NullAway only checks certain common cases with regards to incorrect null usage.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants