Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Findbugs cleanup #244

Merged
merged 7 commits into from Sep 1, 2015
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -55,7 +55,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.net.id>rsandell</java.net.id>
<powermock.version>1.5.4</powermock.version>
<findbugs.version>2.5.5</findbugs.version>
<findbugs.version>3.0.2</findbugs.version>
<checkstyle.version>2.13</checkstyle.version>
</properties>

Expand Down
Expand Up @@ -75,7 +75,7 @@ public int compare(GerritTriggeredEvent o1, GerritTriggeredEvent o2) {
if (o1 == null && o2 != null) {
return -1;
}
return new Integer(o1.hashCode()).compareTo(o2.hashCode());
return Integer.valueOf(o1.hashCode()).compareTo(o2.hashCode());
}
}

Expand Down
Expand Up @@ -40,6 +40,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is Java 1.7, but this plugin is still based on a Jenkins core version that supports Java 1.6. So until we go >=1.612 of Jenkins core we shouldn't use Java 1.7 features.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 0b44bfc

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -88,20 +89,20 @@ private static Pattern buildLinePattern() {
+ "|" + SHORTNAME_FILE
+ "|" + SHORTNAME_FORBIDDEN_FILE
+ ")";
String operators = "(";
StringBuilder operators = new StringBuilder("(");
boolean firstoperator = true;
for (CompareType type : CompareType.values()) {
if (!firstoperator) {
operators += "|";
operators.append("|");
}
operators += type.getOperator();
operators.append(type.getOperator());
firstoperator = false;
}
operators += ")";
operators.append(")");

return Pattern.compile(projectBranchFile
+ "\\s*"
+ operators
+ operators.toString()
+ "\\s*(.+)$");
}

Expand Down Expand Up @@ -246,7 +247,7 @@ public static List<GerritProject> fetch(String gerritTriggerConfigUrl, String se
BufferedReader reader = null;
try {
instream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(instream));
reader = new BufferedReader(new InputStreamReader(instream, StandardCharsets.UTF_8));
return readAndParseTriggerConfig(reader, serverName);
} finally {
if (reader != null) {
Expand Down
Expand Up @@ -44,6 +44,7 @@

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Constructor;
import java.nio.charset.StandardCharsets;
import java.util.List;

import org.apache.commons.codec.binary.Base64;
Expand Down Expand Up @@ -260,7 +261,7 @@ private void setOrCreateParameterValue(List<ParameterValue> parameters, String v
constructor = clazz.getConstructor(types);
parameter = constructor.newInstance(args);
parameters.add(parameter);
} catch (Exception ex) {
} catch (ReflectiveOperationException ex) {
parameter = null;
}
}
Expand Down Expand Up @@ -391,7 +392,7 @@ public static void setOrCreateParameters(GerritTriggeredEvent gerritEvent, Job p
try {
byte[] encodedBytes = Base64.encodeBase64(commitMessage.getBytes("UTF-8"));
GERRIT_CHANGE_COMMIT_MESSAGE.setOrCreateBase64EncodedStringParameterValue(
parameters, new String(encodedBytes), escapeQuotes);
parameters, new String(encodedBytes, StandardCharsets.UTF_8), escapeQuotes);
} catch (UnsupportedEncodingException uee) {
logger.error("Failed to encode commit message as Base64: ", uee);
}
Expand Down
Expand Up @@ -357,32 +357,26 @@ protected String getEventsFromEventsLogPlugin(IGerritHudsonTriggerConfig config,
if (statusCode == HttpURLConnection.HTTP_OK) {
try {
HttpEntity entity = execute.getEntity();
ContentType contentType;
if (entity == null) {
logger.warn("Not successful at requesting missed events from {} plugin. Null entity returned)",
statusCode);
}
contentType = ContentType.get(entity);
if (contentType == null) {
contentType = ContentType.DEFAULT_TEXT;
}
Charset charset = contentType.getCharset();
if (charset == null) {
charset = Charset.defaultCharset();
if (entity != null) {
ContentType contentType = ContentType.get(entity);
if (contentType == null) {
contentType = ContentType.DEFAULT_TEXT;
}
Charset charset = contentType.getCharset();
if (charset == null) {
charset = Charset.defaultCharset();
}
InputStream bodyStream = entity.getContent();
String body = IOUtils.toString(bodyStream, charset.name());
logger.debug(body);
return body;
}
InputStream bodyStream = entity.getContent();
String body = IOUtils.toString(bodyStream, charset.name());
logger.debug(body);
return body;
} catch (IOException ioe) {
logger.warn(ioe.getMessage(), ioe);
logger.warn("Not successful at requesting missed events from {} plugin. (errorcode: {})",
EVENTS_LOG_PLUGIN_NAME, statusCode);
}
} else {
logger.warn("Not successful at requesting missed events from {} plugin. (errorcode: {})",
EVENTS_LOG_PLUGIN_NAME, statusCode);
}
logger.warn("Not successful at requesting missed events from {} plugin. (errorcode: {})",
EVENTS_LOG_PLUGIN_NAME, statusCode);
return "";
}

Expand Down
Expand Up @@ -123,7 +123,7 @@ public CauseOfBlockage canRun(Item item) {
if (item.isBuildable()) {
return null;
}
Integer itemId = new Integer(item.id);
Integer itemId = Integer.valueOf(item.id);
if (blockedItems.containsKey(itemId)) {
BlockedItem blockedItem = blockedItems.get(itemId);
if (blockedItem.canRunWithTimeoutCheck()) {
Expand Down