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

S6073 should not produce a NullPointerException when trying to read the body of an abstract method

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.3
    • Component/s: None
    • Labels:

      Description

      When checking that a method call returns an argument matcher, S6073 should first ensure that the method actually has a body.
      In the sample code that follows, as S6073 tries to access the body of the method getCommand, a null reference is returned and S6073 crashes.

      public abstract class SomeAbstractTest {
          interface SthToMock {
            String command( String exec );
          }
      
          @Mock
          private SthToMock sthToMock;
      
          public abstract String getCommand();
      
          @Test
          public void shouldReturnSystemDateTime() {
            when(sthToMock.command(getCommand())).thenReturn("test");
          }
        }
      

      When the invoked method references a method whose body cannot be accessed, S6073 should consider that the return value is most likely an argument matcher.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dorian.burihabwa Dorian Burihabwa
              Reporter:
              dorian.burihabwa Dorian Burihabwa
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: