Skip to content

Commit

Permalink
(android) Avoid Crash Report: ConcurrentModificationException
Browse files Browse the repository at this point in the history
  • Loading branch information
lempere committed Sep 20, 2020
1 parent 565106f commit 4eee8d3
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions framework/src/org/apache/cordova/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Licensed to the Apache Software Foundation (ASF) under one
package org.apache.cordova;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

import org.json.JSONException;

Expand All @@ -28,6 +30,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.net.Uri;
import android.os.Bundle;
import android.os.Debug;
import android.os.Build;

/**
* PluginManager is exposed to JavaScript in the Cordova WebView.
Expand All @@ -40,8 +43,8 @@ public class PluginManager {
private static final int SLOW_EXEC_WARNING_THRESHOLD = Debug.isDebuggerConnected() ? 60 : 16;

// List of service entries
private final LinkedHashMap<String, CordovaPlugin> pluginMap = new LinkedHashMap<String, CordovaPlugin>();
private final LinkedHashMap<String, PluginEntry> entryMap = new LinkedHashMap<String, PluginEntry>();
private final Map<String, CordovaPlugin> pluginMap = Collections.synchronizedMap(new LinkedHashMap<>());
private final Map<String, PluginEntry> entryMap = Collections.synchronizedMap(new LinkedHashMap<>());

private final CordovaInterface ctx;
private final CordovaWebView app;
Expand Down Expand Up @@ -307,11 +310,19 @@ public void onDestroy() {
* @return Object to stop propagation or null
*/
public Object postMessage(String id, Object data) {
for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
Object obj = plugin.onMessage(id, data);
if (obj != null) {
return obj;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
this.pluginMap.forEach((s, plugin) -> {
if (plugin != null) {
plugin.onMessage(id, data);
}
});
} else {
for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
Object obj = plugin.onMessage(id, data);
if (obj != null) {
return obj;
}
}
}
}
Expand Down

0 comments on commit 4eee8d3

Please sign in to comment.