-        boolean shareByLink = false;
-        // Check if the file is shared by link
-        if (result.isSuccess() && result.getData().size() > 0){
-            ArrayList<Object> shares = result.getData();
-            for(Object object: shares){
-                if (((OCShare) object).getShareType() == ShareType.PUBLIC_LINK){
-                    shareByLink = true;
+        // Create public link if doesn't exist yet
+        boolean publicShareExists = false;
+        if (result.isSuccess()) {
+            OCShare share = null;
+            for (int i=0 ; i<result.getData().size(); i++) {
+                share = (OCShare) result.getData().get(i);
+                if (ShareType.PUBLIC_LINK.equals(share.getShareType())) {
+                    publicShareExists = true;