Skip to content

Commit 201394e

Browse files
Karl-Philipp Richterhenryju
authored andcommitted
Log response which cannot to be parsed in BootstrapIndexDownloader in order to be able to investigate successful however unexpected responses, e.g. from OAuth login forms
1 parent 09e6070 commit 201394e

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

api/src/main/java/org/sonarsource/scanner/api/internal/BootstrapIndexDownloader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Collection<JarEntry> getIndex() {
4444
return parse(index);
4545
}
4646

47-
private static Collection<JarEntry> parse(String index) {
48-
Collection<JarEntry> entries = new ArrayList<>();
47+
private Collection<JarEntry> parse(String index) {
48+
final Collection<JarEntry> entries = new ArrayList<>();
4949

5050
String[] lines = index.split("[\r\n]+");
5151
for (String line : lines) {
@@ -56,6 +56,7 @@ private static Collection<JarEntry> parse(String index) {
5656
String hash = libAndHash[1];
5757
entries.add(new JarEntry(filename, hash));
5858
} catch (Exception e) {
59+
logger.error("Failed bootstrap index response: " + index);
5960
throw new IllegalStateException("Fail to parse entry in bootstrap index: " + line);
6061
}
6162
}

api/src/test/java/org/sonarsource/scanner/api/internal/BootstrapIndexDownloaderTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ public void test_invalid_index() throws Exception {
7272
bootstrapIndexDownloader.getIndex();
7373
}
7474

75+
@Test
76+
public void test_handles_empty_line_gracefully() throws Exception {
77+
when(connection.downloadString("/batch/index")).thenReturn("\n");
78+
79+
Collection<JarEntry> index = bootstrapIndexDownloader.getIndex();
80+
assertThat(index).hasSize(0);
81+
verify(connection, times(1)).downloadString("/batch/index");
82+
}
83+
84+
@Test(expected = IllegalStateException.class)
85+
public void test_handles_empty_string_with_exception() throws Exception {
86+
when(connection.downloadString("/batch/index")).thenReturn("");
87+
88+
bootstrapIndexDownloader.getIndex();
89+
}
90+
7591
@Test
7692
public void should_fail() throws IOException {
7793
when(connection.downloadString("/batch/index")).thenThrow(new IOException("io error"));

0 commit comments

Comments
 (0)