Skip to content

Apache Lucene open-source search software

LUCENE-4199: fix some String.formats

Robert Muir2b4f7762cd81
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/HunspellDictionary.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/HunspellDictionary.java
index 135584e2825..626b0cb6ef3 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/HunspellDictionary.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/HunspellDictionary.java
@@ -252,7 +252,7 @@ public class HunspellDictionary {
}
String condition = ruleArgs[4];
- affix.setCondition(condition, String.format(conditionPattern, condition));
+ affix.setCondition(condition, String.format(Locale.ROOT, conditionPattern, condition));
affix.setCrossProduct(crossProduct);
List<HunspellAffix> list = affixes.get(affix.getAppend());
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestCharArraySet.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestCharArraySet.java
index 0eb55aa155a..db4d30bfb34 100755
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestCharArraySet.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestCharArraySet.java
@@ -208,16 +208,16 @@ public class TestCharArraySet extends LuceneTestCase {
set.add(upper);
}
for (int i = 0; i < upperArr.length; i++) {
- assertTrue(String.format(missing, upperArr[i]), set.contains(upperArr[i]));
- assertTrue(String.format(missing, lowerArr[i]), set.contains(lowerArr[i]));
+ assertTrue(String.format(Locale.ROOT, missing, upperArr[i]), set.contains(upperArr[i]));
+ assertTrue(String.format(Locale.ROOT, missing, lowerArr[i]), set.contains(lowerArr[i]));
}
set = new CharArraySet(TEST_VERSION_CURRENT, Arrays.asList(TEST_STOP_WORDS), false);
for (String upper : upperArr) {
set.add(upper);
}
for (int i = 0; i < upperArr.length; i++) {
- assertTrue(String.format(missing, upperArr[i]), set.contains(upperArr[i]));
- assertFalse(String.format(falsePos, lowerArr[i]), set.contains(lowerArr[i]));
+ assertTrue(String.format(Locale.ROOT, missing, upperArr[i]), set.contains(upperArr[i]));
+ assertFalse(String.format(Locale.ROOT, falsePos, lowerArr[i]), set.contains(lowerArr[i]));
}
}
@@ -235,8 +235,8 @@ public class TestCharArraySet extends LuceneTestCase {
set.add(upper);
}
for (int i = 0; i < upperArr.length; i++) {
- assertTrue(String.format(missing, upperArr[i]), set.contains(upperArr[i]));
- assertTrue(String.format(missing, lowerArr[i]), set.contains(lowerArr[i]));
+ assertTrue(String.format(Locale.ROOT, missing, upperArr[i]), set.contains(upperArr[i]));
+ assertTrue(String.format(Locale.ROOT, missing, lowerArr[i]), set.contains(lowerArr[i]));
}
set = new CharArraySet(TEST_VERSION_CURRENT, Arrays.asList(TEST_STOP_WORDS),
false);
@@ -244,8 +244,8 @@ public class TestCharArraySet extends LuceneTestCase {
set.add(upper);
}
for (int i = 0; i < upperArr.length; i++) {
- assertTrue(String.format(missing, upperArr[i]), set.contains(upperArr[i]));
- assertFalse(String.format(falsePos, upperArr[i]), set
+ assertTrue(String.format(Locale.ROOT, missing, upperArr[i]), set.contains(upperArr[i]));
+ assertFalse(String.format(Locale.ROOT, falsePos, upperArr[i]), set
.contains(lowerArr[i]));
}
}
diff --git a/lucene/core/src/java/org/apache/lucene/util/NamedThreadFactory.java b/lucene/core/src/java/org/apache/lucene/util/NamedThreadFactory.java
index 236670eaa1c..84a94c54438 100644
--- a/lucene/core/src/java/org/apache/lucene/util/NamedThreadFactory.java
+++ b/lucene/core/src/java/org/apache/lucene/util/NamedThreadFactory.java
@@ -17,6 +17,7 @@ package org.apache.lucene.util;
* limitations under the License.
*/
+import java.util.Locale;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
@@ -43,7 +44,7 @@ public class NamedThreadFactory implements ThreadFactory {
final SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() : Thread.currentThread()
.getThreadGroup();
- this.threadNamePrefix = String.format(NAME_PATTERN,
+ this.threadNamePrefix = String.format(Locale.ROOT, NAME_PATTERN,
checkPrefix(threadNamePrefix), threadPoolNumber.getAndIncrement());
}
@@ -57,7 +58,7 @@ public class NamedThreadFactory implements ThreadFactory {
* @see java.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
*/
public Thread newThread(Runnable r) {
- final Thread t = new Thread(group, r, String.format("%s-%d",
+ final Thread t = new Thread(group, r, String.format(Locale.ROOT, "%s-%d",
this.threadNamePrefix, threadNumber.getAndIncrement()), 0);
t.setDaemon(false);
t.setPriority(Thread.NORM_PRIORITY);
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java b/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java
index 55c82d26d84..0ffe41ec296 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Locale;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -261,7 +262,7 @@ public class TestFieldCache extends LuceneTestCase {
if (chunk == 0) {
for (int ord = 0; ord < values.size(); ord++) {
BytesRef term = values.get(ord);
- assertNull(String.format("Document[%d] misses field must be null. Has value %s for ord %d", i, term, ord), term);
+ assertNull(String.format(Locale.ROOT, "Document[%d] misses field must be null. Has value %s for ord %d", i, term, ord), term);
}
break;
}
@@ -275,7 +276,7 @@ public class TestFieldCache extends LuceneTestCase {
reuse = termOrds.lookup(i, reuse);
reuse.read(buffer);
}
- assertTrue(String.format("Expected value %s for doc %d and ord %d, but was %s", expected, i, idx, actual), expected.equals(actual));
+ assertTrue(String.format(Locale.ROOT, "Expected value %s for doc %d and ord %d, but was %s", expected, i, idx, actual), expected.equals(actual));
}
if (chunk <= buffer.length) {
diff --git a/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java b/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java
index 27ff14de943..906921e18e1 100644
--- a/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java
+++ b/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java
@@ -1637,7 +1637,7 @@ public class TestFSTs extends LuceneTestCase {
String idString;
if (cycle == 0) {
// PKs are assigned sequentially
- idString = String.format("%07d", id);
+ idString = String.format(Locale.ROOT, "%07d", id);
} else {
while(true) {
final String s = Long.toString(random().nextLong());
@@ -1668,7 +1668,7 @@ public class TestFSTs extends LuceneTestCase {
for(int idx=0;idx<NUM_IDS/10;idx++) {
String idString;
if (cycle == 0) {
- idString = String.format("%07d", (NUM_IDS + idx));
+ idString = String.format(Locale.ROOT, "%07d", (NUM_IDS + idx));
} else {
while(true) {
idString = Long.toString(random().nextLong());
@@ -1710,8 +1710,8 @@ public class TestFSTs extends LuceneTestCase {
exists = false;
final int idv = random().nextInt(NUM_IDS-1);
if (cycle == 0) {
- id = String.format("%07da", idv);
- nextID = String.format("%07d", idv+1);
+ id = String.format(Locale.ROOT, "%07da", idv);
+ nextID = String.format(Locale.ROOT, "%07d", idv+1);
} else {
id = sortedAllIDsList.get(idv) + "a";
nextID = sortedAllIDsList.get(idv+1);
diff --git a/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java b/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
index 8140d1305ac..efb2ceb9b56 100644
--- a/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
+++ b/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
@@ -20,6 +20,7 @@ package org.apache.lucene.util.packed;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.Random;
import org.apache.lucene.codecs.CodecUtil;
@@ -267,7 +268,7 @@ public class TestPackedInts extends LuceneTestCase {
fill(packedInt, PackedInts.maxValue(bitsPerValue), randomSeed);
} catch (Exception e) {
e.printStackTrace(System.err);
- fail(String.format(
+ fail(String.format(Locale.ROOT,
"Exception while filling %s: valueCount=%d, bitsPerValue=%s",
packedInt.getClass().getSimpleName(),
valueCount, bitsPerValue));
@@ -311,7 +312,7 @@ public class TestPackedInts extends LuceneTestCase {
for (int i = 0 ; i < packedInt.size() ; i++) {
long value = _TestUtil.nextLong(rnd2, 0, maxValue);
packedInt.set(i, value);
- assertEquals(String.format(
+ assertEquals(String.format(Locale.ROOT,
"The set/get of the value at index %d should match for %s",
i, packedInt.getClass().getSimpleName()),
value, packedInt.get(i));
@@ -336,7 +337,7 @@ public class TestPackedInts extends LuceneTestCase {
}
for (int i = 0 ; i < valueCount ; i++) {
for (int j = 1 ; j < packedInts.size() ; j++) {
- assertEquals(String.format(
+ assertEquals(String.format(Locale.ROOT,
"%s. The value at index %d should be the same for %s and %s",
message, i, base.getClass().getSimpleName(),
packedInts.get(j).getClass().getSimpleName()),