Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-1154

Spring Data query methods in kotlin may lead to breaking null safety

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Repositories
    • Labels:
      None

      Description

      Let's assume that we have a repository interface

      Unable to find source-code formatter for language: kotlin. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      interface UserRepository : CrudRepository<User, Long> {
      
          fun findByLastName(lastName: String): User
          
      }
      

      if we try to find a user with last name that does not exist we get a null value. It is not flagged by a '?' operator suggesting Kotlin compiler that it might be a null value, so all of the null safety Kotlin provides goes out of the window.

      Wouldn't be possible to throw error (warning?) at startup when query method looking for one result wasn't accompanied by a '?' operator

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mp911de Mark Paluch
                Reporter:
                Jan Petryk Jan Petryk
                Last updater:
                Mark Paluch
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: