Skip to content

Commit

Permalink
Issue #261: handle 204 no content correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Jun 4, 2016
1 parent 16a0f8e commit 0415326
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/kohsuke/github/Requester.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ private <T> T parse(Class<T> type, T instance) throws IOException {
if (responseCode == 304) {
return null; // special case handling for 304 unmodified, as the content will be ""
}
if (responseCode == 204 && type.isArray()) {
// no content
return type.cast(Array.newInstance(type.getComponentType(),0));
}

r = new InputStreamReader(wrapStream(uc.getInputStream()), "UTF-8");
String data = IOUtils.toString(r);
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/Foo.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHRepository.Contributor;
import org.kohsuke.github.GHUser;
import org.kohsuke.github.GitHub;

Expand All @@ -9,11 +10,10 @@
*/
public class Foo {
public static void main(String[] args) throws Exception {
Collection<GHRepository> lst = GitHub.connect().getUser("kohsuke").getRepositories().values();
for (GHRepository r : lst) {
System.out.println(r.getName());
GitHub gh = GitHub.connect();
for (Contributor c : gh.getRepository("kohsuke/yo").listContributors()) {
System.out.println(c);
}
System.out.println(lst.size());
}

private static void testRateLimit() throws Exception {
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/kohsuke/github/RepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ public void listLanguages() throws IOException {
String mainLanguage = r.getLanguage();
assertTrue(r.listLanguages().containsKey(mainLanguage));
}

@Test // Issue #261
public void listEmptyContributors() throws IOException {
GitHub gh = GitHub.connect();
for (Contributor c : gh.getRepository("github-api-test-org/empty").listContributors()) {
System.out.println(c);
}
}
}

0 comments on commit 0415326

Please sign in to comment.