Skip to content

Commit

Permalink
Some DoubleCheckedLocking smells resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonad07 committed Nov 15, 2023
1 parent 1b3763e commit bfe15f6
Showing 1 changed file with 57 additions and 44 deletions.
101 changes: 57 additions & 44 deletions src/main/java/org/gitlab4j/api/GitLabApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -833,16 +833,19 @@ class VersionApi extends AbstractApi {
* @return the ApplicationsApi instance owned by this GitLabApi instance
*/
public ApplicationsApi getApplicationsApi() {

if (applicationsApi == null) {
ApplicationsApi localRef = applicationsApi;

if (localRef == null) {
synchronized (this) {
if (applicationsApi == null) {
applicationsApi = new ApplicationsApi(this);
localRef = applicationsApi;
if (localRef == null) {
localRef = new ApplicationsApi(this);
applicationsApi = localRef;
}
}
}

return (applicationsApi);
return localRef;
}

/**
Expand All @@ -852,16 +855,19 @@ public ApplicationsApi getApplicationsApi() {
* @return the ApplicationsApi instance owned by this GitLabApi instance
*/
public ApplicationSettingsApi getApplicationSettingsApi() {
ApplicationSettingsApi localRef = applicationSettingsApi;

if (applicationSettingsApi == null) {
if (localRef == null) {
synchronized (this) {
if (applicationSettingsApi == null) {
applicationSettingsApi = new ApplicationSettingsApi(this);
localRef = applicationSettingsApi;
if (localRef == null) {
localRef = new ApplicationSettingsApi(this);
applicationSettingsApi = localRef;
}
}
}

return (applicationSettingsApi);
return localRef;
}

/**
Expand Down Expand Up @@ -947,16 +953,18 @@ public CommitsApi getCommitsApi() {
* @return the ContainerRegistryApi instance owned by this GitLabApi instance
*/
public ContainerRegistryApi getContainerRegistryApi() {

if (containerRegistryApi == null) {
ContainerRegistryApi localInstance = containerRegistryApi;

if (localInstance == null) {
synchronized (this) {
if (containerRegistryApi == null) {
containerRegistryApi = new ContainerRegistryApi(this);
localInstance = containerRegistryApi;
if (localInstance == null) {
containerRegistryApi = localInstance = new ContainerRegistryApi(this);
}
}
}

return (containerRegistryApi);
return localInstance;
}

/**
Expand Down Expand Up @@ -1222,16 +1230,17 @@ public JobApi getJobApi() {
}

public LabelsApi getLabelsApi() {

if (labelsApi == null) {
LabelsApi result = labelsApi;
if (result == null) {
synchronized (this) {
if (labelsApi == null) {
labelsApi = new LabelsApi(this);
result = labelsApi;
if (result == null) {
result = new LabelsApi(this);
labelsApi = result;
}
}
}

return (labelsApi);
return result;
}

/**
Expand Down Expand Up @@ -1336,16 +1345,16 @@ public MilestonesApi getMilestonesApi() {
* @return the NamespaceApi instance owned by this GitLabApi instance
*/
public NamespaceApi getNamespaceApi() {

if (namespaceApi == null) {
NamespaceApi result = namespaceApi;
if (result == null) {
synchronized (this) {
if (namespaceApi == null) {
namespaceApi = new NamespaceApi(this);
result = namespaceApi;
if (result == null) {
namespaceApi = result = new NamespaceApi(this);
}
}
}

return (namespaceApi);
return result;
}

/**
Expand Down Expand Up @@ -1507,16 +1516,17 @@ public ReleasesApi getReleasesApi() {
* @return the RepositoryApi instance owned by this GitLabApi instance
*/
public RepositoryApi getRepositoryApi() {

if (repositoryApi == null) {
RepositoryApi localRef = repositoryApi;
if (localRef == null) {
synchronized (this) {
if (repositoryApi == null) {
repositoryApi = new RepositoryApi(this);
localRef = repositoryApi;
if (localRef == null) {
localRef = new RepositoryApi(this);
repositoryApi = localRef;
}
}
}

return (repositoryApi);
return localRef;
}

/**
Expand Down Expand Up @@ -1621,16 +1631,17 @@ public SearchApi getSearchApi() {
* @return the ServicesApi instance owned by this GitLabApi instance
*/
public ServicesApi getServicesApi() {

if (servicesApi == null) {
ServicesApi result = servicesApi;
if (result == null) {
synchronized (this) {
if (servicesApi == null) {
servicesApi = new ServicesApi(this);
result = servicesApi;
if (result == null) {
result = new ServicesApi(this);
servicesApi = result;
}
}
}

return (servicesApi);
return result;
}

/**
Expand Down Expand Up @@ -1714,15 +1725,17 @@ public SnippetsApi getSnippetApi() {
* @return the TodosApi instance owned by this GitLabApi instance
*/
public TodosApi getTodosApi() {
if (todosApi == null) {
TodosApi result = todosApi;
if (result == null) {
synchronized (this) {
if (todosApi == null) {
todosApi = new TodosApi(this);
result = todosApi;
if (result == null) {
result = new TodosApi(this);
todosApi = result;
}
}
}

return todosApi;
return result;
}

/**
Expand Down

0 comments on commit bfe15f6

Please sign in to comment.