Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9178649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:36:09+00:00 2026-06-17T17:36:09+00:00

I want to create custom annotations to suppress individual FindBugs warnings to make it

  • 0

I want to create custom annotations to suppress individual FindBugs warnings to make it easier to use them via code-completion. For example, this one ignores constructors that don’t set all @Nonnull fields.

@TypeQualifierDefault(ElementType.CONSTRUCTOR)
@SuppressFBWarnings("NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
@Retention(RetentionPolicy.CLASS)
public @interface SuppressNonnullFieldNotInitializedWarning
{ }

However, I still see the warning when using the annotation.

public class User {
    @Nonnull
    private String name;

    @SuppressNonnullFieldNotInitializedWarning
    public User() {
        // "Nonnull field name is not initialized by new User()"
    }
}

I’ve tried different retention policies and element types, putting the annotation on the constructor and the class, and even @TypeQualifierNickname.

This same pattern works to apply @Nonnull to all fields in a class.

@Nonnull
@TypeQualifierDefault(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface FieldsAreNonnullByDefault
{ }

FindBugs correctly displays a warning for code that assigns null to name.

@FieldsAreNonnullByDefault
public class User {
    private String name;

    public UserModel() {
        name = null;
        // "Store of null value into field User.name annotated Nonnull"
    }
}

I believe the problem is that @SuppressFBWarnings is not marked with @TypeQualifier while @Nonnull is, and thus @TypeQualifierDefault and @TypeQualifierNickname don’t apply to it. But there must be some other mechanism to apply one annotation using another.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:36:10+00:00Added an answer on June 17, 2026 at 5:36 pm

    (Not specifically answering the question), but if you just want to make code-completion work better with @SuppressFBWarnings, you could define a static final String for each of the warning codes and then use those in the annotation. e.g.

    public final class FBWarningCodes {
        private FBWarningCodes() { }
    
        public static final String NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR";
    }
    

    Then:

    import static com.tmobile.tmo.cms.service.content.FBWarningCodes.*;
    
    @SuppressFBWarnings(NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR)
    

    (though admittedly Eclipse doesn’t want to do code-completion unless you specify value= in the annotation)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create custom error code and message mapping file. Currently I use
I want to create custom buttons to use in a TabHost. I haven been
I want to create a custom button in ActionScript. This is my code: import
I want to create custom radiobuttons via Bootstrap. I did it, but I want
I want to create custom NANT files. To do this, I use C# to
I want to create custom search engine for multiple domain. How can I use
I want to create custom action in c# code for sharepoint list. I am
I want to create a custom annotation (using Java) which would accept other annotations
i want create a custom json data from the mssql 2008 results so that
I want to create custom button and I need it to be circle. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.