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

  • Home
  • SEARCH
  • 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 8710825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:43:28+00:00 2026-06-13T04:43:28+00:00

I had a serious bug in my code, which luckily I found :), because

  • 0

I had a serious bug in my code, which luckily I found :), because I forgot to change the method’s return type signature (from int to Integer) and my app was crashing without any warning.

I had the following method:

public static int getDataSourceIdForName(String name) {
    Integer i = dsNameToIdMap.get(name);
    return i;
}

It was crashing my app. I observed that it was crashing only when a special case occurred and the name was actually not in the map (Map<String, Integer> dsNameToIdMap = new HashMap<>()) thus it was returning null. I would expect a running application to throw a NullPointerException but this was not the case and the app was simply dying and I had a trip full of excitement to find the bug 🙂

Since I would like to have my IDE’s support in avoiding those situations in future, I am asking you guys how to set NetBeans to warn of those situations, i.e. when I am returning an object in a function which return signature is a primitive type, as I cannot figure it out myself.

UPDATE:
I have found the real problem. The code is in fact throwing the NullPointerException, as Jon rightly argued 🙂 It was only my clients ‘survival mechanism’ that was hiding it, as you can see in the sample below:

public class WhyNoNullPointerException {
    private static int test() {
        Integer i = null;
        return i;
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {

                for (int i = 0; i < 100; i++) {
                    System.out.println("i = " + i);
                    if (i == 10) {
                        try{
                           test();
                        }finally{
                            run();
                        }
                    }
                }
            }
        });
        t.setDaemon(true);
        t.start();
        Thread.sleep(1111);
    }
}

Since the program in finally tries to stay alive by restarting its main operational loop, for this reason it ‘hides’ the NullPointerException.

To avoid this situation in future I will now always, in this self restarting code, add a catch for Exception before the finally block as a good practice this way an exception will not be ‘lost’ (I had the block in the first place in my code I had a byte reading there which can throw IOException).

As to development of a hint I found a very nice tutorial over which I will go today and hopefully will have a working hint (link below). Thanks for your links guys (@JonSkeet and @Nambari) they were very useful in finding some more about the hint development.

NetBeans Java Hint Module Tutorial.

  • 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-13T04:43:29+00:00Added an answer on June 13, 2026 at 4:43 am

    It really does throw NullPointerException:

    import java.util.*;
    
    public class Test {
        private static final Map<String, Integer> map
            = new HashMap<String, Integer>();
    
        public static void main(String[] args) {
            getInt("Foo");
        }
    
        public static int getInt(String name) {
            Integer i = map.get(name);
            return i;
        }
    }
    

    Result:

    c:\Users\Jon\Test>java Test
    Exception in thread "main" java.lang.NullPointerException
            at Test.getInt(Test.java:13)
            at Test.main(Test.java:8)
    

    Now you may or may not also want NetBeans to warn on auto-unboxing… but it’s worth at least checking what’s going on first 🙂

    I found a plugin which highlights auto-boxing/unboxing and varargs, but it’s very old and may well not be supported on the version you’re using.

    I’d expect this to be configurable as a compiler option (it is in Eclipse) but I don’t have enough experience with NetBeans to say much more.

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

Sidebar

Related Questions

I recently had a serious bug, where I forgot to return a value in
Had to download Command Line Tools from Apple to get make to work, but
Had received a module from CCAVENUE and it was working fine with Magento 1.6.2...
Had a page that was working fine. Only change I made was to add
Had a problem with the recursive conflictCheck() method. That seems fine now. I have
I had a question in MySQL, did it correctly. But the book code differs
I had a weird issue arise after using CodeMaid to clean up my code.
Why was String designed as a reference type instead of value type? From the
I haven't had the chance to take any serious low-level programming courses in school.
I'm investigating a serious performance problem in my OSGi-based application which is using Eclipselink

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.