Skip to content

Commit

Permalink
Possible fix for ConcurrentModificationException
Browse files Browse the repository at this point in the history
  • Loading branch information
ebhsgit committed Jun 19, 2020
1 parent f1f4722 commit 9d32223
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions framework/src/org/apache/cordova/PluginManager.java
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 @@ -29,6 +31,8 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.os.Bundle;
import android.os.Debug;

import android.util.Log;

/**
* PluginManager is exposed to JavaScript in the Cordova WebView.
*
Expand All @@ -40,8 +44,13 @@ 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 LinkedHashMap<String, CordovaPlugin> pluginMap = new LinkedHashMap<String, CordovaPlugin>();
// private final LinkedHashMap<String, PluginEntry> entryMap = new LinkedHashMap<String, PluginEntry>();

// Fix for concurrent modification exception
// https://github.com/breautek/cordova-android/commit/bfda452a09ba26412e0f527f6af1957379d89453
private final Map<String, CordovaPlugin> pluginMap = Collections.synchronizedMap(new LinkedHashMap<String, CordovaPlugin>());
private final Map<String, PluginEntry> entryMap = Collections.synchronizedMap(new LinkedHashMap<String, PluginEntry>());

private final CordovaInterface ctx;
private final CordovaWebView app;
Expand Down Expand Up @@ -96,6 +105,7 @@ private void startupPlugins() {
if (entry.onload) {
getPlugin(entry.service);
} else {
Log.d(TAG, "startupPlugins: put - " + entry.service);
pluginMap.put(entry.service, null);
}
}
Expand Down Expand Up @@ -169,6 +179,7 @@ public CordovaPlugin getPlugin(String service) {
ret = instantiatePlugin(pe.pluginClass);
}
ret.privateInitialize(service, ctx, app, app.getPreferences());
Log.d(TAG, "getPlugin - put: " + service);
pluginMap.put(service, ret);
}
return ret;
Expand Down Expand Up @@ -196,6 +207,7 @@ public void addService(PluginEntry entry) {
this.entryMap.put(entry.service, entry);
if (entry.plugin != null) {
entry.plugin.privateInitialize(entry.service, ctx, app, app.getPreferences());
Log.d(TAG, "addService: put - " + entry.service);
pluginMap.put(entry.service, entry.plugin);
}
}
Expand Down Expand Up @@ -307,6 +319,7 @@ public void onDestroy() {
* @return Object to stop propagation or null
*/
public Object postMessage(String id, Object data) {
Log.d(TAG, "postMessage: " + id);
for (CordovaPlugin plugin : this.pluginMap.values()) {
if (plugin != null) {
Object obj = plugin.onMessage(id, data);
Expand Down Expand Up @@ -523,4 +536,4 @@ public Bundle onSaveInstanceState() {
}
return state;
}
}
}

0 comments on commit 9d32223

Please sign in to comment.