Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-32248

Incorrect AssertJ usage

    XMLWordPrintableJSON

Details

    Description

      Flink uses AssertJ incorrectly:

      • Multiple tests callĀ AssertJ's withFailMessage at the end, for example something like this:
        assertThat(...)
            ...()
            .withFailMessage("Some message");
        

        However, the withFailMessage documentation says:

        You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.

        This can be seen for example with the following code where the custom message is ignored:

         assertThat(false).isTrue().withFailMessage("Some message");
        

        There are 20+ cases of this in the Flink code so I am not going to list them here, hoping that it is easier to find them yourself. Though please let me know if I should list them here.

      I found those because AssertJ is luckily using @CheckReturnValue on their API. I assume SpotBugs, Error Prone or IntelliJ IDEA might have found these issues as well, in case you want to investigate integrating automatic detection of such errors.

      Attachments

        Issue Links

          Activity

            People

              yyhx xuhuang
              Marcono1234 Marcono1234
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: