Index: lucene/src/java/org/apache/lucene/store/FSDirectory.java =================================================================== --- lucene/src/java/org/apache/lucene/store/FSDirectory.java (revision 1053036) +++ lucene/src/java/org/apache/lucene/store/FSDirectory.java (working copy) @@ -22,6 +22,7 @@ import java.io.FilenameFilter; import java.io.IOException; import java.io.RandomAccessFile; +import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -111,16 +112,9 @@ * @see Directory */ public abstract class FSDirectory extends Directory { - private final static MessageDigest DIGESTER; + private static MessageDigest DIGESTER; + private static final Object DIGESTER_LOCK = new Object(); - static { - try { - DIGESTER = MessageDigest.getInstance("MD5"); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e.toString(), e); - } - } - /** * Default read chunk size. This is a conditional default: on 32bit JVMs, it defaults to 100 MB. On 64bit JVMs, it's * Integer.MAX_VALUE. @@ -196,7 +190,8 @@ @Override public void setLockFactory(LockFactory lockFactory) throws IOException { - super.setLockFactory(lockFactory); + // dont call super because it sets also LockPrefix: super.setLockFactory(lockFactory); + this.lockFactory = lockFactory; // for filesystem based LockFactory, delete the lockPrefix, if the locks are placed // in index dir. If no index dir is given, set ourselves @@ -209,9 +204,12 @@ lf.setLockPrefix(null); } else if (dir.getCanonicalPath().equals(directory.getCanonicalPath())) { lf.setLockPrefix(null); + } else { + lf.setLockPrefix(this.getLockID()); } + } else { + lockFactory.setLockPrefix(this.getLockID()); } - } /** Lists all files (not subdirectories) in the @@ -353,8 +351,9 @@ @Override public String getLockID() { + //DEBUG: System.out.println("getLockID() called"); ensureOpen(); - String dirName; // name to be hashed + final String dirName; // name to be hashed try { dirName = directory.getCanonicalPath(); } catch (IOException e) { @@ -362,10 +361,20 @@ } byte digest[]; - synchronized (DIGESTER) { - digest = DIGESTER.digest(dirName.getBytes()); + synchronized (DIGESTER_LOCK) { + if (DIGESTER == null) try { + DIGESTER = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("Missing MD5 digest algorithm in this Java version", e); + } + + try { + digest = DIGESTER.digest(dirName.getBytes("UTF-8")); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("Should never happen", e); + } } - StringBuilder buf = new StringBuilder(); + final StringBuilder buf = new StringBuilder(); buf.append("lucene-"); for (int i = 0; i < digest.length; i++) { int b = digest[i]; Index: lucene/src/java/org/apache/lucene/util/Constants.java =================================================================== --- lucene/src/java/org/apache/lucene/util/Constants.java (revision 1053036) +++ lucene/src/java/org/apache/lucene/util/Constants.java (working copy) @@ -43,6 +43,8 @@ public static final boolean WINDOWS = OS_NAME.startsWith("Windows"); /** True iff running on SunOS. */ public static final boolean SUN_OS = OS_NAME.startsWith("SunOS"); + /** True iff running on Mac OS X */ + public static final boolean MAC_OS_X = OS_NAME.startsWith("Mac OS X"); public static final String OS_ARCH = System.getProperty("os.arch"); public static final String OS_VERSION = System.getProperty("os.version"); Index: lucene/src/test/org/apache/lucene/util/LuceneTestCase.java =================================================================== --- lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (revision 1053036) +++ lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (working copy) @@ -554,7 +554,8 @@ !rogueThreads.containsKey(t) && t != Thread.currentThread() && // TODO: TimeLimitingCollector starts a thread statically.... WTF?! - !t.getName().equals("TimeLimitedCollector timer thread")) { + !t.getName().equals("TimeLimitedCollector timer thread") && + !t.getName().matches(".*SunPKCS11.*")) { System.err.println("WARNING: " + context + " left thread running: " + t); rogueThreads.put(t, true); rogueCount++;