From 5dc83cf2bf1ba8e945986a7e9fb156332ab138ee Mon Sep 17 00:00:00 2001 From: Ruben Dijkstra Date: Wed, 7 Oct 2015 09:38:48 +0200 Subject: [PATCH] Overzealous FindBugs changes. Charsets that are standard on the JRE are try-lookuped, bridge methods were removed and a stream that would be closed later is closed explicitly --- src/main/java/org/kohsuke/github/GHObject.java | 15 +++++++++++++++ src/main/java/org/kohsuke/github/GHRelease.java | 9 ++------- src/main/java/org/kohsuke/github/GitHub.java | 8 ++------ src/main/java/org/kohsuke/github/Requester.java | 4 +++- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHObject.java b/src/main/java/org/kohsuke/github/GHObject.java index 50aa0a6a86..270ac1fcc5 100644 --- a/src/main/java/org/kohsuke/github/GHObject.java +++ b/src/main/java/org/kohsuke/github/GHObject.java @@ -29,6 +29,11 @@ public Date getCreatedAt() throws IOException { return GitHub.parseDate(created_at); } + @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getCreatedAt") + private Object createdAtStr(Date id, Class type) { + return created_at; + } + /** * API URL of this object. */ @@ -57,4 +62,14 @@ public Date getUpdatedAt() throws IOException { public int getId() { return id; } + + @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getId") + private Object intToString(int id, Class type) { + return String.valueOf(id); + } + + @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getHtmlUrl") + private Object urlToString(URL url, Class type) { + return url==null ? null : url.toString(); + } } diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 901bb8f359..b61dc62b38 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -129,14 +129,9 @@ public GHAsset uploadAsset(File file, String contentType) throws IOException { String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s", owner.getApiTailUrl(""), getId(), file.getName()); - FileInputStream istream = new FileInputStream(file); - try { - return builder.contentType(contentType) - .with(istream) + return builder.contentType(contentType) + .with(new FileInputStream(file)) .to(url, GHAsset.class).wrap(this); - } finally { - istream.close(); - } } public List getAssets() throws IOException { diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 9e638bb4aa..2eaef53ceb 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -47,6 +47,7 @@ import java.util.TimeZone; import java.util.concurrent.TimeUnit; +import org.apache.commons.codec.Charsets; import org.apache.commons.codec.binary.Base64; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -129,12 +130,7 @@ public class GitHub { } else { if (password!=null) { String authorization = (login + ':' + password); - final Charset charset; - try { - charset = Charset.forName("UTF-8"); - } catch (Exception ex) { - throw new IOException("UTF-8 encoding is not supported", ex); - } + Charset charset = Charsets.UTF_8; encodedAuthorization = "Basic "+new String(Base64.encodeBase64(authorization.getBytes(charset)), charset); } else {// anonymous access encodedAuthorization = null; diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 78ead072d9..b8b53b78cd 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -53,6 +53,8 @@ import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; +import javax.annotation.WillClose; + import static java.util.Arrays.asList; import static org.kohsuke.github.GitHub.*; @@ -143,7 +145,7 @@ public Requester with(String key, Map value) { return _with(key, value); } - public Requester with(InputStream body) { + public Requester with(@WillClose/*later*/ InputStream body) { this.body = body; return this; }