Skip to content

Commit

Permalink
[JENKINS-45055] - Cleanup issues reported by FindBugs
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-nenashev committed Jun 22, 2017
1 parent b3f4b15 commit af1bcc6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/main/java/org/jenkinsci/lib/envinject/EnvInjectAction.java
@@ -1,6 +1,7 @@
package org.jenkinsci.lib.envinject;

import com.google.common.collect.Maps;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.AbstractBuild;
import hudson.model.Job;
import hudson.model.Run;
Expand Down Expand Up @@ -72,6 +73,8 @@ public EnvInjectAction(@Nonnull AbstractBuild build,
* @param envMap Environment Map
* @since 0.25
*/
@SuppressFBWarnings(value = "NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR",
justification = "RunAction2 handlers in the core should do it in all valid use-cases")
public EnvInjectAction(@CheckForNull Map<String, String> envMap) {
this.envMap = envMap;
}
Expand Down Expand Up @@ -128,8 +131,10 @@ private Object writeReplace() throws ObjectStreamException {
try {
EnvInjectSavable dao = new EnvInjectSavable();

Map<String, String> toWrite = envMap != null ? envMap : Collections.<String, String>emptyMap();

if (rootDir == null) {
dao.saveEnvironment(build.getRootDir(), Maps.transformEntries(envMap,
dao.saveEnvironment(build.getRootDir(), Maps.transformEntries(toWrite,
new Maps.EntryTransformer<String, String, String>() {
public String transformEntry(String key, String value) {
return (sensibleVariables != null && sensibleVariables.contains(key))
Expand All @@ -139,7 +144,7 @@ public String transformEntry(String key, String value) {
return this;
}

dao.saveEnvironment(rootDir, envMap);
dao.saveEnvironment(rootDir, toWrite);
} catch (Throwable e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -173,6 +178,8 @@ public Run<?,?> getOwner() {
}

@SuppressWarnings("unused")
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE",
justification = "Data migration")
private Object readResolve() throws ObjectStreamException {

if (resultVariables != null) {
Expand Down
Expand Up @@ -38,13 +38,13 @@ public Action getEnvInjectAction(AbstractBuild<?, ?> build) {
}
}
} catch (ClassNotFoundException e) {
LOGGER.log(Level.FINEST, String.format("hudson.matrix.MatrixRun is not installed", e));
LOGGER.log(Level.FINEST, "hudson.matrix.MatrixRun is not installed", e);
} catch (NoSuchMethodException e) {
LOGGER.log(Level.WARNING, String.format("The method getParentBuild does not exist for hudson.matrix.MatrixRun", e));
LOGGER.log(Level.WARNING, "The method getParentBuild does not exist for hudson.matrix.MatrixRun", e);
} catch (IllegalAccessException e) {
LOGGER.log(Level.WARNING, String.format("There was a problem in the invocation of getParentBuild in hudson.matrix.MatrixRun", e));
LOGGER.log(Level.WARNING, "There was a problem in the invocation of getParentBuild in hudson.matrix.MatrixRun", e);
} catch (InvocationTargetException e) {
LOGGER.log(Level.WARNING, String.format("There was a problem in the invocation of getParentBuild in hudson.matrix.MatrixRun", e));
LOGGER.log(Level.WARNING, "There was a problem in the invocation of getParentBuild in hudson.matrix.MatrixRun", e);
}
actions = build.getActions();
for (Action action : actions) {
Expand Down
@@ -1,5 +1,6 @@
package org.jenkinsci.lib.envinject.service;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.jenkinsci.lib.envinject.EnvInjectException;

import java.io.*;
Expand All @@ -21,6 +22,7 @@ public class EnvInjectSavable {
private static final String ENVINJECT_TXT_FILENAME = "injectedEnvVars.txt";
private static final String TOKEN = "=";

@SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "Deprecated class")
public Map<String, String> getEnvironment(File envInjectBaseDir) throws EnvInjectException {

if (envInjectBaseDir == null) {
Expand All @@ -34,7 +36,7 @@ public Map<String, String> getEnvironment(File envInjectBaseDir) throws EnvInjec
return null;
}
fileReader = new FileReader(f);
Map result = new HashMap();
final Map<String, String> result = new HashMap<String, String>();
fromTxt(fileReader, result);
return result;
} catch (FileNotFoundException fne) {
Expand All @@ -50,6 +52,7 @@ public Map<String, String> getEnvironment(File envInjectBaseDir) throws EnvInjec
}
}

@SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "Deprecated class")
public void saveEnvironment(File rootDir, Map<String, String> envMap) throws EnvInjectException {
FileWriter fileWriter = null;
try {
Expand Down Expand Up @@ -99,7 +102,7 @@ private void fromTxt(FileReader fileReader, Map<String, String> result) throws E

private void toTxt(Map<String, String> envMap, FileWriter fw) throws IOException {
for (Map.Entry<String, String> entry : envMap.entrySet()) {
fw.write(String.format("%s%s%s\n", entry.getKey(), TOKEN, entry.getValue()));
fw.write(String.format("%s%s%s%n", entry.getKey(), TOKEN, entry.getValue()));
}
}

Expand Down

0 comments on commit af1bcc6

Please sign in to comment.