]> source.dussan.org Git - poi.git/commitdiff
try to make VariantSupport thread safe
authorPJ Fanning <fanningpj@apache.org>
Tue, 15 Oct 2024 16:39:09 +0000 (16:39 +0000)
committerPJ Fanning <fanningpj@apache.org>
Tue, 15 Oct 2024 16:39:09 +0000 (16:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921341 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java

index f6da239c8b8a67ba04e0b982f99e74dfa9473415..39ef7e2431ad34187d1fff1fa54b8869fe51e5d6 100644 (file)
@@ -66,7 +66,7 @@ public class VariantSupport extends Variant {
      * Keeps a list of the variant types an "unsupported" message has already
      * been issued for.
      */
-    private static List<Long> unsupportedMessage;
+    private static final List<Long> unsupportedMessage = new LinkedList<>();
 
     private static final byte[] paddingBytes = new byte[3];
 
@@ -102,18 +102,18 @@ public class VariantSupport extends Variant {
      *
      * @param ex The exception to log
      */
-    protected static void writeUnsupportedTypeMessage
-        (final UnsupportedVariantTypeException ex) {
-        if (isLogUnsupportedTypes())
-        {
-            if (unsupportedMessage == null) {
-                unsupportedMessage = new LinkedList<>();
+    protected static void writeUnsupportedTypeMessage(final UnsupportedVariantTypeException ex) {
+        if (isLogUnsupportedTypes()) {
+            final Long vt = ex.getVariantType();
+            boolean needsLogging = false;
+            synchronized (unsupportedMessage) {
+                if (!unsupportedMessage.contains(vt)) {
+                    needsLogging = true;
+                    unsupportedMessage.add(vt);
+                }
             }
-            Long vt = Long.valueOf(ex.getVariantType());
-            if (!unsupportedMessage.contains(vt))
-            {
+            if (needsLogging) {
                 LOG.atError().withThrowable(ex).log("Unsupported type");
-                unsupportedMessage.add(vt);
             }
         }
     }