Skip to content

Commit

Permalink
FindBugs: Add CheckForNull annotations where such null check is actua…
Browse files Browse the repository at this point in the history
…lly required
  • Loading branch information
oleg-nenashev committed Sep 19, 2016
1 parent 1a6f1d2 commit 43be53b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 5 deletions.
Expand Up @@ -10,6 +10,8 @@
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

/**
* @author Gregory Boissinot
Expand Down Expand Up @@ -40,6 +42,7 @@ public String getPropertiesContent() {
return propertiesContent;
}

@CheckForNull
@SuppressWarnings("deprecation")
public Map<String, String> getPropertiesContentMap(Map<String, String> currentEnvVars) {

Expand Down Expand Up @@ -67,7 +70,9 @@ public Map<String, String> getPropertiesContentMap(Map<String, String> currentEn

/**
* Fix CR/LF and always make it Unix style.
* @return String with fixed line endings. May return {@code null} only for {@code null} input
*/
@Nullable
protected String fixCrLf(String s) {
if (s == null) {
return null;
Expand Down
Expand Up @@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.CheckForNull;

/**
* @author Gregory Boissinot
Expand Down Expand Up @@ -245,6 +246,7 @@ public void buildEnvVars(Map<String, String> env) {
};
}

@CheckForNull
private Node getNode() {
Computer computer = Computer.currentComputer();
if (computer == null) {
Expand All @@ -253,6 +255,7 @@ private Node getNode() {
return computer.getNode();
}

@CheckForNull
private FilePath getNodeRootPath() {
Node node = getNode();
if (node != null) {
Expand Down
Expand Up @@ -7,6 +7,7 @@

import java.io.Serializable;
import java.util.Map;
import jenkins.model.Jenkins;

/**
* @author Gregory Boissinot
Expand All @@ -21,11 +22,11 @@ public abstract class EnvInjectJobPropertyContributor implements ExtensionPoint,
public abstract Map<String, String> getEnvVars(AbstractBuild build, TaskListener listener) throws EnvInjectException;

public Descriptor<EnvInjectJobPropertyContributor> getDescriptor() {
return Hudson.getInstance().getDescriptor(getClass());
return Jenkins.getActiveInstance().getDescriptor(getClass());
}

@SuppressWarnings("unused")
public static DescriptorExtensionList<EnvInjectJobPropertyContributor, EnvInjectJobPropertyContributorDescriptor> all() {
return Hudson.getInstance().getDescriptorList(EnvInjectJobPropertyContributor.class);
return Jenkins.getActiveInstance().getDescriptorList(EnvInjectJobPropertyContributor.class);
}
}
Expand Up @@ -16,6 +16,7 @@

import static com.google.common.base.Joiner.on;
import java.util.Locale;
import javax.annotation.CheckForNull;
import static org.apache.commons.lang.StringUtils.isNotBlank;


Expand Down Expand Up @@ -81,6 +82,7 @@ private static Map<String, String> buildCauseEnvironmentVariables(String envBase
return triggerVars;
}

@CheckForNull
@SuppressWarnings(value = "deprecation")
private static String getTriggerName(Cause cause) {
if (SCMTrigger.SCMTriggerCause.class.isInstance(cause)) {
Expand Down
Expand Up @@ -22,7 +22,9 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* @author Gregory Boissinot
Expand Down Expand Up @@ -246,7 +248,8 @@ public Map<String, String> removeUnsetVars(Map<String, String> envVars) {
return result;
}

private String removeUnsetVars(String value) {
@Nullable
private String removeUnsetVars(@CheckForNull String value) {

if (value == null) {
return null;
Expand Down
Expand Up @@ -14,6 +14,7 @@
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.annotation.CheckForNull;

/**
* @author Gregory Boissinot
Expand Down Expand Up @@ -63,7 +64,7 @@ private void maskPasswordsEnvInjectIfAny(AbstractBuild build, EnvInjectLogger lo
}
}


@CheckForNull
private EnvInjectPasswordWrapper getEnvInjectPasswordWrapper(AbstractBuild build) throws EnvInjectException {

DescribableList<BuildWrapper, Descriptor<BuildWrapper>> wrappersProject;
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import jenkins.model.Jenkins;

/**
Expand Down Expand Up @@ -121,6 +122,7 @@ public Map<String, String> getBuildVariables(AbstractBuild build, EnvInjectLogge
return result;
}

@CheckForNull
@SuppressWarnings("unchecked")
public EnvInjectJobProperty getEnvInjectJobProperty(AbstractBuild build) {
if (build == null) {
Expand Down
Expand Up @@ -2,13 +2,16 @@

import java.io.Serializable;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

/**
* @author Gregory Boissinot
*/
public class PropertiesGetter implements Serializable {

public String getPropertiesContentFromMapObject(Map<String, String> propertiesContent) {
@Nullable
public String getPropertiesContentFromMapObject(@CheckForNull Map<String, String> propertiesContent) {

if (propertiesContent == null) {
return null;
Expand Down
Expand Up @@ -11,6 +11,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import javax.annotation.CheckForNull;

/**
* @author Gregory Boissinot
Expand Down Expand Up @@ -79,6 +80,7 @@ private Map<String, String> getVars(String content, Map<String, String> currentE
return result;
}

@CheckForNull
private String processElement(Object prop, Map<String, String> currentEnvVars) {
String macroProcessedElement = Util.replaceMacro(String.valueOf(prop), currentEnvVars);
if (macroProcessedElement == null) {
Expand Down

0 comments on commit 43be53b

Please sign in to comment.