You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ResourceSet implement Iterable, but its implementation is flawed. You can only iterate through its elements once, even if you get a new iterator.
ResourceSet implements Iterable and has inner class ResourceSetIterator for its iterator internally. The implementation of ResourceSetIterator uses class variables from ResourceSet, specifically ResourceSet.iterator and ResourceSet.processed. Because of this, even though ResourceSet.iterator() method does create a new instance of ResourceSetIterator, since the processed count and the iterator in the outer class never get reset, it is functionally still at the end (hasNext() method returns false).
Steps to Reproduce
Get a ResourceSet
Iterate through the elements - works
Iterate through the elements again - never goes into the loop
Code Snippet
importcom.twilio.Twilio;
importcom.twilio.base.ResourceSet;
importcom.twilio.rest.monitor.v1.Alert;
publicclassExample {
publicstaticvoidmain(String[] args) {
Twilio.init("my_account_sid", "my_auth_token");
ResourceSet<Alert> alerts = Alert.reader().limit(5).read();
System.out.println("Before first loop:");
for(Alertrecord : alerts) {
System.out.println(" First loop - " + record.getSid());
}
System.out.println("Before second loop:");
for(Alertrecord : alerts) {
System.out.println(" Second loop - " + record.getSid());
}
System.out.println("After second loop");
}
}
Exception/Log
Output from above code - second loop had no output:
Before first loop:
First loop - NO06bc5d5591ecd607e21f5f3436dc22b0
First loop - NO48d74ff1f40c2ef88d4c74dbc0d39907
First loop - NO27183f081d5903afb84ec8b5e3a1b7be
First loop - NO8426237981e0ea63bab859157c1c9ca8
First loop - NOc2ef3b0918b79d2a62a0efc8290a1885
Before second loop:
After second loop
Technical details:
twilio-java version: 8.30.1
java version: openjdk version "1.8.0_322"
The text was updated successfully, but these errors were encountered:
Hi @rjbird77, this issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.
Issue Summary
ResourceSet implement Iterable, but its implementation is flawed. You can only iterate through its elements once, even if you get a new iterator.
ResourceSet implements Iterable and has inner class ResourceSetIterator for its iterator internally. The implementation of ResourceSetIterator uses class variables from ResourceSet, specifically ResourceSet.iterator and ResourceSet.processed. Because of this, even though ResourceSet.iterator() method does create a new instance of ResourceSetIterator, since the processed count and the iterator in the outer class never get reset, it is functionally still at the end (hasNext() method returns false).
Steps to Reproduce
Code Snippet
Exception/Log
Technical details:
The text was updated successfully, but these errors were encountered: