You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But any consistent (and documented) behavior would be good.
Actual Behavior
Sync:
sync.set("foo", "bar")
sync.get[Int]("foo") == None
sync.getOrElseUpdate[Int]("foo")(1) throws ClassCastException (inconsistent with sync.get)
Async:
async.set("foo", "bar")
async.get[Int]("foo") == Some("bar") (inconsistent with sync.get, ignores type parameter)
async.getOrElseUpdate[Int]("foo")(Future(1)) throws ClassCastException (consistent with async.get)
I have not tested other cache implementations.
Reproducible Test Case
classCaffeineSpecextendsPlaySpecwithGuiceOneAppPerTestwithInjecting {
lazyvalcache= inject[SyncCacheApi]
lazyvalasyncCache= inject[AsyncCacheApi]
"Caffeine" when {
"sync" should {
"return None when type differs" in {
cache.set("foo", "bar")
valret= cache.get[Int]("foo")
ret mustBe None
}
"set via getOrElseUpdate" in {
cache.set("foo", "bar")
valret= cache.getOrElseUpdate[Int]("foo")(1)
ret mustBe 1
}
}
"async" should {
"return None when type differs" in {
await(asyncCache.set("foo", "bar"))
valret= await(asyncCache.get[Int]("foo"))
ret mustBe None
}
"set via getOrElseUpdate" in {
await(asyncCache.set("foo", "bar"))
valret= await(asyncCache.getOrElseUpdate[Int]("foo")(Future.successful(1)))
ret mustBe 1
}
}
}
}
CaffeineSpec
Caffeine
when sync
- should return None when type differs
- should set via getOrElseUpdate *** FAILED ***
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Integer (java.lang.String and java.lang.Integer are in module java.base of loader 'bootstrap')
at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:99)
at CaffeineSpec.$anonfun$new$4(CaffeineSpec.scala:26)
...
when async
- should return None when type differs *** FAILED ***
Some("bar") was not equal to None (CaffeineSpec.scala:35)
- should set via getOrElseUpdate *** FAILED ***
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Integer (java.lang.String and java.lang.Integer are in module java.base of loader 'bootstrap')
at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:99)
at CaffeineSpec.$anonfun$new$8(CaffeineSpec.scala:40)
...
Execution took 2.72s
4 tests, 1 passed, 3 failed
The text was updated successfully, but these errors were encountered:
Thanks @akervinen.
This results definitely seem a bit strange. Having a consistent behavior would definitely make sense.
Would you be interested in providing a pull request to fix this?
Thanks a lot!
Play Version
2.9.1
API
Scala 2.13.12
Operating System
Windows 10
JDK
Library Dependencies
Expected Behavior
If current
sync.get
behavior is expected:cache.set("foo", "bar")
cache.get[Int]("foo") == None
cache.getOrElseUpdate[Int]("foo")(1) == 1
But any consistent (and documented) behavior would be good.
Actual Behavior
Sync:
sync.set("foo", "bar")
sync.get[Int]("foo") == None
sync.getOrElseUpdate[Int]("foo")(1)
throwsClassCastException
(inconsistent withsync.get
)Async:
async.set("foo", "bar")
async.get[Int]("foo") == Some("bar")
(inconsistent withsync.get
, ignores type parameter)async.getOrElseUpdate[Int]("foo")(Future(1))
throwsClassCastException
(consistent withasync.get
)I have not tested other cache implementations.
Reproducible Test Case
The text was updated successfully, but these errors were encountered: