Skip to content

Commit b3a9274

Browse files
authored
[CQ] stop storing property service instance (#8118)
A bit pedantic but generally good practice and easy to fix. (There's also no real reason to store the instance.) ![image](https://github.com/user-attachments/assets/529be20b-134e-4c41-8093-7928c676bab7) Inspection motivation: > Such services' assignments contribute to global state and make it impossible to tear down an application and set up another one in tests, therefore, repeated tests in the same process may fail. The only exception is an explicit constructor call to store dummy/default instances. > The recommended way to avoid storing services is to retrieve a service locally. Alternatively, one can wrap it in java.util.function.Supplier (Java, Kotlin) or convert the property to a function (Kotlin). --- - [x] I’ve reviewed the contributor guide and applied the relevant portions to this PR. <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide]([https://github.com/dart-lang/sdk/blob/main/CONTRIBUTING.md](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Dart contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`. - Java and Kotlin contributions should strive to follow Java and Kotlin best practices ([discussion](#8098)). </details>
1 parent 29ce7fb commit b3a9274

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

flutter-idea/src/io/flutter/survey/FlutterSurveyService.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ public class FlutterSurveyService {
2121
private static final String FLUTTER_LAST_SURVEY_CONTENT_CHECK_KEY = "FLUTTER_LAST_SURVEY_CONTENT_CHECK_KEY";
2222
private static final long CHECK_INTERVAL_IN_MS = TimeUnit.HOURS.toMillis(40);
2323
private static final String CONTENT_URL = "https://storage.googleapis.com/flutter-uxr/surveys/flutter-survey-metadata.json";
24-
private static final PropertiesComponent properties = PropertiesComponent.getInstance();
2524
private static final Logger LOG = Logger.getInstance(FlutterSurveyService.class);
26-
private static FlutterSurvey cachedSurvey;
25+
private static @Nullable FlutterSurvey cachedSurvey;
2726

2827
private static boolean timeToUpdateCachedContent() {
2928
// Don't check more often than daily.
3029
final long currentTimeMillis = System.currentTimeMillis();
31-
final long lastCheckedMillis = properties.getLong(FLUTTER_LAST_SURVEY_CONTENT_CHECK_KEY, 0);
32-
final boolean timeToUpdateCache = currentTimeMillis - lastCheckedMillis >= CHECK_INTERVAL_IN_MS;
33-
if (timeToUpdateCache) {
34-
properties.setValue(FLUTTER_LAST_SURVEY_CONTENT_CHECK_KEY, String.valueOf(currentTimeMillis));
35-
return true;
30+
final PropertiesComponent properties = PropertiesComponent.getInstance();
31+
if (properties != null) {
32+
final long lastCheckedMillis = properties.getLong(FLUTTER_LAST_SURVEY_CONTENT_CHECK_KEY, 0);
33+
final boolean timeToUpdateCache = currentTimeMillis - lastCheckedMillis >= CHECK_INTERVAL_IN_MS;
34+
if (timeToUpdateCache) {
35+
properties.setValue(FLUTTER_LAST_SURVEY_CONTENT_CHECK_KEY, String.valueOf(currentTimeMillis));
36+
return true;
37+
}
3638
}
3739
return false;
3840
}

0 commit comments

Comments
 (0)