diff --git a/jdk/src/share/classes/javax/crypto/Cipher.java b/jdk/src/share/classes/javax/crypto/Cipher.java index 8aa8b182d75..408d9b91172 100644 --- a/jdk/src/share/classes/javax/crypto/Cipher.java +++ b/jdk/src/share/classes/javax/crypto/Cipher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, 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 @@ -26,6 +26,8 @@ package javax.crypto; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import java.util.regex.*; @@ -389,16 +391,15 @@ public class Cipher { return matches(regexp, value) ? S_YES : S_NO; } - // Map for previously compiled patterns - // XXX use ConcurrentHashMap once available - private final static Map patternCache = - Collections.synchronizedMap(new HashMap()); + // ConcurrentMap for previously compiled patterns + private final static ConcurrentMap patternCache = + new ConcurrentHashMap(); private static boolean matches(String regexp, String str) { Pattern pattern = patternCache.get(regexp); if (pattern == null) { pattern = Pattern.compile(regexp); - patternCache.put(regexp, pattern); + patternCache.putIfAbsent(regexp, pattern); } return pattern.matcher(str.toUpperCase(Locale.ENGLISH)).matches(); }