Skip to content

Commit bfe15f6

Browse files
committed
Some DoubleCheckedLocking smells resolved
1 parent 1b3763e commit bfe15f6

File tree

1 file changed

+57
-44
lines changed

1 file changed

+57
-44
lines changed

src/main/java/org/gitlab4j/api/GitLabApi.java

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -833,16 +833,19 @@ class VersionApi extends AbstractApi {
833833
* @return the ApplicationsApi instance owned by this GitLabApi instance
834834
*/
835835
public ApplicationsApi getApplicationsApi() {
836-
837-
if (applicationsApi == null) {
836+
ApplicationsApi localRef = applicationsApi;
837+
838+
if (localRef == null) {
838839
synchronized (this) {
839-
if (applicationsApi == null) {
840-
applicationsApi = new ApplicationsApi(this);
840+
localRef = applicationsApi;
841+
if (localRef == null) {
842+
localRef = new ApplicationsApi(this);
843+
applicationsApi = localRef;
841844
}
842845
}
843846
}
844847

845-
return (applicationsApi);
848+
return localRef;
846849
}
847850

848851
/**
@@ -852,16 +855,19 @@ public ApplicationsApi getApplicationsApi() {
852855
* @return the ApplicationsApi instance owned by this GitLabApi instance
853856
*/
854857
public ApplicationSettingsApi getApplicationSettingsApi() {
858+
ApplicationSettingsApi localRef = applicationSettingsApi;
855859

856-
if (applicationSettingsApi == null) {
860+
if (localRef == null) {
857861
synchronized (this) {
858-
if (applicationSettingsApi == null) {
859-
applicationSettingsApi = new ApplicationSettingsApi(this);
862+
localRef = applicationSettingsApi;
863+
if (localRef == null) {
864+
localRef = new ApplicationSettingsApi(this);
865+
applicationSettingsApi = localRef;
860866
}
861867
}
862868
}
863869

864-
return (applicationSettingsApi);
870+
return localRef;
865871
}
866872

867873
/**
@@ -947,16 +953,18 @@ public CommitsApi getCommitsApi() {
947953
* @return the ContainerRegistryApi instance owned by this GitLabApi instance
948954
*/
949955
public ContainerRegistryApi getContainerRegistryApi() {
950-
951-
if (containerRegistryApi == null) {
956+
ContainerRegistryApi localInstance = containerRegistryApi;
957+
958+
if (localInstance == null) {
952959
synchronized (this) {
953-
if (containerRegistryApi == null) {
954-
containerRegistryApi = new ContainerRegistryApi(this);
960+
localInstance = containerRegistryApi;
961+
if (localInstance == null) {
962+
containerRegistryApi = localInstance = new ContainerRegistryApi(this);
955963
}
956964
}
957965
}
958-
959-
return (containerRegistryApi);
966+
967+
return localInstance;
960968
}
961969

962970
/**
@@ -1222,16 +1230,17 @@ public JobApi getJobApi() {
12221230
}
12231231

12241232
public LabelsApi getLabelsApi() {
1225-
1226-
if (labelsApi == null) {
1233+
LabelsApi result = labelsApi;
1234+
if (result == null) {
12271235
synchronized (this) {
1228-
if (labelsApi == null) {
1229-
labelsApi = new LabelsApi(this);
1236+
result = labelsApi;
1237+
if (result == null) {
1238+
result = new LabelsApi(this);
1239+
labelsApi = result;
12301240
}
12311241
}
12321242
}
1233-
1234-
return (labelsApi);
1243+
return result;
12351244
}
12361245

12371246
/**
@@ -1336,16 +1345,16 @@ public MilestonesApi getMilestonesApi() {
13361345
* @return the NamespaceApi instance owned by this GitLabApi instance
13371346
*/
13381347
public NamespaceApi getNamespaceApi() {
1339-
1340-
if (namespaceApi == null) {
1348+
NamespaceApi result = namespaceApi;
1349+
if (result == null) {
13411350
synchronized (this) {
1342-
if (namespaceApi == null) {
1343-
namespaceApi = new NamespaceApi(this);
1351+
result = namespaceApi;
1352+
if (result == null) {
1353+
namespaceApi = result = new NamespaceApi(this);
13441354
}
13451355
}
13461356
}
1347-
1348-
return (namespaceApi);
1357+
return result;
13491358
}
13501359

13511360
/**
@@ -1507,16 +1516,17 @@ public ReleasesApi getReleasesApi() {
15071516
* @return the RepositoryApi instance owned by this GitLabApi instance
15081517
*/
15091518
public RepositoryApi getRepositoryApi() {
1510-
1511-
if (repositoryApi == null) {
1519+
RepositoryApi localRef = repositoryApi;
1520+
if (localRef == null) {
15121521
synchronized (this) {
1513-
if (repositoryApi == null) {
1514-
repositoryApi = new RepositoryApi(this);
1522+
localRef = repositoryApi;
1523+
if (localRef == null) {
1524+
localRef = new RepositoryApi(this);
1525+
repositoryApi = localRef;
15151526
}
15161527
}
15171528
}
1518-
1519-
return (repositoryApi);
1529+
return localRef;
15201530
}
15211531

15221532
/**
@@ -1621,16 +1631,17 @@ public SearchApi getSearchApi() {
16211631
* @return the ServicesApi instance owned by this GitLabApi instance
16221632
*/
16231633
public ServicesApi getServicesApi() {
1624-
1625-
if (servicesApi == null) {
1634+
ServicesApi result = servicesApi;
1635+
if (result == null) {
16261636
synchronized (this) {
1627-
if (servicesApi == null) {
1628-
servicesApi = new ServicesApi(this);
1637+
result = servicesApi;
1638+
if (result == null) {
1639+
result = new ServicesApi(this);
1640+
servicesApi = result;
16291641
}
16301642
}
16311643
}
1632-
1633-
return (servicesApi);
1644+
return result;
16341645
}
16351646

16361647
/**
@@ -1714,15 +1725,17 @@ public SnippetsApi getSnippetApi() {
17141725
* @return the TodosApi instance owned by this GitLabApi instance
17151726
*/
17161727
public TodosApi getTodosApi() {
1717-
if (todosApi == null) {
1728+
TodosApi result = todosApi;
1729+
if (result == null) {
17181730
synchronized (this) {
1719-
if (todosApi == null) {
1720-
todosApi = new TodosApi(this);
1731+
result = todosApi;
1732+
if (result == null) {
1733+
result = new TodosApi(this);
1734+
todosApi = result;
17211735
}
17221736
}
17231737
}
1724-
1725-
return todosApi;
1738+
return result;
17261739
}
17271740

17281741
/**

0 commit comments

Comments
 (0)