You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/08/19 16:36:49 UTC

[camel] branch camel-3.4.x updated: CAMEL-15424: fix a possible NPE on camel-box-api when adding a new collaborator (#4103)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.4.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.4.x by this push:
     new 8c5ba27  CAMEL-15424: fix a possible NPE on camel-box-api when adding a new collaborator (#4103)
8c5ba27 is described below

commit 8c5ba273d5fe26ea773bd0817bb5085fd92684d7
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Wed Aug 19 18:30:49 2020 +0200

    CAMEL-15424: fix a possible NPE on camel-box-api when adding a new collaborator (#4103)
---
 .../box/api/BoxCollaborationsManager.java          |  9 +++--
 .../box/BoxCollaborationsManagerTest.java          | 42 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxCollaborationsManager.java b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxCollaborationsManager.java
index d076831..8e5bc27 100644
--- a/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxCollaborationsManager.java
+++ b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxCollaborationsManager.java
@@ -86,19 +86,18 @@ public class BoxCollaborationsManager {
      * 
      * @return The new collaboration.
      */
-    @SuppressWarnings("unused") // compiler for some reason thinks 'if
-                                // (collaborator == null)' clause is dead code.
-    public BoxCollaboration addFolderCollaboration(String folderId, BoxCollaborator collaborator,
+    public BoxCollaboration addFolderCollaboration(
+            String folderId, BoxCollaborator collaborator,
             BoxCollaboration.Role role) {
         try {
-            LOG.debug("Creating  collaborations for folder(id=" + folderId + ") with collaborator("
-                    + collaborator.getID() + ")");
             if (folderId == null) {
                 throw new IllegalArgumentException("Parameter 'folderId' can not be null");
             }
             if (collaborator == null) {
                 throw new IllegalArgumentException("Parameter 'collaborator' can not be null");
             }
+            LOG.debug("Creating  collaborations for folder(id=" + folderId + ") with collaborator("
+                    + collaborator.getID() + ")");
             if (role == null) {
                 throw new IllegalArgumentException("Parameter 'role' can not be null");
             }
diff --git a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxCollaborationsManagerTest.java b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxCollaborationsManagerTest.java
new file mode 100644
index 0000000..93739b8
--- /dev/null
+++ b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxCollaborationsManagerTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.box;
+
+import com.box.sdk.BoxCollaboration;
+import com.box.sdk.BoxUser;
+import org.apache.camel.component.box.api.BoxCollaborationsManager;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class BoxCollaborationsManagerTest {
+
+    @Test
+    public void testAddFolderCollaborationNullFolderId() {
+        BoxCollaborationsManager bcm = new BoxCollaborationsManager(null);
+
+        assertThrows(IllegalArgumentException.class,
+                () -> bcm.addFolderCollaboration(null, new BoxUser(null, "id"), BoxCollaboration.Role.EDITOR));
+
+        assertThrows(IllegalArgumentException.class,
+                () -> bcm.addFolderCollaboration("123", null, BoxCollaboration.Role.EDITOR));
+
+        assertThrows(IllegalArgumentException.class,
+                () -> bcm.addFolderCollaboration("123", new BoxUser(null, "id"), null));
+    }
+}
\ No newline at end of file