Skip to content

Commit 57d22e5

Browse files
alanvjimgoog
authored andcommitted
Synchronize access to the AidlLanguage constructor and registration
Fixes: 280346978 Test: N/A Change-Id: I781fe8943492b6c71a4ab9958952287d2385c2b4
1 parent c777c73 commit 57d22e5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lint-checks/src/main/java/androidx/com/android/tools/idea/lang/aidl/AidlLanguage.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@
2222
* Android IDL Language.
2323
*/
2424
public class AidlLanguage extends Language {
25+
private static final Object INSTANCE_LOCK = new Object();
26+
2527
public static final Language INSTANCE = getOrCreate();
2628

2729
private static Language getOrCreate() {
28-
Language lang = Language.findLanguageByID(ID);
29-
if (lang != null) {
30-
return lang;
30+
// The Language class is not thread-safe, so this is a best-effort to avoid a race condition
31+
// during our own access across multiple lint worker threads.
32+
synchronized (INSTANCE_LOCK) {
33+
Language lang = Language.findLanguageByID(ID);
34+
if (lang != null) {
35+
return lang;
36+
}
37+
return new AidlLanguage();
3138
}
32-
return new AidlLanguage();
3339
}
3440

3541
@NonNls private static final String ID = "AIDL";

0 commit comments

Comments
 (0)