Skip to content

Commit

Permalink
Merge pull request #210 from oleg-nenashev/findbugs-cleanup
Browse files Browse the repository at this point in the history
Cleanup issues discovered by FindBugs
  • Loading branch information
oleg-nenashev committed Jul 24, 2015
2 parents 2d45ac5 + 79c5b2e commit ec450b8
Show file tree
Hide file tree
Showing 33 changed files with 210 additions and 54 deletions.
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<findbugs-maven-plugin.version>3.0.1</findbugs-maven-plugin.version>
<findbugs-maven-plugin.failOnError>true</findbugs-maven-plugin.failOnError>
</properties>

<build>
Expand All @@ -47,11 +49,11 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<version>${findbugs-maven-plugin.version}</version>
<configuration>
<xmlOutput>true</xmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
<failOnError>false</failOnError>
<failOnError>${findbugs-maven-plugin.failOnError}</failOnError>
</configuration>
<executions>
<execution>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/kohsuke/github/DeleteToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
*/
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* @author Kohsuke Kawaguchi
*/
@SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD",
justification = "Being constructed by JSON deserialization")
class DeleteToken {
public String delete_token;
}
6 changes: 5 additions & 1 deletion src/main/java/org/kohsuke/github/GHAuthorization.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.net.URL;
import java.util.Collection;
import java.util.Date;
Expand Down Expand Up @@ -59,6 +60,8 @@ public String getAppName() {
return app.name;
}

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


