This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 9ee0982 CAMEL-15424: fix a possible NPE on camel-box-api when adding
a new collaborator (#4099)
9ee0982 is described below
commit 9ee0982c4522ca56caf2b4efef1315b8480fa252
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Wed Aug 19 18:30:37 2020 +0200
CAMEL-15424: fix a possible NPE on camel-box-api when adding a new
collaborator (#4099)
---
.../box/api/BoxCollaborationsManager.java | 6 ++--
.../box/BoxCollaborationsManagerTest.java | 42 ++++++++++++++++++++++
2 files changed, 44 insertions(+), 4 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 b6d093f..f6bc027 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
@@ -80,20 +80,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,
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