From 8db5e06c625b129aa80c006788d25e239a0fdb09 Mon Sep 17 00:00:00 2001 From: Bryce Curtis Date: Fri, 6 Jan 2012 22:23:49 -0600 Subject: [PATCH] Fix CB-135 Multithreaded access on CallbackServer javascript object. --- .../src/com/phonegap/CallbackServer.java | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/framework/src/com/phonegap/CallbackServer.java b/framework/src/com/phonegap/CallbackServer.java index 81e5800c..d459d995 100755 --- a/framework/src/com/phonegap/CallbackServer.java +++ b/framework/src/com/phonegap/CallbackServer.java @@ -314,9 +314,10 @@ public class CallbackServer implements Runnable { * @return int */ public int getSize() { - int size = this.javascript.size(); - //System.out.println("getSize() = " + size); - return size; + synchronized(this) { + int size = this.javascript.size(); + return size; + } } /** @@ -325,17 +326,16 @@ public class CallbackServer implements Runnable { * @return String */ public String getJavascript() { - if (this.javascript.size() == 0) { - return null; - } - String statement = this.javascript.remove(0); - //System.out.println("CallbackServer.getJavascript() = " + statement); - if (this.javascript.size() == 0) { - synchronized (this) { - this.empty = true; - } - } - return statement; + synchronized(this) { + if (this.javascript.size() == 0) { + return null; + } + String statement = this.javascript.remove(0); + if (this.javascript.size() == 0) { + this.empty = true; + } + return statement; + } } /** @@ -344,12 +344,11 @@ public class CallbackServer implements Runnable { * @param statement */ public void sendJavascript(String statement) { - //System.out.println("CallbackServer.sendJavascript("+statement+")"); - this.javascript.add(statement); - synchronized (this) { - this.empty = false; - this.notify(); - } + synchronized (this) { + this.javascript.add(statement); + this.empty = false; + this.notify(); + } } /* The Following code has been modified from original implementation of URLEncoder */