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 4087308
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:50:20+00:00 2026-05-20T18:50:20+00:00

Hi I have got some code that is reported as having the NP_GUARANTEED_DEREF issue

  • 0

Hi I have got some code that is reported as having the NP_GUARANTEED_DEREF issue by Findbugs.
Now looking at my code I don’t quite understand what is wrong with it, can anyone suggest what the problem is.

public void test() {
  String var = "";
  int index = 2;
  if (index == -1) {
    var = String.class.getName();
    if (var.length() == 0) {
      var = null;
    }
  } else {
    var = Integer.class.getName();
    if (var.length() == 0) {
      var = null;
    }
  }
  if (var == null) {// FINBUGS reports on this line NP_GUARANTEED_DEREF
    /*
     * There is a statement or branch that if executed guarantees that a value
     * is null at this point, and that value that is guaranteed to be
     * dereferenced (except on forward paths involving runtime exceptions).
     */
    throw new NullPointerException("NULL");
  }
}

Now drilling into the Error in Findbugs it highlights the two assignments to var = null; as cause for the bug but I don’t quite understand why. It is not like I am actually doing anything with the var object I am just doing a Null check. The example is taken from real production code but stripped of anything that wasn’t needed to reproduce the error. What I am wondering if this is a false positive or not. And if not what would be an appropriate fix.

Here is the link to the Findbugs Bug Detail: http://findbugs.sourceforge.net/bugDescriptions.html#NP_GUARANTEED_DEREF

[UPDATE] After recieving some feedback on this issue I have now logged this as a False Positive in the Findbugs Bugtracker on Sourceforge the link is https://sourceforge.net/tracker/?func=detail&aid=3277814&group_id=96405&atid=614693

Conversation about the problem will continue there.

  • 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-05-20T18:50:20+00:00Added an answer on May 20, 2026 at 6:50 pm

    I see. I can confirm the same FB behavior on my computer. Looks strange indeed. What’s funny, that if you replaced throw new NullPointerException with throw new RuntimeException the bug marker would disappear.

    Now I think I understand what they’ve meant. The wording of the message is not exact, but they are warning you against a NPE. I guess they consider explicitly throwing NPE a bad practice.

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

Sidebar

Related Questions

I have some OpenGL code that behaves inconsistently across different hardware. I've got some
I have got some code to load an assembly and get all types, which
I just got Delphi 2009 and have previously read some articles about modifications that
I've got some code that runs on every (nearly) every admin request but doesn't
I've got some code that is logging unhandled exceptions in the global.asax. Whenever an
I've got some code that lies in a browser, and wrote C++ plugins for
I have got some code to pass in a variable into a script from
I've got some code that: reads from a ReadableByteChannel into a ByteBuffer , takes
I've got some entities which have decimal properties on them. These entities' properties are
I have a project I am doing some maintenance work on and have got

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.