From 81acfb95719956a4ede9e0046fa154b42cbdf23b Mon Sep 17 00:00:00 2001 From: masensio Date: Fri, 31 Jan 2014 12:25:39 +0100 Subject: [PATCH] OC-2678: Consider CreateShareRemoteOperation returns result!=null in exceptions --- .../remote/CreateShareRemoteOperation.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/com/owncloud/android/lib/operations/remote/CreateShareRemoteOperation.java b/src/com/owncloud/android/lib/operations/remote/CreateShareRemoteOperation.java index 8e3e3bc0..8e3a4d20 100644 --- a/src/com/owncloud/android/lib/operations/remote/CreateShareRemoteOperation.java +++ b/src/com/owncloud/android/lib/operations/remote/CreateShareRemoteOperation.java @@ -102,18 +102,20 @@ public class CreateShareRemoteOperation extends RemoteOperation { RemoteOperationResult result = null; int status = -1; - // Post Method - PostMethod post = new PostMethod(client.getBaseUri() + ShareUtils.SHAREAPI_ROUTE); - Log.d(TAG, "URL ------> " + client.getBaseUri() + ShareUtils.SHAREAPI_ROUTE); - - post.addParameter(PARAM_PATH, mPath); - post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue())); - post.addParameter(PARAM_SHARE_WITH, mShareWith); - post.addParameter(PARAM_PUBLIC_UPLOAD, Boolean.toString(mPublicUpload)); - post.addParameter(PARAM_PASSWORD, mPassword); - post.addParameter(PARAM_PERMISSIONS, Integer.toString(mPermissions)); + PostMethod post = null; try { + // Post Method + post = new PostMethod(client.getBaseUri() + ShareUtils.SHAREAPI_ROUTE); + Log.d(TAG, "URL ------> " + client.getBaseUri() + ShareUtils.SHAREAPI_ROUTE); + + post.addParameter(PARAM_PATH, mPath); + post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue())); + post.addParameter(PARAM_SHARE_WITH, mShareWith); + post.addParameter(PARAM_PUBLIC_UPLOAD, Boolean.toString(mPublicUpload)); + post.addParameter(PARAM_PASSWORD, mPassword); + post.addParameter(PARAM_PERMISSIONS, Integer.toString(mPermissions)); + status = client.executeMethod(post); if(isSuccess(status)) { @@ -138,12 +140,18 @@ public class CreateShareRemoteOperation extends RemoteOperation { result.setData(sharesObjects); } + } else { + result = new RemoteOperationResult(false, status, post.getResponseHeaders()); } + } catch (Exception e) { result = new RemoteOperationResult(e); Log.e(TAG, "Exception while Creating New Share", e); + } finally { - post.releaseConnection(); + if (post != null) { + post.releaseConnection(); + } } return result; }