From 6827e171e4f47bd7d5bdeb65224083ff2af388ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hallvard=20Tr=C3=A6tteberg?= <hal@ntnu.no>
Date: Fri, 24 Sep 2021 09:12:24 +0000
Subject: [PATCH] Handle intentional (spot) bug

---
 .../main/java/fxutil/SuppressFBWarnings.java  | 22 +++++++++++++++++++
 .../java/fxutil/doc/FileMenuController.java   |  6 ++++-
 2 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 todolist/fxutil/src/main/java/fxutil/SuppressFBWarnings.java

diff --git a/todolist/fxutil/src/main/java/fxutil/SuppressFBWarnings.java b/todolist/fxutil/src/main/java/fxutil/SuppressFBWarnings.java
new file mode 100644
index 0000000..72071ed
--- /dev/null
+++ b/todolist/fxutil/src/main/java/fxutil/SuppressFBWarnings.java
@@ -0,0 +1,22 @@
+package fxutil;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Annontation to suppress spotbugs warnings.
+ * Must have this specific name to be considered by spotbugs.
+ */
+@Retention(RetentionPolicy.CLASS)
+public @interface SuppressFBWarnings {
+  /**
+   * The set of FindBugs warnings that are to be suppressed in
+   * annotated element. The value can be a bug category, kind or pattern.
+   */
+  String[] value() default {};
+
+  /**
+   * Optional documentation of the reason why the warning is suppressed.
+   */
+  String justification() default "";
+}
diff --git a/todolist/fxutil/src/main/java/fxutil/doc/FileMenuController.java b/todolist/fxutil/src/main/java/fxutil/doc/FileMenuController.java
index a91dd76..ab3af83 100644
--- a/todolist/fxutil/src/main/java/fxutil/doc/FileMenuController.java
+++ b/todolist/fxutil/src/main/java/fxutil/doc/FileMenuController.java
@@ -1,5 +1,6 @@
 package fxutil.doc;
 
+import fxutil.SuppressFBWarnings;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -35,13 +36,16 @@ public class FileMenuController {
    *
    * @param documentStorage the document storage
    */
+  @SuppressFBWarnings(
+      value = "EI_EXPOSE_REP2", 
+      justification = "We intentioanlly don't deep copy documentStorage")
   public void setDocumentStorage(final DocumentStorage<File> documentStorage) {
     this.documentStorage = documentStorage;
     if (importMenu != null) {
       importMenu.setDisable(documentStorage.getDocumentImporters().isEmpty());
     }
   }
-
+  
   @FXML
   public void handleNewAction() {
     documentStorage.newDocument();
-- 
GitLab