Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit ec450b8

Browse files
committed
Merge pull request hub4j#210 from oleg-nenashev/findbugs-cleanup
Cleanup issues discovered by FindBugs
2 parents 2d45ac5 + 79c5b2e commit ec450b8

33 files changed

+210
-54
lines changed

pom.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
<properties>
3030
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
<findbugs-maven-plugin.version>3.0.1</findbugs-maven-plugin.version>
32+
<findbugs-maven-plugin.failOnError>true</findbugs-maven-plugin.failOnError>
3133
</properties>
3234

3335
<build>
@@ -47,11 +49,11 @@
4749
<plugin>
4850
<groupId>org.codehaus.mojo</groupId>
4951
<artifactId>findbugs-maven-plugin</artifactId>
50-
<version>3.0.1</version>
52+
<version>${findbugs-maven-plugin.version}</version>
5153
<configuration>
5254
<xmlOutput>true</xmlOutput>
5355
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
54-
<failOnError>false</failOnError>
56+
<failOnError>${findbugs-maven-plugin.failOnError}</failOnError>
5557
</configuration>
5658
<executions>
5759
<execution>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@
2323
*/
2424
package org.kohsuke.github;
2525

26+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
27+
2628
/**
2729
* @author Kohsuke Kawaguchi
2830
*/
31+
@SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD",
32+
justification = "Being constructed by JSON deserialization")
2933
class DeleteToken {
3034
public String delete_token;
3135
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.kohsuke.github;
22

3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
34
import java.net.URL;
45
import java.util.Collection;
56
import java.util.Date;
@@ -59,6 +60,8 @@ public String getAppName() {
5960
return app.name;
6061
}
6162

63+
@SuppressFBWarnings(value = "NM_CONFUSING",
64+
justification = "It's a part of the library API, cannot be changed")
6265
public URL getApiURL() {
6366
return GitHub.parseURL(url);
6467
}
@@ -84,7 +87,8 @@ public URL getNoteUrl() {
8487
return this;
8588
}
8689

87-
90+
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD"},
91+
justification = "JSON API")
8892
private static class App {
8993
private String url;
9094
private String name;

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package org.kohsuke.github;
22

3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
35
/**
46
* A branch in a repository.
57
*
68
* @author Yusuke Kokubo
79
*/
10+
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
11+
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
812
public class GHBranch {
913
private GitHub root;
1014
private GHRepository owner;
@@ -13,7 +17,10 @@ public class GHBranch {
1317
private Commit commit;
1418

1519
public static class Commit {
16-
String sha,url;
20+
String sha;
21+
22+
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
23+
String url;
1724
}
1825

1926
public GitHub getRoot() {
@@ -37,7 +44,7 @@ public String getName() {
3744
public String getSHA1() {
3845
return commit.sha;
3946
}
40-
47+
4148
@Override
4249
public String toString() {
4350
final String url = owner != null ? owner.getUrl().toString() : "unknown";

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.kohsuke.github;
22

33
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
4+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
45

56
import java.io.IOException;
67
import java.net.URL;
@@ -16,6 +17,8 @@
1617
* @see GHRepository#getCommit(String)
1718
* @see GHCommitComment#getCommit()
1819
*/
20+
@SuppressFBWarnings(value = {"NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD"},
21+
justification = "JSON API")
1922
public class GHCommit {
2023
private GHRepository owner;
2124

@@ -24,6 +27,8 @@ public class GHCommit {
2427
/**
2528
* Short summary of this commit.
2629
*/
30+
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
31+
"NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD"}, justification = "JSON API")
2732
public static class ShortInfo {
2833
private GHAuthor author;
2934
private GHAuthor committer;
@@ -67,6 +72,8 @@ public static class Stats {
6772
/**
6873
* A file that was modified.
6974
*/
75+
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD",
76+
justification = "It's being initilized by JSON deserialization")
7077
public static class File {
7178
String status;
7279
int changes,additions,deletions;
@@ -104,6 +111,8 @@ public String getStatus() {
104111
/**
105112
* Full path in the repository.
106113
*/
114+
@SuppressFBWarnings(value = "NM_CONFUSING",
115+
justification = "It's a part of the library's API and cannot be renamed")
107116
public String getFileName() {
108117
return filename;
109118
}
@@ -147,13 +156,19 @@ public String getSha() {
147156
}
148157

149158
public static class Parent {
150-
String url,sha;
159+
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
160+
String url;
161+
String sha;
151162
}
152163

153164
static class User {
154165
// TODO: what if someone who doesn't have an account on GitHub makes a commit?
155-
String url,avatar_url,login,gravatar_id;
166+
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
167+
String url,avatar_url,gravatar_id;
168+
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
156169
int id;
170+
171+
String login;
157172
}
158173

159174
String url,sha;

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.kohsuke.github;
22

3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
34
import java.io.IOException;
45
import java.net.URL;
56
import java.util.Date;
@@ -12,6 +13,8 @@
1213
* @see GHCommit#listComments()
1314
* @see GHCommit#createComment(String, String, Integer, Integer)
1415
*/
16+
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
17+
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
1518
public class GHCommitComment extends GHObject {
1619
private GHRepository owner;
1720

@@ -22,8 +25,12 @@ public class GHCommitComment extends GHObject {
2225

2326
static class User {
2427
// TODO: what if someone who doesn't have an account on GitHub makes a commit?
25-
String url,avatar_url,login,gravatar_id;
28+
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
29+
String url,avatar_url,gravatar_id;
30+
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
2631
int id;
32+
33+
String login;
2734
}
2835

2936
public GHRepository getOwner() {
@@ -83,7 +90,7 @@ public GHCommit getCommit() throws IOException {
8390
* Updates the body of the commit message.
8491
*/
8592
public void update(String body) throws IOException {
86-
GHCommitComment r = new Requester(owner.root)
93+
new Requester(owner.root)
8794
.with("body", body)
8895
.method("PATCH").to(getApiTail(), GHCommitComment.class);
8996
this.body = body;

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.kohsuke.github;
22

33
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
4+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
45

56
import java.net.URL;
7+
import java.util.Arrays;
68
import java.util.Date;
79

810
/**
@@ -65,12 +67,20 @@ public Commit getMergeBaseCommit() {
6567
return merge_base_commit;
6668
}
6769

70+
/**
71+
* Gets an array of commits.
72+
* @return A copy of the array being stored in the class.
73+
*/
6874
public Commit[] getCommits() {
69-
return commits;
75+
return Arrays.copyOf(commits, commits.length);
7076
}
7177

78+
/**
79+
* Gets an array of commits.
80+
* @return A copy of the array being stored in the class.
81+
*/
7282
public GHCommit.File[] getFiles() {
73-
return files;
83+
return Arrays.copyOf(files, files.length);
7484
}
7585

7686
public GHCompare wrap(GHRepository owner) {
@@ -87,6 +97,8 @@ public GHCompare wrap(GHRepository owner) {
8797
* Compare commits had a child commit element with additional details we want to capture.
8898
* This extenstion of GHCommit provides that.
8999
*/
100+
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD"},
101+
justification = "JSON API")
90102
public static class Commit extends GHCommit {
91103

92104
private InnerCommit commit;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public String getPath() {
7676
* Use {@link #read()}
7777
*/
7878
public String getContent() throws IOException {
79-
return new String(DatatypeConverter.parseBase64Binary(getEncodedContent()));
79+
return new String(DatatypeConverter.parseBase64Binary(getEncodedContent()), getEncoding());
8080
}
8181

8282
/**
@@ -162,11 +162,11 @@ protected void wrapUp(GHContent[] page) {
162162
}
163163

164164
public GHContentUpdateResponse update(String newContent, String commitMessage) throws IOException {
165-
return update(newContent.getBytes(), commitMessage, null);
165+
return update(newContent.getBytes(getEncoding()), commitMessage, null);
166166
}
167167

168168
public GHContentUpdateResponse update(String newContent, String commitMessage, String branch) throws IOException {
169-
return update(newContent.getBytes(), commitMessage, branch);
169+
return update(newContent.getBytes(getEncoding()), commitMessage, branch);
170170
}
171171

172172
public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage) throws IOException {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.kohsuke.github;
22

33
import java.net.URL;
4+
import java.util.Locale;
45

56
public class GHDeploymentStatus extends GHObject {
67
private GHRepository owner;
@@ -28,8 +29,9 @@ public URL getDeploymentUrl() {
2829
public URL getRepositoryUrl() {
2930
return GitHub.parseURL(repository_url);
3031
}
32+
3133
public GHDeploymentState getState() {
32-
return GHDeploymentState.valueOf(state.toUpperCase());
34+
return GHDeploymentState.valueOf(state.toUpperCase(Locale.ENGLISH));
3335
}
3436

3537
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.kohsuke.github;
22

33
import java.io.IOException;
4+
import java.util.Locale;
45

56
public class GHDeploymentStatusBuilder {
67
private final Requester builder;
@@ -11,7 +12,7 @@ public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeployme
1112
this.repo = repo;
1213
this.deploymentId = deploymentId;
1314
this.builder = new Requester(repo.root);
14-
this.builder.with("state",state.toString().toLowerCase());
15+
this.builder.with("state",state.toString().toLowerCase(Locale.ENGLISH));
1516
}
1617

1718
public GHDeploymentStatusBuilder description(String description) {

0 commit comments

Comments
 (0)