Skip to content

Commit 8b7cd2b

Browse files
authored
Merge pull request #275 from xdev-software/fix-storage-crash-on-unknown-actions-value
Fix storage deserialization crash on unknown actions value
2 parents 4ed935d + af78b37 commit 8b7cd2b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.4.2
2+
* Fix storage deserialization crash on unknown actions value #273
3+
14
## 1.4.1
25
* Fix ``Add class qualifier to static member access outside declaring class`` not working correctly for ``switch`` statements #263
36

src/main/java/software/xdev/saveactions/model/Storage.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package software.xdev.saveactions.model;
22

33
import java.util.ArrayList;
4-
import java.util.EnumSet;
54
import java.util.HashSet;
65
import java.util.List;
76
import java.util.Objects;
@@ -18,9 +17,12 @@
1817

1918
@State(name = "SaveActionSettings", storages = {@com.intellij.openapi.components.Storage("saveactions_settings.xml")})
2019
@Service(Service.Level.PROJECT)
20+
@SuppressWarnings("PMD.UseEnumCollections") // Set must be nullable!
2121
public final class Storage implements PersistentStateComponent<Storage>
2222
{
2323
private boolean firstLaunch;
24+
// Must use a set that supports nullable values!
25+
// For example EnumSet will crash when encountering an unknown/null value
2426
private Set<Action> actions;
2527
private Set<String> exclusions;
2628
private Set<String> inclusions;
@@ -31,7 +33,7 @@ public final class Storage implements PersistentStateComponent<Storage>
3133
public Storage()
3234
{
3335
this.firstLaunch = true;
34-
this.actions = EnumSet.noneOf(Action.class);
36+
this.actions = new HashSet<>();
3537
this.exclusions = new HashSet<>();
3638
this.inclusions = new HashSet<>();
3739
this.configurationPath = null;
@@ -42,7 +44,7 @@ public Storage()
4244
public Storage(final Storage storage)
4345
{
4446
this.firstLaunch = storage.firstLaunch;
45-
this.actions = EnumSet.copyOf(storage.actions);
47+
this.actions = new HashSet<>(storage.actions);
4648
this.exclusions = new HashSet<>(storage.exclusions);
4749
this.inclusions = new HashSet<>(storage.inclusions);
4850
this.configurationPath = storage.configurationPath;

0 commit comments

Comments
 (0)