From 665f250863ae467006914c507a4e977a290dc82f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Amor=C3=ADn?= Date: Fri, 24 Jan 2020 13:24:15 -0300 Subject: [PATCH 1/3] [FIX] Caught RejectedExecutionException on Android HttpRequest and tried synchronously --- .../lib/src/org/oxygine/lib/HttpRequests.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java b/oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java index 0576d66aa..abbc899c7 100644 --- a/oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java +++ b/oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java @@ -14,7 +14,7 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; - +import java.util.concurrent.RejectedExecutionException; /** * Created by Denis on 31.12.2014. */ @@ -38,10 +38,15 @@ public HttpRequestHolder() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) // API 11 public static void executeAsyncTask(AsyncTask asyncTask, T... params) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) - asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); - else - asyncTask.execute(params); + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); + } else { + throw new RejectedExecutionException("Invalid API level") + } + } catch(RejectedExecutionException e) { + asyncTask.execute(params); + } } @@ -145,7 +150,7 @@ protected String doInBackground(RequestDetails... details_) { } catch (Exception e) { Log.v("HttpRequest", "error: " + e.toString()); - nativeHttpRequestError(details.handle); + nativeHttpRequestError(details.handle); return e.toString(); } finally { try { @@ -205,4 +210,4 @@ static public HttpRequestHolder createRequest(String url, String[] headerKeys, S return downloadTask; } -} \ No newline at end of file +} From 58b2d98c5dfbde37edf838de916851101ce66853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Amor=C3=ADn?= Date: Fri, 24 Jan 2020 18:38:56 -0300 Subject: [PATCH 2/3] [FIX] syntax --- oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java b/oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java index abbc899c7..666b8d9cc 100644 --- a/oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java +++ b/oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java @@ -42,7 +42,7 @@ public static void executeAsyncTask(AsyncTask asyncTask, T... param if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); } else { - throw new RejectedExecutionException("Invalid API level") + throw new RejectedExecutionException("Invalid API level"); } } catch(RejectedExecutionException e) { asyncTask.execute(params); From 7c76dfe82d15f09aaa9960299c88aacbc5e6c3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Amor=C3=ADn?= Date: Mon, 27 Jan 2020 15:45:31 -0300 Subject: [PATCH 3/3] [FIX] IllegalStateException --- .../lib/src/org/oxygine/lib/HttpRequests.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java b/oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java index 666b8d9cc..7f1daff91 100644 --- a/oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java +++ b/oxygine/SDL/android/lib/src/org/oxygine/lib/HttpRequests.java @@ -37,14 +37,10 @@ public HttpRequestHolder() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) // API 11 - public static void executeAsyncTask(AsyncTask asyncTask, T... params) { - try { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); - } else { - throw new RejectedExecutionException("Invalid API level"); - } - } catch(RejectedExecutionException e) { + public static void executeAsyncTask(AsyncTask asyncTask, T... params) throws RejectedExecutionException { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); + } else { asyncTask.execute(params); } } @@ -55,8 +51,11 @@ public void run(final RequestDetails details) { @Override public void run() { HttpRequest task = new HttpRequest(); - //task.execute(details); - executeAsyncTask(task, details); + try { + executeAsyncTask(task, details); + }catch(RejectedExecutionException ree) { + HttpRequest.nativeHttpRequestError(details.handle); + } } }); }