Skip to content

Conversation

@zjffdu
Copy link
Contributor

@zjffdu zjffdu commented Sep 9, 2016

What is this PR for?

We should use Iterator to iterate the list when we want to remove items in the middle of iteration, Otherwise will get the ConcurrentModificationException

What type of PR is it?

[Bug Fix]

Todos

  • - Task

What is the Jira issue?

How should this be tested?

No test added

Questions:

  • Does the licenses files need update? No
  • Is there breaking changes for older versions? No
  • Does this needs documentation? No

}

Iterator<String> iter = interpreterSettingIds.iterator();
while (iter.hasNext()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also remove the synchronized block, it seems not necessary.

@Leemoonsoo
Copy link
Member

LGTM and merge if there're no more discussions.

InterpreterSetting setting = get(id);
if (setting == null) {
// interpreter setting is removed from factory. remove id from here, too
iter.remove();
Copy link

@prasadwagle prasadwagle Sep 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of removing the id? It seems to me that interpreterSettingIds is a temporary LinkedList and the effect of removing id is not persisted.

  private List<String> getNoteInterpreterSettingBinding(String noteId) {
    LinkedList<String> bindings = new LinkedList<>();
    synchronized (interpreterSettings) {
      List<String> settingIds = interpreterBindings.get(noteId);
      if (settingIds != null) {
        bindings.addAll(settingIds);
      }
    }
    return bindings;
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prasadwagle It is because the interpreter setting may be removed in other threads, so we need to check it here. I don't quite understand your concern about the persistence.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few weeks ago, I came across the exact same question as @prasadwagle. Call remote on the temporary (not returned) list is useless (this consideration/question is separate from this PR which aims solving the concurrent modification exception (which I met also), but is worth to consider).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's good question although not related to topic of this PR. maybe @jongyoul could bring little clarity as I believe he's the original author of that function

@bzz
Copy link
Member

bzz commented Sep 18, 2016

Shall we merge this guy now?

@khalidhuseynov
Copy link
Member

tested locally, LGTM

@bzz
Copy link
Member

bzz commented Sep 19, 2016

Merging to master, if there is no further discussion.

@asfgit asfgit closed this in b8755eb Sep 19, 2016
pedrozatta pushed a commit to pedrozatta/zeppelin that referenced this pull request Oct 27, 2016
…lling remove inside foreach loop

### What is this PR for?
We should use Iterator to iterate the list when we want to remove items in the middle of iteration, Otherwise will get the ConcurrentModificationException

### What type of PR is it?
[Bug Fix]

### Todos
* [ ] - Task

### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-1420

### How should this be tested?
No test added

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Jeff Zhang <[email protected]>

Closes apache#1419 from zjffdu/ZEPPELIN-1420 and squashes the following commits:

ddd0710 [Jeff Zhang] ZEPPELIN-1420. java.util.ConcurrentModificationException caused by calling remove inside foreach loop
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

Successfully merging this pull request may close these issues.

6 participants