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

S3655 should not raise an issue when a method doing nothing is called between "isPresent" and "get()"

    Details

    • Type: False-Positive
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.7
    • Component/s: Rules, Symbolic Execution
    • Labels:
      None

      Description

      Reproducer:

      public class S3655 {
      
        private Optional<String> state;
      
        public void functionThatDoesNotChangeState() {
          // DO NOTHING
        }
      
        public String useOptionalWithCallToMemberFunction() {
          if (state.isPresent()) {
            functionThatDoesNotChangeState();
            return state.get(); // SQ Issue S3655
          }
          return "";
        }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                quentin.jaquier Quentin Jaquier
                Reporter:
                alexandre.gigleux Alexandre Gigleux
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: