Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've made several attempts at getting package annotation @ParametersAreNonnullByDefault to work for me in a maven project but with no success. Could someone share a link to a minimal/sample maven project where this is setup (or post the pom.xml and package-info.java and demo class)?

I'm talking about having findbugs processor enforce it for me.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
250 views
Welcome To Ask or Share your Answers For Others

1 Answer

How to apply @ParametersAreNonnullByDefault

Create a file package-info.java in your package where you want to enforce the desired behavior.

In that file, do the following:

/**
 * You should do it like this!
 */
@ParametersAreNonnullByDefault
package com.stackoverflow;

import javax.annotation.ParametersAreNonnullByDefault;

How not to apply @ParametersAreNonnullByDefault

Don't do the following in a Java source file:

/**
 * But you shouldn't do it this way!
 */
@ParametersAreNonnullByDefault
package com.stackoverflow;

import javax.annotation.ParametersAreNonnullByDefault;

public class Answer { ...

Declaring annotations like this is ambiguous.

Notes

It would be OK to apply the annotation directly on Answer class.

package com.stackoverflow;

import javax.annotation.ParametersAreNonnullByDefault;

/**
 * You can do it like this also.
 */
@ParametersAreNonnullByDefault
public class Answer { ...

The exact same things apply to @ParametersAreNullableByDefault also.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...