Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3169

S2589 should not raise issue with null check in finally block

    Details

    • Type: False-Positive
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Symbolic Execution
    • Labels:
      None

      Description

      RSPEC-2589 raises an issue in the following snippet, although it is possible for x to be null in the finally block.

      abstract class A11440 {
      
        abstract Object sampleMethod();
      
        public void run() {
          Object x = sampleMethod();
          try {
            if (x.equals("aaa")) //if x is null there is a NullPointerException
            {
              //do something
            }
          } catch (NumberFormatException a) {
            //do something
          } finally {
      //finally block is executed even if there is NullPointerException in try block, so x can be null
            if (x != null) {  // False positive raised S2589
              //do something
            }
          }
        }
      }
      
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                tibor.blenessy Tibor Blenessy
              • Votes:
                1 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: