Uploaded image for project: 'Application Controller'
  1. Application Controller
  2. APPC-1047

Blocker issue reported by sonar for A "NullPointerException" could be thrown:

XMLWordPrintable

      https://sonar.onap.org/project/issues?assignees=krisjinka&id=org.onap.appc%3Aappc&resolved=false&severities=BLOCKER&types=BUG

      Issues related with "NullPointerException" in the above link

      The purpose of this bug is to address the blocker issue related with "A "NullPointerException" could be thrown;" Opening a separate bug for this, because this change could be sensitive and might need some sort of exception handling. Because as per sonarcube, at these places, its possible that nullpointer could be thrown at runtime and we need to trace how this exception is handled down the line. 

      Adding null check could be actually counter productive because, in that case it will mask the exception that would have otherwise occurred at runtime. So., in order to fix this issue, following are some options I could think of

      1. At some places, there is null check in some method, but later for same variable , null check is missing. Thats why sonarcube flagged this error. So, to handle this, it might be better to check for null and throw an exception. Again, here some more investigation have to be done as to what kind of exception have to be thrown ?
        1. Option 1) Throwing a checked exception could create more dependency because the function calling this have to handle this new exception*,*
        2. Option 2) Throw a Runtime exception after checking for null for example IllegalArgumentException. My assumption here is since IllegalArgument exception is also a runtime exception similar to NullPointerException, the system behavior will not change. And to improve further, a suitable message in this, would actually help while debugging to figure out why this happened. In this case, some value was null, or inappropriate for the code to proceed further

      Hence from the initial analysis, it seems like Option 2) is more reasonable in the following ways:

      1. It provides more info about why the exception happens
      2. The system behavior is not impacted because similar to null pointer exception, it is also a runtime exception
      3. And it will fix the Nullpointer issue in Sonarcube

       

      rx196w, Please let me know your thoughts on this issue ?

      I will do more code analysis and post any impacts of addressing this issue in the comments below. 

       

            krisjinka krisjinka
            krisjinka krisjinka
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: