aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshade <unknown>2019-02-06 14:58:17 +0100
committerbell-sw <liberica@bell-sw.com>2019-04-20 16:52:03 +0300
commit291aa3882c8a9b18a1a333355d8b10f45e97fb08 (patch)
treeee905d2757668e2c153d11a3915359befd321e8d
parent4c4c7c02466d22c284957f49dcd1ef1cd07ce3cc (diff)
downloadjdk8u_jaxp-291aa3882c8a9b18a1a333355d8b10f45e97fb08.tar.gz
8212178: Soft reference reclamation race in com.sun.xml.internal.stream.util.ThreadLocalBufferAllocator
Reviewed-by: rkennke, kbarrett, joehw
-rw-r--r--src/com/sun/xml/internal/stream/util/ThreadLocalBufferAllocator.java24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/com/sun/xml/internal/stream/util/ThreadLocalBufferAllocator.java b/src/com/sun/xml/internal/stream/util/ThreadLocalBufferAllocator.java
index 25bdf6b..5f4243d 100644
--- a/src/com/sun/xml/internal/stream/util/ThreadLocalBufferAllocator.java
+++ b/src/com/sun/xml/internal/stream/util/ThreadLocalBufferAllocator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -39,15 +39,19 @@ import java.lang.ref.*;
* @author Santiago.PericasGeertsen@sun.com
*/
public class ThreadLocalBufferAllocator {
- private static ThreadLocal tlba = new ThreadLocal();
+ private static final ThreadLocal<SoftReference<BufferAllocator>> TL = new ThreadLocal<>();
- public static BufferAllocator getBufferAllocator() {
- SoftReference bAllocatorRef = (SoftReference) tlba.get();
- if (bAllocatorRef == null || bAllocatorRef.get() == null) {
- bAllocatorRef = new SoftReference(new BufferAllocator());
- tlba.set(bAllocatorRef);
+ public static BufferAllocator getBufferAllocator() {
+ BufferAllocator ba = null;
+ SoftReference<BufferAllocator> sr = TL.get();
+ if (sr != null) {
+ ba = sr.get();
}
-
- return (BufferAllocator) bAllocatorRef.get();
- }
+ if (ba == null) {
+ ba = new BufferAllocator();
+ sr = new SoftReference<>(ba);
+ TL.set(sr);
+ }
+ return ba;
+ }
}