@@ -24,8 +24,8 @@ public final class VersionStateManager {
2424 private final ExistenceStateIndex existenceStateIndex ;
2525 private final ApiCoverageStateIndex apiCoverageStateIndex ;
2626 private final Boolean isSetIgnoreFlag ;
27- private final SupportedVersion currentVersion ;
28- private final SupportedVersion targetVersion ;
27+ private SupportedVersion currentVersion ;
28+ private SupportedVersion targetVersion ;
2929 private final List <SupportedVersion > versionsToLoad ;
3030
3131 /**
@@ -48,6 +48,7 @@ public static synchronized VersionStateManager getInstance(
4848 )) {
4949 instance = new VersionStateManager (project );
5050 }
51+
5152 return instance ;
5253 }
5354
@@ -115,6 +116,8 @@ private VersionStateManager(final @NotNull Project project) {
115116 currentVersion = settingsService .getCurrentVersionOrDefault ();
116117 targetVersion = settingsService .getTargetVersion ();
117118 versionsToLoad = new LinkedList <>();
119+ // Correct settings if stored data isn't valid for current supported versions state.
120+ correctSettings (project );
118121
119122 deprecationStateIndex = new DeprecationStateIndex ();
120123 compute (deprecationStateIndex );
@@ -126,6 +129,35 @@ private VersionStateManager(final @NotNull Project project) {
126129 compute (apiCoverageStateIndex );
127130 }
128131
132+ /**
133+ * Correct settings if corrupted.
134+ *
135+ * @param project Project
136+ */
137+ @ SuppressWarnings ("PMD.AvoidSynchronizedAtMethodLevel" )
138+ private synchronized void correctSettings (final @ NotNull Project project ) {
139+ final UctSettingsService settingsService = UctSettingsService .getInstance (project );
140+ final List <String > allVersions = SupportedVersion .getSupportedVersions ();
141+
142+ if (currentVersion == null
143+ || SupportedVersion .getVersion (currentVersion .getVersion ()) == null ) {
144+ final SupportedVersion correctCurrentVersion = SupportedVersion .getVersion (
145+ allVersions .get (0 )
146+ );
147+ settingsService .setCurrentVersion (correctCurrentVersion );
148+ currentVersion = correctCurrentVersion ;
149+ }
150+
151+ if (targetVersion == null
152+ || SupportedVersion .getVersion (targetVersion .getVersion ()) == null ) {
153+ final SupportedVersion correctTargetVersion = SupportedVersion .getVersion (
154+ allVersions .get (allVersions .size () - 1 )
155+ );
156+ settingsService .setTargetVersion (correctTargetVersion );
157+ targetVersion = correctTargetVersion ;
158+ }
159+ }
160+
129161 /**
130162 * Check if current instance is valid for settings.
131163 *
0 commit comments