My IntelliJ version is 2024.1.7 and it keeps removing the trailing spaces. I disabled it by switching the Settings | Editor | General > On Save > Remove trailing spaces on off.
Settings | Editor | General > On Save > Remove trailing spaces on