Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator.next() is ignored for List<Value<T>> #993

Closed
volgin opened this issue May 6, 2016 · 4 comments
Closed

Iterator.next() is ignored for List<Value<T>> #993

volgin opened this issue May 6, 2016 · 4 comments
Assignees

Comments

@volgin
Copy link

volgin commented May 6, 2016

This code produces an endless loop:

List<Value<Long>> releases = entity.getList("releases");
System.out.println(releases.size());    // prints 1 

while (releases.iterator().hasNext()) {
    Value<Long> value = releases.iterator().next();
    System.out.println(value.get());   // prints correct value over and over
}

@ajkannan
Copy link

ajkannan commented May 6, 2016

The condition in the while loop creates a new iterator for each iteration of the loop, which causes the infinite loop. If you save the iterator you create before the while loop rather than creating a new one each time, the problem should be fixed.

@volgin
Copy link
Author

volgin commented May 6, 2016

Is this documented? Typically I don't expect a new iterator created when I simply pass a reference to it.

-----Original Message-----
From: "Ajay Kannan" notifications@github.com
Sent: ‎5/‎6/‎2016 6:57 PM
To: "GoogleCloudPlatform/gcloud-java" gcloud-java@noreply.github.com
Cc: "volgin" volgin@spiraluniverse.com; "Author" author@noreply.github.com
Subject: Re: [GoogleCloudPlatform/gcloud-java] Iterator.next() is ignored forList<Value> (#993)

The condition in the while loop creates a new iterator for each iteration of the loop, which causes the infinite loop. If you save the iterator you create before the while loop rather than creating a new one each time, the problem should be fixed.

You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

@ajkannan
Copy link

ajkannan commented May 6, 2016

releases is of type java.util.List (which is Iterable). The contract of Iterable's iterator() is to return a new iterator over all items in the list. The code you provide would also loop endlessly if you used some other generic type (e.g. Integer), like below:

List<Integer> releases = Collections.singletonList(1);
System.out.println(releases.size());

while (releases.iterator().hasNext()) {
    int value = releases.iterator().next();
    System.out.println(value);
}

@volgin
Copy link
Author

volgin commented May 6, 2016

OK. Thank you for a quick response, and feel free to close this issue.

@ajkannan ajkannan closed this as completed May 6, 2016
github-actions bot pushed a commit that referenced this issue Jul 18, 2022
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
Source-Link: googleapis/synthtool@72c64b7
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:b2e8f445ca0e605d4bbefbfdbdf7335692d75cf1647af62243828dcc0ea4e690
github-actions bot pushed a commit that referenced this issue Sep 15, 2022
…ow to v4.8.1 (#993)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-dialogflow](https://github.com/googleapis/java-dialogflow) | `4.8.0` -> `4.8.1` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-dialogflow/4.8.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-dialogflow/4.8.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-dialogflow/4.8.1/compatibility-slim/4.8.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-dialogflow/4.8.1/confidence-slim/4.8.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/java-dialogflow</summary>

### [`v4.8.1`](https://github.com/googleapis/java-dialogflow/blob/HEAD/CHANGELOG.md#&#8203;481-httpsgithubcomgoogleapisjava-dialogflowcomparev480v481-2022-09-06)

[Compare Source](https://github.com/googleapis/java-dialogflow/compare/v4.8.0...v4.8.1)

##### Dependencies

-   Update dependency com.google.cloud ([b0b6edd](https://github.com/googleapis/java-dialogflow/commit/b0b6eddf78598b8e162afbf20553605245f36b67))
-   Update dependency com.google.cloud ([3b9ae1d](https://github.com/googleapis/java-dialogflow/commit/3b9ae1d36eec1394b0705a1c95a5f1bf1373ac04))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-dialogflow).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4xOTIuMyIsInVwZGF0ZWRJblZlciI6IjMyLjE5Mi4zIn0=-->
github-actions bot pushed a commit that referenced this issue Oct 4, 2022
🤖 I have created a release *beep* *boop*
---


### Updating meta-information for bleeding-edge SNAPSHOT release.

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
github-actions bot pushed a commit that referenced this issue Oct 5, 2022
🤖 I have created a release *beep* *boop*
---


## [3.1.2](https://github.com/googleapis/java-vision/compare/v3.1.1...v3.1.2) (2022-10-03)


### Documentation

* Update comments for image annotator OCR models ([#983](https://github.com/googleapis/java-vision/issues/983)) ([5c408fe](https://github.com/googleapis/java-vision/commit/5c408fef37777fb9899d9190b89896318f64d262))


### Dependencies

* Update dependency com.google.cloud:google-cloud-core to v2.8.12 ([#984](https://github.com/googleapis/java-vision/issues/984)) ([59f683c](https://github.com/googleapis/java-vision/commit/59f683ce1933b80a3b6256d9cf7f737c689ba711))
* Update dependency com.google.cloud:google-cloud-core to v2.8.13 ([#992](https://github.com/googleapis/java-vision/issues/992)) ([e0882e8](https://github.com/googleapis/java-vision/commit/e0882e83f338f4fb530a0c304dfa97bc1977fc56))
* Update dependency com.google.cloud:google-cloud-core to v2.8.14 ([#993](https://github.com/googleapis/java-vision/issues/993)) ([efd9c3f](https://github.com/googleapis/java-vision/commit/efd9c3fc7863dd4d819e9628d18bb43998f73ef8))
* Update dependency com.google.cloud:google-cloud-core to v2.8.18 ([#995](https://github.com/googleapis/java-vision/issues/995)) ([ead37cc](https://github.com/googleapis/java-vision/commit/ead37cc0cf1a1af8bb513d89153e30f06ea71f20))
* Update dependency com.google.cloud:google-cloud-core to v2.8.19 ([#1023](https://github.com/googleapis/java-vision/issues/1023)) ([ce23a3b](https://github.com/googleapis/java-vision/commit/ce23a3b2ae1c49a8df71fd66eda38f4845763cad))
* Update dependency com.google.cloud:google-cloud-shared-dependencies to v3.0.4 ([#1026](https://github.com/googleapis/java-vision/issues/1026)) ([71a4c70](https://github.com/googleapis/java-vision/commit/71a4c70366ab05af1307d914975aa43a2e5679a7))
* Update dependency com.google.cloud:google-cloud-storage to v2.12.0 ([#986](https://github.com/googleapis/java-vision/issues/986)) ([08262f8](https://github.com/googleapis/java-vision/commit/08262f87c3ce67eed973ccf9fc2f1f63525f5857))
* Update spring.version to v2.7.4 ([#994](https://github.com/googleapis/java-vision/issues/994)) ([8688790](https://github.com/googleapis/java-vision/commit/868879044e4296f524d6157d37b8601a5fc8dc4d))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
suztomo pushed a commit that referenced this issue Feb 1, 2023
🤖 I have created a release *beep* *boop*
---


### Updating meta-information for bleeding-edge SNAPSHOT release.

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants