Issue #261: handle 204 no content correctly

This commit is contained in:
Kohsuke Kawaguchi
2016-06-03 20:27:29 -07:00
parent 16a0f8ece0
commit 0415326d09
3 changed files with 16 additions and 4 deletions

View File

@@ -512,6 +512,10 @@ class Requester {
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);

View File

@@ -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;
@@ -9,11 +10,10 @@ import java.util.Collection;
*/
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 {

View File

@@ -50,4 +50,12 @@ public class RepositoryTest extends AbstractGitHubApiTestBase {
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);
}
}
}