File tree Expand file tree Collapse file tree
main/java/org/sonarsource/scanner/api/internal
test/java/org/sonarsource/scanner/api/internal Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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" ));
You can’t perform that action at this time.
0 commit comments