Skip to content

Commit

Permalink
Fix Spotbugs warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-tkachenko-datadog committed Sep 12, 2024
1 parent 513ec33 commit c699f39
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ public Map<String, String> toEnvironmentVariables() {

@Override
public Descriptor<DatadogClientConfiguration> getDescriptor() {
return Jenkins.getInstanceOrNull().getDescriptorOrDie(DatadogAgentConfiguration.class);
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null) {
throw new RuntimeException("Jenkins instance is null");
}
return jenkins.getDescriptorOrDie(DatadogAgentConfiguration.class);
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ public Map<String, String> toEnvironmentVariables() {

@Override
public Descriptor<DatadogClientConfiguration> getDescriptor() {
return Jenkins.getInstanceOrNull().getDescriptorOrDie(DatadogApiConfiguration.class);
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null) {
throw new RuntimeException("Jenkins instance is null");
}
return jenkins.getDescriptorOrDie(DatadogApiConfiguration.class);
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public abstract class DatadogClientConfiguration implements Describable<DatadogC

public static abstract class DatadogClientConfigurationDescriptor extends Descriptor<DatadogClientConfiguration> {
public static List<DatadogClientConfigurationDescriptor> all() {
List<DatadogClientConfigurationDescriptor> descriptors = Jenkins.getInstanceOrNull().getDescriptorList(DatadogClientConfiguration.class);
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null) {
throw new RuntimeException("Jenkins instance is null");
}
List<DatadogClientConfigurationDescriptor> descriptors = jenkins.getDescriptorList(DatadogClientConfiguration.class);
List<DatadogClientConfigurationDescriptor> sortedDescriptors = new ArrayList<>(descriptors);
sortedDescriptors.sort(Comparator.comparingInt(DatadogClientConfigurationDescriptor::getOrder));
return sortedDescriptors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public abstract class DatadogIntake implements Describable<DatadogIntake>, Seria

public static abstract class DatadogIntakeDescriptor extends Descriptor<DatadogIntake> {
public static List<DatadogIntakeDescriptor> all() {
List<DatadogIntakeDescriptor> descriptors = Jenkins.getInstanceOrNull().getDescriptorList(DatadogIntake.class);
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null) {
throw new RuntimeException("Jenkins instance is null");
}
List<DatadogIntakeDescriptor> descriptors = jenkins.getDescriptorList(DatadogIntake.class);
List<DatadogIntakeDescriptor> sortedDescriptors = new ArrayList<>(descriptors);
sortedDescriptors.sort(Comparator.comparingInt(DatadogIntakeDescriptor::getOrder));
return sortedDescriptors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ public String getSiteName() {

@Override
public Descriptor<DatadogIntake> getDescriptor() {
return Jenkins.getInstanceOrNull().getDescriptorOrDie(DatadogIntakeSite.class);
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null) {
throw new RuntimeException("Jenkins instance is null");
}
return jenkins.getDescriptorOrDie(DatadogIntakeSite.class);
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ public String getSiteName() {

@Override
public Descriptor<DatadogIntake> getDescriptor() {
return Jenkins.getInstanceOrNull().getDescriptorOrDie(DatadogIntakeUrls.class);
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null) {
throw new RuntimeException("Jenkins instance is null");
}
return jenkins.getDescriptorOrDie(DatadogIntakeUrls.class);
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public abstract class DatadogApiKey implements Describable<DatadogApiKey>, Seria

public static abstract class DatadogApiKeyDescriptor extends Descriptor<DatadogApiKey> {
public static List<DatadogApiKeyDescriptor> all() {
List<DatadogApiKeyDescriptor> descriptors = Jenkins.getInstanceOrNull().getDescriptorList(DatadogApiKey.class);
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null) {
throw new RuntimeException("Jenkins instance is null");
}
List<DatadogApiKeyDescriptor> descriptors = jenkins.getDescriptorList(DatadogApiKey.class);
List<DatadogApiKeyDescriptor> sortedDescriptors = new ArrayList<>(descriptors);
sortedDescriptors.sort(Comparator.comparingInt(DatadogApiKeyDescriptor::getOrder));
return sortedDescriptors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ static StringCredentials getCredentialFromId(String credentialId) {

@Override
public Descriptor<DatadogApiKey> getDescriptor() {
return Jenkins.getInstanceOrNull().getDescriptorOrDie(DatadogCredentialsApiKey.class);
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null) {
throw new RuntimeException("Jenkins instance is null");
}
return jenkins.getDescriptorOrDie(DatadogCredentialsApiKey.class);
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public Secret getKey() {

@Override
public Descriptor<DatadogApiKey> getDescriptor() {
return Jenkins.getInstanceOrNull().getDescriptorOrDie(DatadogTextApiKey.class);
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null) {
throw new RuntimeException("Jenkins instance is null");
}
return jenkins.getDescriptorOrDie(DatadogTextApiKey.class);
}

@Extension
Expand Down

0 comments on commit c699f39

Please sign in to comment.