arturobernalg commented on code in PR #694:
URL: 
https://github.com/apache/httpcomponents-core/pull/694#discussion_r3937215387


##########
httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicListHeaderIterator.java:
##########
@@ -81,6 +81,13 @@ public BasicListHeaderIterator(final List<? extends Header> 
headers, final Strin
         this.lastIndex = -1;
     }
 
+    BasicListHeaderIterator(final List<? extends Header> headers, final int 
currentIndex, final String name) {

Review Comment:
   @ok2c 
   The new `BasicListHeaderIterator` constructor does not initialize 
`lastIndex`, so it defaults to 0. Calling remove() before next() then removes 
the first header instead of throwing IllegalStateException. I confirmed it with 
a regression test. Initializing `lastIndex` to -1 fixes it.
   
   Otherwise, the change looks good to me.
   
   Test that prove.
   
   ```
   
   @Test
   void testIteratorByNameRemoveBeforeNext() {
       final HeaderGroup headerGroup = new HeaderGroup();
       final Header headerA = new BasicHeader("a", "a-one");
       final Header headerB = new BasicHeader("b", "b-one");
       headerGroup.setHeaders(headerA, headerB);
   
       final Iterator<Header> iterator = headerGroup.headerIterator("b");
   
       Assertions.assertThrows(IllegalStateException.class, iterator::remove);
       Assertions.assertArrayEquals(
               new Header[] { headerA, headerB },
               headerGroup.getHeaders());
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to