@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD"},
justification = "JSON API")
private static class App {
private String url;
private String name;
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/kohsuke/github/GHBranch.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* A branch in a repository.
*
* @author Yusuke Kokubo
*/
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
public class GHBranch {
private GitHub root;
private GHRepository owner;
Expand All @@ -13,7 +17,10 @@ public class GHBranch {
private Commit commit;

public static class Commit {
String sha,url;
String sha;

@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
String url;
}

public GitHub getRoot() {
Expand All @@ -37,7 +44,7 @@ public String getName() {
public String getSHA1() {
return commit.sha;
}

@Override
public String toString() {
final String url = owner != null ? owner.getUrl().toString() : "unknown";
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/org/kohsuke/github/GHCommit.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kohsuke.github;

import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.net.URL;
Expand All @@ -16,6 +17,8 @@
* @see GHRepository#getCommit(String)
* @see GHCommitComment#getCommit()
*/
@SuppressFBWarnings(value = {"NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD"},
justification = "JSON API")
public class GHCommit {
private GHRepository owner;

Expand All @@ -24,6 +27,8 @@ public class GHCommit {
/**
* Short summary of this commit.
*/
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD"}, justification = "JSON API")
public static class ShortInfo {
private GHAuthor author;
private GHAuthor committer;
Expand Down Expand Up @@ -67,6 +72,8 @@ public static class Stats {
/**
* A file that was modified.
*/
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD",
justification = "It's being initilized by JSON deserialization")
public static class File {
String status;
int changes,additions,deletions;
Expand Down Expand Up @@ -104,6 +111,8 @@ public String getStatus() {
/**
* Full path in the repository.
*/
@SuppressFBWarnings(value = "NM_CONFUSING",
justification = "It's a part of the library's API and cannot be renamed")
public String getFileName() {
return filename;
}
Expand Down Expand Up @@ -147,13 +156,19 @@ public String getSha() {
}

public static class Parent {
String url,sha;
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
String url;
String sha;
}

static class User {
// TODO: what if someone who doesn't have an account on GitHub makes a commit?
String url,avatar_url,login,gravatar_id;
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
String url,avatar_url,gravatar_id;
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
int id;

String login;
}

String url,sha;
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/kohsuke/github/GHCommitComment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.net.URL;
import java.util.Date;
Expand All @@ -12,6 +13,8 @@
* @see GHCommit#listComments()
* @see GHCommit#createComment(String, String, Integer, Integer)
*/
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
public class GHCommitComment extends GHObject {
private GHRepository owner;

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

static class User {
// TODO: what if someone who doesn't have an account on GitHub makes a commit?
String url,avatar_url,login,gravatar_id;
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
String url,avatar_url,gravatar_id;
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
int id;

String login;
}

public GHRepository getOwner() {
Expand Down Expand Up @@ -83,7 +90,7 @@ public GHCommit getCommit() throws IOException {
* Updates the body of the commit message.
*/
public void update(String body) throws IOException {
GHCommitComment r = new Requester(owner.root)
new Requester(owner.root)
.with("body", body)
.method("PATCH").to(getApiTail(), GHCommitComment.class);
this.body = body;
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/org/kohsuke/github/GHCompare.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.kohsuke.github;

import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.net.URL;
import java.util.Arrays;
import java.util.Date;

/**
Expand Down Expand Up @@ -65,12 +67,20 @@ public Commit getMergeBaseCommit() {
return merge_base_commit;
}

/**
* Gets an array of commits.
* @return A copy of the array being stored in the class.
*/
public Commit[] getCommits() {
return commits;
return Arrays.copyOf(commits, commits.length);
}

/**
* Gets an array of commits.
* @return A copy of the array being stored in the class.
*/
public GHCommit.File[] getFiles() {
return files;
return Arrays.copyOf(files, files.length);
}

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

private InnerCommit commit;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/kohsuke/github/GHContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public String getPath() {
* Use {@link #read()}
*/
public String getContent() throws IOException {
return new String(DatatypeConverter.parseBase64Binary(getEncodedContent()));
return new String(DatatypeConverter.parseBase64Binary(getEncodedContent()), getEncoding());
}

/**
Expand Down Expand Up @@ -162,11 +162,11 @@ protected void wrapUp(GHContent[] page) {
}

public GHContentUpdateResponse update(String newContent, String commitMessage) throws IOException {
return update(newContent.getBytes(), commitMessage, null);
return update(newContent.getBytes(getEncoding()), commitMessage, null);
}

public GHContentUpdateResponse update(String newContent, String commitMessage, String branch) throws IOException {
return update(newContent.getBytes(), commitMessage, branch);
return update(newContent.getBytes(getEncoding()), commitMessage, branch);
}

public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessage) throws IOException {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/kohsuke/github/GHDeploymentStatus.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kohsuke.github;

import java.net.URL;
import java.util.Locale;

public class GHDeploymentStatus extends GHObject {
private GHRepository owner;
Expand Down Expand Up @@ -28,8 +29,9 @@ public URL getDeploymentUrl() {
public URL getRepositoryUrl() {
return GitHub.parseURL(repository_url);
}

public GHDeploymentState getState() {
return GHDeploymentState.valueOf(state.toUpperCase());
return GHDeploymentState.valueOf(state.toUpperCase(Locale.ENGLISH));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kohsuke.github;

import java.io.IOException;
import java.util.Locale;

public class GHDeploymentStatusBuilder {
private final Requester builder;
Expand All @@ -11,7 +12,7 @@ public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeployme
this.repo = repo;
this.deploymentId = deploymentId;
this.builder = new Requester(repo.root);
this.builder.with("state",state.toString().toLowerCase());
this.builder.with("state",state.toString().toLowerCase(Locale.ENGLISH));
}

public GHDeploymentStatusBuilder description(String description) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/kohsuke/github/GHEmail.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
*/
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;


/**
* Represents an email of GitHub.
*
* @author Kelly Campbell
*/
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD", "NP_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD"}, justification = "JSON API")
public class GHEmail {

protected String email;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/kohsuke/github/GHEventInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import java.util.Date;

import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Represents an event.
*
* @author Kohsuke Kawaguchi
*/
@SuppressFBWarnings(value = "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", justification = "JSON API")
public class GHEventInfo {
private GitHub root;

Expand All @@ -27,8 +29,12 @@ public class GHEventInfo {
/**
* Inside the event JSON model, GitHub uses a slightly different format.
*/
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "JSON API")
public static class GHEventRepository {
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
private int id;
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
private String url; // repository API URL
private String name; // owner/repo
}
Expand All @@ -55,10 +61,14 @@ public Date getCreatedAt() {
/**
* Repository where the change was made.
*/
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
justification = "The field comes from JSON deserialization")
public GHRepository getRepository() throws IOException {
return root.getRepository(repo.name);
}

@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
justification = "The field comes from JSON deserialization")
public GHUser getActor() throws IOException {
return root.getUser(actor.getLogin());
}
Expand All @@ -70,6 +80,8 @@ public String getActorLogin() throws IOException {
return actor.getLogin();
}

@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" },
justification = "The field comes from JSON deserialization")
public GHOrganization getOrganization() throws IOException {
return (org==null || org.getLogin()==null) ? null : root.getOrganization(org.getLogin());
}
Expand Down
Loading

0 comments on commit ec450b8

Please sign in to comment.