@@ -24,8 +24,8 @@ public final class VersionStateManager {
24
24
private final ExistenceStateIndex existenceStateIndex ;
25
25
private final ApiCoverageStateIndex apiCoverageStateIndex ;
26
26
private final Boolean isSetIgnoreFlag ;
27
- private final SupportedVersion currentVersion ;
28
- private final SupportedVersion targetVersion ;
27
+ private SupportedVersion currentVersion ;
28
+ private SupportedVersion targetVersion ;
29
29
private final List <SupportedVersion > versionsToLoad ;
30
30
31
31
/**
@@ -48,6 +48,7 @@ public static synchronized VersionStateManager getInstance(
48
48
)) {
49
49
instance = new VersionStateManager (project );
50
50
}
51
+
51
52
return instance ;
52
53
}
53
54
@@ -115,6 +116,8 @@ private VersionStateManager(final @NotNull Project project) {
115
116
currentVersion = settingsService .getCurrentVersionOrDefault ();
116
117
targetVersion = settingsService .getTargetVersion ();
117
118
versionsToLoad = new LinkedList <>();
119
+ // Correct settings if stored data isn't valid for current supported versions state.
120
+ correctSettings (project );
118
121
119
122
deprecationStateIndex = new DeprecationStateIndex ();
120
123
compute (deprecationStateIndex );
@@ -126,6 +129,35 @@ private VersionStateManager(final @NotNull Project project) {
126
129
compute (apiCoverageStateIndex );
127
130
}
128
131
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
+
129
161
/**
130
162
* Check if current instance is valid for settings.
131
163
*
0 commit comments