try to make VariantSupport thread safe

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921341 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2024-10-15 16:39:09 +00:00
parent 822974aadc
commit 24452a2ecb
1 changed files with 11 additions and 11 deletions

View 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);
}
}
}