From cf897f104c663348267e7cbdf2cbe6f0873316a5 Mon Sep 17 00:00:00 2001
From: Stephane Dallongeville <stephane.dallongeville@pasteur.fr>
Date: Tue, 13 Jul 2021 10:57:33 +0200
Subject: [PATCH] Fixed NPE errors

---
 pom.xml                                            |  2 +-
 .../adufour/vars/gui/swing/WorkbookEditor.java     | 13 +++++++++----
 .../plugins/adufour/workbooks/IcySpreadSheet.java  | 14 ++++++++++----
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/pom.xml b/pom.xml
index aba18de..f89854a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
     </parent>
 
     <artifactId>workbooks</artifactId>
-    <version>3.4.11</version>
+    <version>3.4.12</version>
 
     <packaging>jar</packaging>
 
diff --git a/src/main/java/plugins/adufour/vars/gui/swing/WorkbookEditor.java b/src/main/java/plugins/adufour/vars/gui/swing/WorkbookEditor.java
index 8b09ebd..562cd8d 100644
--- a/src/main/java/plugins/adufour/vars/gui/swing/WorkbookEditor.java
+++ b/src/main/java/plugins/adufour/vars/gui/swing/WorkbookEditor.java
@@ -1,6 +1,7 @@
 package plugins.adufour.vars.gui.swing;
 
 import java.awt.BorderLayout;
+import java.awt.Color;
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.Font;
@@ -109,7 +110,7 @@ public class WorkbookEditor extends SwingVarEditor<Workbook>
     private JTabbedPane tabs;
     private final HashMap<Sheet, JXTable> tables = new HashMap<Sheet, JXTable>();
     private final HashMap<Sheet, JXTable> headers = new HashMap<Sheet, JXTable>();
-    
+
     // cached workbook to avoid reference of old book being leaked by GUI
     private Workbook book;
 
@@ -231,7 +232,8 @@ public class WorkbookEditor extends SwingVarEditor<Workbook>
     /**
      * Sets whether the open button should be visible
      * 
-     * @param visible visible state
+     * @param visible
+     *        visible state
      */
     public void setOpenButtonVisible(boolean visible)
     {
@@ -241,7 +243,8 @@ public class WorkbookEditor extends SwingVarEditor<Workbook>
     /**
      * Sets whether the table editor is read-only, and therefore rejects user input
      * 
-     * @param readOnly read only state
+     * @param readOnly
+     *        read only state
      */
     public void setReadOnly(boolean readOnly)
     {
@@ -972,7 +975,9 @@ public class WorkbookEditor extends SwingVarEditor<Workbook>
                         Component component = super.getTableCellRendererComponent(theTable, value, isSelected, hasFocus,
                                 theRow, theColumn);
 
-                        component.setBackground(icySheet.getFillColor(theRow, theColumn));
+                        Color fillColor = icySheet.getFillColor(theRow, theColumn);
+                        if (fillColor != null)
+                            component.setBackground(fillColor);
 
                         return component;
                     }
diff --git a/src/main/java/plugins/adufour/workbooks/IcySpreadSheet.java b/src/main/java/plugins/adufour/workbooks/IcySpreadSheet.java
index 1be355f..c6b6d59 100644
--- a/src/main/java/plugins/adufour/workbooks/IcySpreadSheet.java
+++ b/src/main/java/plugins/adufour/workbooks/IcySpreadSheet.java
@@ -222,17 +222,23 @@ public class IcySpreadSheet
         if (color instanceof HSSFColor)
         {
             short[] rgb = ((HSSFColor) color).getTriplet();
-            if (rgb[0] != 0 || rgb[1] != 0 || rgb[2] != 0)
+            if ((rgb != null) && (rgb.length >= 3))
             {
-                return new Color(rgb[0], rgb[1], rgb[2]);
+                if (rgb[0] != 0 || rgb[1] != 0 || rgb[2] != 0)
+                {
+                    return new Color(rgb[0], rgb[1], rgb[2]);
+                }
             }
         }
         else if (color instanceof XSSFColor)
         {
             byte[] rgb = ((XSSFColor) color).getRGB();
-            if (rgb[0] != 0 || rgb[1] != 0 || rgb[2] != 0)
+            if ((rgb != null) && (rgb.length >= 3))
             {
-                return new Color(rgb[0] & 0xff, rgb[1] & 0xff, rgb[2] & 0xff);
+                if (rgb[0] != 0 || rgb[1] != 0 || rgb[2] != 0)
+                {
+                    return new Color(rgb[0] & 0xff, rgb[1] & 0xff, rgb[2] & 0xff);
+                }
             }
         }
 
-- 
GitLab