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

NPE in Symbolic Execution engine when dealing with java 14 switch expressions without default

    Details

      Description

      The following code causes a NPE in our symbolic execution engine, when dealing with a switch expression:

      public class A {
        int foo(MyEnum s) {
          return switch (s) {
            case SOME_TYPE -> 123;
            case ANOTHER_TYPE -> 456;
          };
        }
      
        public enum MyEnum {
          SOME_TYPE,
          ANOTHER_TYPE;
        }
      }
      

      Stack trace:

      java.lang.NullPointerException
      	at java.base/java.util.Objects.requireNonNull(Objects.java:221)
      	at org.sonar.java.collections.AVLTree.get(AVLTree.java:76)
      	at org.sonar.java.se.ProgramState.removeConstraintsOnDomain(ProgramState.java:320)
      	at org.sonar.java.se.checks.StreamConsumedCheck.checkPostStatement(StreamConsumedCheck.java:212)
      	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:106)
      

      The absence of default block is unexpected by the engine, and causes an extra transition, without anything on the stack.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                michael.gumowski Michael Gumowski
                Reporter:
                michael.gumowski Michael Gumowski
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: