Index: FSDirectory.java =================================================================== --- FSDirectory.java (revision 165147) +++ FSDirectory.java (working copy) @@ -45,19 +45,57 @@ */ private static final Hashtable DIRECTORIES = new Hashtable(); - private static final boolean DISABLE_LOCKS = - Boolean.getBoolean("disableLuceneLocks") || Constants.JAVA_1_1; + /** + * Wrap initialization of DISABLE_LOCKS in try/catch block so that in an + * unsigned applet environment, failure to get the system property will + * result in a reasonable default and won't fail the whole applet. + */ + private static boolean DISABLE_LOCKS; + static { + try { + DISABLE_LOCKS = Boolean.getBoolean("disableLuceneLocks") || Constants.JAVA_1_1; + } catch ( Exception e ) { + DISABLE_LOCKS = Constants.JAVA_1_1; + } + } - /** - * Directory specified by org.apache.lucene.lockDir - * or java.io.tmpdir system property - */ - public static final String LOCK_DIR = - System.getProperty("org.apache.lucene.lockDir", - System.getProperty("java.io.tmpdir")); + /** + * Sets the DISABLE_LOCKS property. + * @param disable true to disable file locks, false to enable locks. + */ + public static void setDisableLocks( boolean disable ) + { + DISABLE_LOCKS = disable; + } + /** + * Returns the value of the DISABLE_LOCKS property. + * @return true if locks are disabled, false if locks are enabled. + */ + public static boolean getDisableLocks() + { + return DISABLE_LOCKS; + } + + /** + * Directory specified by org.apache.lucene.lockdir + * or java.io.tmpdir system property. + *

+ * This is wrapped in a try/catch block so that in an unsigned applet + * environment, failure to get the system property will result in a + * reasonable default and won't fail the whole applet. + */ + public static String LOCK_DIR; + static { + try { + LOCK_DIR = System.getProperty("org.apache.lucene.lockdir", System.getProperty("java.io.tmpdir", ".")); + } catch ( Exception e ) { + LOCK_DIR = "."; + } + } + /** The default class which implements filesystem-based directories. */ - private static final Class IMPL; + private static Class IMPL; static { try { String name = @@ -66,6 +104,12 @@ IMPL = Class.forName(name); } catch (ClassNotFoundException e) { throw new RuntimeException("cannot load FSDirectory class: " + e.toString()); + } catch ( SecurityException se ) { + try { + IMPL = Class.forName( FSDirectory.class.getName() ); + } catch ( ClassNotFoundException e ) { + throw new RuntimeException( "cannot load default FSDirectory class: " + e.toString() ); + } } }