Possible Int overflow in AggregateEventTag
See original GitHub issueLagom Version
1.4.5, 1.5.0, Master
API (Scala / Java / Neither / Both)
Both Scala and Java API.
Expected Behavior
AggregateEventTag.selectShard
should always return positive value.
Actual Behavior
AggregateEventTag.selectShard
can return a negative value, if entityId.hashCode == Int.MinValue. Then, if numShards is e.g. 6, the the result will be -2.
def selectShard(numShards: Int, entityId: String): Int = {
Math.abs(entityId.hashCode) % numShards
}
Here Math.abs(entityId.hashCode) % numShards
will reduce to Int.MinValue % numShards
, if entityId.hashCode
equals Int.MinValue
.
As there is no guarantee that String.hashCode
will not return Int.MinValue
, it is possible, albeit very unlikely, that the tag shard tag name generation will return an invalid tag name.
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (14 by maintainers)
Top Results From Across the Web
How does Java handle integer underflows and overflows and ...
If it overflows, it goes back to the minimum value and continues from there. If it underflows, it goes back to the maximum...
Read more >Domain Modelling with Akka Persistence Typed
In Akka Typed, unlike Akka classic and Lagom Persistence, it's not possible to return an exception to the caller. All communication between the...
Read more >Check for Integer Overflow - GeeksforGeeks
Write a “C” function, int addOvf(int* result, int a, int b) If there is no overflow, the function places the resultant = sum...
Read more >java.util.concurrent.ConcurrentHashMap Scala Example
Utils def apply( execId: String, host: String, port: Int, topologyInfo: ... AggregateEventTag import com.lightbend.lagom.scaladsl.persistence.
Read more >Is Integer Overflow and Underflow possible in any scenerio in ...
Well, yes. If you use assembly or the unchecked keyword you can get an overflow/underflow. Check this simple code I created:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think you mean:
Could also be:
Math.abs(shard)
I think the solution is:
Which hardcodes the mapping of
Int.MinValue
to0
and maintains all other mappings.