-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Description
The Interval.of method has a cache that is not thread safe and can thus return invalid Interval instances. This can manifest for example with
org.antlr.v4.runtime.CommonToken.getText returning invalid tokens, usually either the first character of the input stream or the entire input.
I have seen this happen in the jdbi code here, where sql statement are randomly corrupted when parsed.
It was only observed on arm (aws ec2 running graviton processor).
There are few options how to fix it
- Make the cache thread safe (will add synchronization overhead)
- Drop the cache altogether (potential very small object creation overhead, could also not be there if inilining + escape analyzis and scalar replacement works as intended)
- Initialize the cache with all the values (potential small memory overhead)
- Use safe idiom for unsafe publication (maybe marking fields final should suffice)
I suggest solution 2. I can prepare PR with the fix.
findepi, wendigo, petroav, carlos-caldera, stevenschlansker and 1 morewendigo, petroav, carlos-caldera and VictorAtPLwendigo, petroav, carlos-caldera and eljonnywendigo, petroav, carlos-caldera and VictorAtPLwendigo and petroav
Metadata
Metadata
Assignees
Labels
No labels