Foso / Ktorfit

HTTP client generator / KSP plugin for Kotlin Multiplatform (Android, iOS, Js, Jvm, Native) using KSP and Ktor clients inspired by Retrofit https://foso.github.io/Ktorfit
https://foso.github.io/Ktorfit
Apache License 2.0
1.57k stars 41 forks source link

Equals comparison appears to be inconsistent #205

Closed mikedrawz closed 1 year ago

mikedrawz commented 1 year ago

Ktorfit version

1.0.0

What happened and how can we reproduce this issue?

Environment info

Steps to reproduce

  1. Create an API created by the library that can be accessed by the android app (using CallResponseConverter)
  2. Call the API method
  3. Note the following behavior when comparing the response code equality LOGGER.debug("mike-log - response val [{}] - ok val[{}] - equals[{}]", httpResponse.getStatus().getValue(), HttpStatusCode.Companion.getOK().getValue(), (httpResponse.getStatus() == HttpStatusCode.Companion.getOK())); LOGGER.debug("mike-log - equals 1: {}", HttpStatusCode.Companion.getOK().equals(httpResponse.getStatus())); LOGGER.debug("mike-log - equals 2: {}", httpResponse.getStatus().equals(HttpStatusCode.Companion.getOK())); LOGGER.debug("mike-log - is same class 1: {}", httpResponse.getStatus() instanceof HttpStatusCode); LOGGER.debug("mike-log - is same class 2: {}", HttpStatusCode.Companion.getOK() instanceof HttpStatusCode); LOGGER.debug("mike-log - val equals {}", HttpStatusCode.Companion.getOK().getValue() == httpResponse.getStatus().getValue());

produces

DEBUG mike-log - response val [200] - ok val[200] - equals[false] DEBUG mike-log - equals 1: true DEBUG mike-log - equals 2: true DEBUG mike-log - is same class 1: true DEBUG mike-log - is same class 2: true DEBUG mike-log - val equals true

I'm not sure why, but == seems to fail when .equals() works. I'm unsure if this is a KMM thing or related to the class HttpStatusCode but I figured I'd bring this to the project's attention.

What did you expect to happen?

I would expect that == and .equals() would work in the same manner.

Is there anything else we need to know about?

No response

Foso commented 1 year ago

Thank you for reporting this, but it looks like a bug inside Ktor