Skip to content

Commit 5dc83cf

Browse files
committed
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
1 parent 6516b20 commit 5dc83cf

4 files changed

Lines changed: 22 additions & 14 deletions

File tree

src/main/java/org/kohsuke/github/GHObject.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public Date getCreatedAt() throws IOException {
2929
return GitHub.parseDate(created_at);
3030
}
3131

32+
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getCreatedAt")
33+
private Object createdAtStr(Date id, Class type) {
34+
return created_at;
35+
}
36+
3237
/**
3338
* API URL of this object.
3439
*/
@@ -57,4 +62,14 @@ public Date getUpdatedAt() throws IOException {
5762
public int getId() {
5863
return id;
5964
}
65+
66+
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getId")
67+
private Object intToString(int id, Class type) {
68+
return String.valueOf(id);
69+
}
70+
71+
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getHtmlUrl")
72+
private Object urlToString(URL url, Class type) {
73+
return url==null ? null : url.toString();
74+
}
6075
}

src/main/java/org/kohsuke/github/GHRelease.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,9 @@ public GHAsset uploadAsset(File file, String contentType) throws IOException {
129129

130130
String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s",
131131
owner.getApiTailUrl(""), getId(), file.getName());
132-
FileInputStream istream = new FileInputStream(file);
133-
try {
134-
return builder.contentType(contentType)
135-
.with(istream)
132+
return builder.contentType(contentType)
133+
.with(new FileInputStream(file))
136134
.to(url, GHAsset.class).wrap(this);
137-
} finally {
138-
istream.close();
139-
}
140135
}
141136

142137
public List<GHAsset> getAssets() throws IOException {

src/main/java/org/kohsuke/github/GitHub.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.TimeZone;
4848
import java.util.concurrent.TimeUnit;
4949

50+
import org.apache.commons.codec.Charsets;
5051
import org.apache.commons.codec.binary.Base64;
5152

5253
import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -129,12 +130,7 @@ public class GitHub {
129130
} else {
130131
if (password!=null) {
131132
String authorization = (login + ':' + password);
132-
final Charset charset;
133-
try {
134-
charset = Charset.forName("UTF-8");
135-
} catch (Exception ex) {
136-
throw new IOException("UTF-8 encoding is not supported", ex);
137-
}
133+
Charset charset = Charsets.UTF_8;
138134
encodedAuthorization = "Basic "+new String(Base64.encodeBase64(authorization.getBytes(charset)), charset);
139135
} else {// anonymous access
140136
encodedAuthorization = null;

src/main/java/org/kohsuke/github/Requester.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
import java.util.regex.Pattern;
5454
import java.util.zip.GZIPInputStream;
5555

56+
import javax.annotation.WillClose;
57+
5658
import static java.util.Arrays.asList;
5759
import static org.kohsuke.github.GitHub.*;
5860

@@ -143,7 +145,7 @@ public Requester with(String key, Map<String, String> value) {
143145
return _with(key, value);
144146
}
145147

146-
public Requester with(InputStream body) {
148+
public Requester with(@WillClose/*later*/ InputStream body) {
147149
this.body = body;
148150
return this;
149151
}

0 commit comments

Comments
 (0)