How to make IntelliJ 2021 format single-line throwing lambda as in IntelliJ 2020?

Viewed 161

I am using IntelliJ code style format definition published at https://github.com/airlift/codestyle/blob/f20834967969cdafce461ee203788e567f842e1e/IntelliJIdea2019/Airlift.xml

IntelliJ 2020.3.4 (and I think all previous versions I used) would format single line throwing lambda like this

Consumer<String> unimplemented = value -> { throw new UnsupportedOperationException(); };

While formatting the above, IntelliJ 2021.2.3 removes spaces inside curly braces:

Consumer<String> unimplemented = value -> {throw new UnsupportedOperationException();};

How to make IntelliJ 2021.2.3 format the code the way older versions did?

1 Answers

In the Code Style settings, go to the "Spaces" tab and find "Within -> Code Braces". Turn it on.

enter image description here

Or if you want to edit the code style XML directly, you can add:

<option name="SPACE_WITHIN_BRACES" value="true" />

in the block

<codeStyleSettings language="JAVA">
    ...
</codeStyleSettings>
Related