File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
main/java/org/jsoup/nodes
test/java/org/jsoup/nodes Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 1717import java .util .Iterator ;
1818import java .util .List ;
1919import java .util .Map ;
20+ import java .util .NoSuchElementException ;
2021import java .util .Set ;
2122
2223import static org .jsoup .internal .Normalizer .lowerCase ;
@@ -367,6 +368,7 @@ public boolean hasNext() {
367368 @ Override
368369 public Attribute next () {
369370 checkModified ();
371+ if (i >= size ) throw new NoSuchElementException ();
370372 final Attribute attr = new Attribute (keys [i ], (String ) vals [i ], Attributes .this );
371373 i ++;
372374 return attr ;
Original file line number Diff line number Diff line change 77import java .util .Iterator ;
88import java .util .List ;
99import java .util .Map ;
10+ import java .util .NoSuchElementException ;
1011
1112import static org .junit .jupiter .api .Assertions .*;
1213
@@ -143,6 +144,29 @@ public void testIteratorSkipsInternal() {
143144 assertEquals (2 , seen );
144145 }
145146
147+ @ Test void iteratorThrows () {
148+ Attributes attrs = new Attributes ();
149+ attrs .put ("One" , "one" ).put ("Two" , "two" );
150+
151+ Iterator <Attribute > it = attrs .iterator ();
152+ int seen = 0 ;
153+ while (it .hasNext ()) {
154+ it .next ();
155+ seen ++;
156+ }
157+ assertFalse (it .hasNext ());
158+ assertEquals (2 , seen );
159+
160+ boolean threw = false ;
161+ try {
162+ Attribute next = it .next ();
163+ assertNotNull (next ); // not hit
164+ } catch (NoSuchElementException e ) {
165+ threw = true ;
166+ }
167+ assertTrue (threw );
168+ }
169+
146170 @ Test
147171 public void testListSkipsInternal () {
148172 Attributes a = new Attributes ();
You can’t perform that action at this time.
0 commit comments