Skip to content

Commit 3a93977

Browse files
committed
BCJSSE: Store session bindings in a ConcurrentHashMap
- add null guards for related methods
1 parent e99a4ea commit 3a93977

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

tls/src/main/java/org/bouncycastle/jsse/provider/ProvSSLSessionBase.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import java.security.Principal;
44
import java.security.cert.Certificate;
55
import java.security.cert.X509Certificate;
6-
import java.util.Collections;
7-
import java.util.HashMap;
8-
import java.util.Map;
6+
import java.util.concurrent.ConcurrentHashMap;
97
import java.util.concurrent.atomic.AtomicLong;
108
import java.util.concurrent.atomic.AtomicReference;
119

@@ -27,7 +25,7 @@
2725
abstract class ProvSSLSessionBase
2826
extends BCExtendedSSLSession
2927
{
30-
protected final Map<String, Object> valueMap = Collections.synchronizedMap(new HashMap<String, Object>());
28+
protected final ConcurrentHashMap<String, Object> valueMap = new ConcurrentHashMap<String, Object>();
3129

3230
protected final AtomicReference<ProvSSLSessionContext> sslSessionContext;
3331
protected final boolean fipsMode;
@@ -237,15 +235,17 @@ public SSLSessionContext getSessionContext()
237235

238236
public Object getValue(String name)
239237
{
238+
if (name == null)
239+
{
240+
throw new IllegalArgumentException("'name' cannot be null");
241+
}
242+
240243
return valueMap.get(name);
241244
}
242245

243246
public String[] getValueNames()
244247
{
245-
synchronized (valueMap)
246-
{
247-
return valueMap.keySet().toArray(new String[valueMap.size()]);
248-
}
248+
return valueMap.keySet().toArray(new String[0]);
249249
}
250250

251251
@Override
@@ -287,12 +287,26 @@ public boolean isValid()
287287

288288
public void putValue(String name, Object value)
289289
{
290+
if (name == null)
291+
{
292+
throw new IllegalArgumentException("'name' cannot be null");
293+
}
294+
if (value == null)
295+
{
296+
throw new IllegalArgumentException("'value' cannot be null");
297+
}
298+
290299
notifyUnbound(name, valueMap.put(name, value));
291300
notifyBound(name, value);
292301
}
293302

294303
public void removeValue(String name)
295304
{
305+
if (name == null)
306+
{
307+
throw new IllegalArgumentException("'name' cannot be null");
308+
}
309+
296310
notifyUnbound(name, valueMap.remove(name));
297311
}
298312

0 commit comments

Comments
 (0)