From 24452a2ecb1a58d01885f574ea6f26e0514ac635 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 15 Oct 2024 16:39:09 +0000 Subject: try to make VariantSupport thread safe git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921341 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/hpsf/VariantSupport.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'poi') diff --git a/poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java b/poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java index f6da239c8b..39ef7e2431 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java +++ b/poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java @@ -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 unsupportedMessage; + private static final List 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); } } } -- cgit v1.2.3