Skip to content

Commit 894d0bb

Browse files
committed
LUCENE-9730: cleaned up temp. folder management in hunspell.
1 parent 04167b2 commit 894d0bb

File tree

1 file changed

+30
-33
lines changed
  • lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell

1 file changed

+30
-33
lines changed

Diff for: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java

+30-33
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,22 @@ public class Dictionary {
8787
FST<IntsRef> suffixes;
8888
Breaks breaks = Breaks.DEFAULT;
8989

90-
// all condition checks used by prefixes and suffixes. these are typically re-used across
91-
// many affix stripping rules. so these are deduplicated, to save RAM.
90+
/**
91+
* All condition checks used by prefixes and suffixes. these are typically re-used across many
92+
* affix stripping rules. so these are deduplicated, to save RAM.
93+
*/
9294
ArrayList<CharacterRunAutomaton> patterns = new ArrayList<>();
9395

94-
// the entries in the .dic file, mapping to their set of flags.
95-
// the fst output is the ordinal list for flagLookup
96+
/**
97+
* The entries in the .dic file, mapping to their set of flags. the fst output is the ordinal list
98+
* for flagLookup.
99+
*/
96100
FST<IntsRef> words;
97-
// the list of unique flagsets (wordforms). theoretically huge, but practically
98-
// small (e.g. for polish this is 756), otherwise humans wouldn't be able to deal with it either.
101+
102+
/**
103+
* The list of unique flagsets (wordforms). theoretically huge, but practically small (for Polish
104+
* this is 756), otherwise humans wouldn't be able to deal with it either.
105+
*/
99106
BytesRefHash flagLookup = new BytesRefHash();
100107

101108
// the list of unique strip affixes.
@@ -126,8 +133,11 @@ public class Dictionary {
126133
// st: morphological entries (either directly, or aliased from AM)
127134
private String[] stemExceptions = new String[8];
128135
private int stemExceptionCount = 0;
129-
// we set this during sorting, so we know to add an extra FST output.
130-
// when set, some words have exceptional stems, and the last entry is a pointer to stemExceptions
136+
137+
/**
138+
* we set this during sorting, so we know to add an extra FST output. when set, some words have
139+
* exceptional stems, and the last entry is a pointer to stemExceptions
140+
*/
131141
boolean hasStemExceptions;
132142

133143
boolean ignoreCase;
@@ -1481,34 +1491,21 @@ public boolean getIgnoreCase() {
14811491
return ignoreCase;
14821492
}
14831493

1484-
private static Path DEFAULT_TEMP_DIR;
1485-
1486-
/** Used by test framework */
1487-
@SuppressWarnings("unused")
1488-
public static void setDefaultTempDir(Path tempDir) {
1489-
DEFAULT_TEMP_DIR = tempDir;
1490-
}
1491-
14921494
/**
1493-
* Returns the default temporary directory. By default, java.io.tmpdir. If not accessible or not
1494-
* available, an IOException is thrown
1495+
* Returns the default temporary directory pointed to by {@code java.io.tmpdir}. If not accessible
1496+
* or not available, an IOException is thrown.
14951497
*/
1496-
static synchronized Path getDefaultTempDir() throws IOException {
1497-
if (DEFAULT_TEMP_DIR == null) {
1498-
// Lazy init
1499-
String tempDirPath = System.getProperty("java.io.tmpdir");
1500-
if (tempDirPath == null) {
1501-
throw new IOException("Java has no temporary folder property (java.io.tmpdir)?");
1502-
}
1503-
Path tempDirectory = Paths.get(tempDirPath);
1504-
if (!Files.isWritable(tempDirectory)) {
1505-
throw new IOException(
1506-
"Java's temporary folder not present or writeable?: " + tempDirectory.toAbsolutePath());
1507-
}
1508-
DEFAULT_TEMP_DIR = tempDirectory;
1498+
static Path getDefaultTempDir() throws IOException {
1499+
String tmpDir = System.getProperty("java.io.tmpdir");
1500+
if (tmpDir == null) {
1501+
throw new IOException("No temporary path (java.io.tmpdir)?");
15091502
}
1510-
1511-
return DEFAULT_TEMP_DIR;
1503+
Path tmpPath = Paths.get(tmpDir);
1504+
if (!Files.isWritable(tmpPath)) {
1505+
throw new IOException(
1506+
"Temporary path not present or writeable?: " + tmpPath.toAbsolutePath());
1507+
}
1508+
return tmpPath;
15121509
}
15131510

15141511
/** Possible word breaks according to BREAK directives */

0 commit comments

Comments
 (0)