From af78b37859a24ae841600f08fb2bacf07ae5edba Mon Sep 17 00:00:00 2001 From: AB Date: Tue, 5 Aug 2025 11:14:06 +0200 Subject: [PATCH] Fix storage deserialization crash on unknown actions value --- CHANGELOG.md | 3 +++ .../java/software/xdev/saveactions/model/Storage.java | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c0e92d..c8df564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.4.2 +* Fix storage deserialization crash on unknown actions value #273 + ## 1.4.1 * Fix ``Add class qualifier to static member access outside declaring class`` not working correctly for ``switch`` statements #263 diff --git a/src/main/java/software/xdev/saveactions/model/Storage.java b/src/main/java/software/xdev/saveactions/model/Storage.java index a8f86a0..7036a99 100644 --- a/src/main/java/software/xdev/saveactions/model/Storage.java +++ b/src/main/java/software/xdev/saveactions/model/Storage.java @@ -1,7 +1,6 @@ package software.xdev.saveactions.model; import java.util.ArrayList; -import java.util.EnumSet; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -18,9 +17,12 @@ @State(name = "SaveActionSettings", storages = {@com.intellij.openapi.components.Storage("saveactions_settings.xml")}) @Service(Service.Level.PROJECT) +@SuppressWarnings("PMD.UseEnumCollections") // Set must be nullable! public final class Storage implements PersistentStateComponent { private boolean firstLaunch; + // Must use a set that supports nullable values! + // For example EnumSet will crash when encountering an unknown/null value private Set actions; private Set exclusions; private Set inclusions; @@ -31,7 +33,7 @@ public final class Storage implements PersistentStateComponent public Storage() { this.firstLaunch = true; - this.actions = EnumSet.noneOf(Action.class); + this.actions = new HashSet<>(); this.exclusions = new HashSet<>(); this.inclusions = new HashSet<>(); this.configurationPath = null; @@ -42,7 +44,7 @@ public Storage() public Storage(final Storage storage) { this.firstLaunch = storage.firstLaunch; - this.actions = EnumSet.copyOf(storage.actions); + this.actions = new HashSet<>(storage.actions); this.exclusions = new HashSet<>(storage.exclusions); this.inclusions = new HashSet<>(storage.inclusions); this.configurationPath = storage.configurationPath;