-
Notifications
You must be signed in to change notification settings - Fork 2.8k
ZEPPELIN-1420. java.util.ConcurrentModificationException caused by calling remove inside foreach loop #1419
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1017,15 +1017,16 @@ public List<String> getInterpreters(String noteId) { | |
| public List<InterpreterSetting> getInterpreterSettings(String noteId) { | ||
| List<String> interpreterSettingIds = getNoteInterpreterSettingBinding(noteId); | ||
| LinkedList<InterpreterSetting> settings = new LinkedList<>(); | ||
| synchronized (interpreterSettingIds) { | ||
| for (String id : interpreterSettingIds) { | ||
| InterpreterSetting setting = get(id); | ||
| if (setting == null) { | ||
| // interpreter setting is removed from factory. remove id from here, too | ||
| interpreterSettingIds.remove(id); | ||
| } else { | ||
| settings.add(setting); | ||
| } | ||
|
|
||
| Iterator<String> iter = interpreterSettingIds.iterator(); | ||
| while (iter.hasNext()) { | ||
| String id = iter.next(); | ||
| InterpreterSetting setting = get(id); | ||
| if (setting == null) { | ||
| // interpreter setting is removed from factory. remove id from here, too | ||
| iter.remove(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } else { | ||
| settings.add(setting); | ||
| } | ||
| } | ||
| return settings; | ||
|
|
||
There was a problem hiding this comment.
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.