LUCENE-4199: fix remaining violations

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4199@1359188 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-07-09 14:22:20 +00:00
parent 46cb8b9780
commit 123b645157
15 changed files with 30 additions and 28 deletions

View File

@ -151,7 +151,7 @@ public class SnapShooter {
if(m.find()) { if(m.find()) {
try { try {
this.dir = dir; this.dir = dir;
this.timestamp = new SimpleDateFormat(DATE_FMT).parse(m.group(1)); this.timestamp = new SimpleDateFormat(DATE_FMT, Locale.ROOT).parse(m.group(1));
} catch(Exception e) { } catch(Exception e) {
this.dir = null; this.dir = null;
this.timestamp = null; this.timestamp = null;

View File

@ -19,12 +19,14 @@ package org.apache.solr.handler.admin;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.File; import java.io.File;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean; import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean; import java.lang.management.RuntimeMXBean;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
@ -180,7 +182,7 @@ public class SystemInfoHandler extends RequestHandlerBase
process = Runtime.getRuntime().exec(cmd); process = Runtime.getRuntime().exec(cmd);
in = new DataInputStream( process.getInputStream() ); in = new DataInputStream( process.getInputStream() );
// use default charset from locale here, because the command invoked also uses the default locale: // use default charset from locale here, because the command invoked also uses the default locale:
return IOUtils.toString(in); return IOUtils.toString(new InputStreamReader(in, Charset.defaultCharset()));
} }
catch( Exception ex ) { catch( Exception ex ) {
// ignore - log.warn("Error executing command", ex); // ignore - log.warn("Error executing command", ex);

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo; import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean; import java.lang.management.ThreadMXBean;
import java.util.Locale;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap; import org.apache.solr.common.util.SimpleOrderedMap;
@ -119,7 +120,7 @@ public class ThreadDumpHandler extends RequestHandlerBase
} }
private static String formatNanos(long ns) { private static String formatNanos(long ns) {
return String.format("%.4fms", ns / (double) 1000000); return String.format(Locale.ROOT, "%.4fms", ns / (double) 1000000);
} }
//////////////////////// SolrInfoMBeans methods ////////////////////// //////////////////////// SolrInfoMBeans methods //////////////////////

View File

@ -180,7 +180,7 @@ public class QueryComponent extends SearchComponent
try { try {
responseFormat = Grouping.Format.valueOf(formatStr); responseFormat = Grouping.Format.valueOf(formatStr);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, String.format("Illegal %s parameter", GroupParams.GROUP_FORMAT)); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, String.format(Locale.ROOT, "Illegal %s parameter", GroupParams.GROUP_FORMAT));
} }
groupingSpec.setResponseFormat(responseFormat); groupingSpec.setResponseFormat(responseFormat);
@ -386,7 +386,7 @@ public class QueryComponent extends SearchComponent
if (grouping.isSignalCacheWarning()) { if (grouping.isSignalCacheWarning()) {
rsp.add( rsp.add(
"cacheWarning", "cacheWarning",
String.format("Cache limit of %d percent relative to maxdoc has exceeded. Please increase cache size or disable caching.", maxDocsPercentageToCache) String.format(Locale.ROOT, "Cache limit of %d percent relative to maxdoc has exceeded. Please increase cache size or disable caching.", maxDocsPercentageToCache)
); );
} }
rb.setResult(result); rb.setResult(result);

View File

@ -105,16 +105,6 @@ public class CSVParser {
// the constructor // the constructor
// ====================================================== // ======================================================
/**
* Default strategy for the parser follows the default {@link CSVStrategy}.
*
* @param input an InputStream containing "csv-formatted" stream
* @deprecated use {@link #CSVParser(Reader)}.
*/
public CSVParser(InputStream input) {
this(new InputStreamReader(input));
}
/** /**
* CSV parser using the default {@link CSVStrategy}. * CSV parser using the default {@link CSVStrategy}.
* *

View File

@ -22,6 +22,8 @@ import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import org.apache.lucene.util.IOUtils;
/** /**
* Tries to guess a config based on an InputStream. * Tries to guess a config based on an InputStream.
* *
@ -74,7 +76,7 @@ public class CSVConfigGuesser {
public CSVConfig guess() { public CSVConfig guess() {
try { try {
// tralalal // tralalal
BufferedReader bIn = new BufferedReader(new InputStreamReader((getInputStream()))); BufferedReader bIn = new BufferedReader(new InputStreamReader(getInputStream(), IOUtils.CHARSET_UTF_8));
String[] lines = new String[10]; String[] lines = new String[10];
String line = null; String line = null;
int counter = 0; int counter = 0;

View File

@ -39,6 +39,7 @@ import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.queries.function.docvalues.FloatDocValues; import org.apache.lucene.queries.function.docvalues.FloatDocValues;
import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.RequestHandlerBase; import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.handler.RequestHandlerUtils; import org.apache.solr.handler.RequestHandlerUtils;
@ -224,7 +225,7 @@ public class FileFloatSource extends ValueSource {
return vals; return vals;
} }
BufferedReader r = new BufferedReader(new InputStreamReader(is)); BufferedReader r = new BufferedReader(new InputStreamReader(is, IOUtils.CHARSET_UTF_8));
String idName = ffs.keyField.getName(); String idName = ffs.keyField.getName();
FieldType idType = ffs.keyField.getType(); FieldType idType = ffs.keyField.getType();

View File

@ -77,7 +77,7 @@ public final class HttpCacheHeaderUtil {
etagCache = "\"" etagCache = "\""
+ new String(Base64.encodeBase64((Long.toHexString + new String(Base64.encodeBase64((Long.toHexString
(Long.reverse(indexVersionCache)) (Long.reverse(indexVersionCache))
+ etagSeed).getBytes()), "US-ASCII") + etagSeed).getBytes("US-ASCII")), "US-ASCII")
+ "\""; + "\"";
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new RuntimeException(e); // may not happen throw new RuntimeException(e); // may not happen

View File

@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.lucene.analysis.Token; import org.apache.lucene.analysis.Token;
@ -126,7 +127,7 @@ public class WordBreakSolrSpellChecker extends SolrSpellChecker {
wbsp = new WordBreakSpellChecker(); wbsp = new WordBreakSpellChecker();
String bstb = strParam(config, PARAM_BREAK_SUGGESTION_TIE_BREAKER); String bstb = strParam(config, PARAM_BREAK_SUGGESTION_TIE_BREAKER);
if (bstb != null) { if (bstb != null) {
bstb = bstb.toUpperCase(); bstb = bstb.toUpperCase(Locale.ROOT);
if (bstb.equals(BreakSuggestionTieBreaker.SUM_FREQ.name())) { if (bstb.equals(BreakSuggestionTieBreaker.SUM_FREQ.name())) {
sortMethod = BreakSuggestionSortMethod.NUM_CHANGES_THEN_SUMMED_FREQUENCY; sortMethod = BreakSuggestionSortMethod.NUM_CHANGES_THEN_SUMMED_FREQUENCY;
} else if (bstb.equals(BreakSuggestionTieBreaker.MAX_FREQ.name())) { } else if (bstb.equals(BreakSuggestionTieBreaker.MAX_FREQ.name())) {

View File

@ -75,7 +75,7 @@ public class SolrIndexWriter extends IndexWriter {
File parent = f.getParentFile(); File parent = f.getParentFile();
if (parent != null) parent.mkdirs(); if (parent != null) parent.mkdirs();
FileOutputStream fos = new FileOutputStream(f, true); FileOutputStream fos = new FileOutputStream(f, true);
return new PrintStreamInfoStream(new PrintStream(fos, true)); return new PrintStreamInfoStream(new PrintStream(fos, true, "UTF-8"));
} else { } else {
return InfoStream.NO_OUTPUT; return InfoStream.NO_OUTPUT;
} }

View File

@ -18,6 +18,7 @@
package org.apache.solr.util; package org.apache.solr.util;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Locale;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
@ -27,7 +28,7 @@ import org.apache.lucene.util.BytesRef;
public class NumberUtils { public class NumberUtils {
public static String readableSize(long size) { public static String readableSize(long size) {
NumberFormat formatter = NumberFormat.getNumberInstance(); NumberFormat formatter = NumberFormat.getNumberInstance(Locale.ROOT);
formatter.setMaximumFractionDigits(2); formatter.setMaximumFractionDigits(2);
if (size / (1024 * 1024 * 1024) > 0) { if (size / (1024 * 1024 * 1024) > 0) {
return formatter.format(size * 1.0d / (1024 * 1024 * 1024)) + " GB"; return formatter.format(size * 1.0d / (1024 * 1024 * 1024)) + " GB";

View File

@ -19,6 +19,7 @@ package org.apache.solr.handler.component;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.MapSolrParams; import org.apache.solr.common.params.MapSolrParams;
@ -34,6 +35,7 @@ import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -412,7 +414,7 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
// write a test file to boost some docs // write a test file to boost some docs
private void writeFile(File file, String query, String... ids) throws Exception { private void writeFile(File file, String query, String... ids) throws Exception {
PrintWriter out = new PrintWriter(new FileOutputStream(file)); PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), IOUtils.CHARSET_UTF_8));
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
out.println("<elevate>"); out.println("<elevate>");
out.println("<query text=\"" + query + "\">"); out.println("<query text=\"" + query + "\">");

View File

@ -43,7 +43,7 @@ public class CSVConfigGuesserTest extends TestCase {
* 1234 ; abcd ; 1234 ; * 1234 ; abcd ; 1234 ;
* *
*/ */
public void testConfigGuess1() { public void testConfigGuess1() throws Exception {
CSVConfig expected = new CSVConfig(); CSVConfig expected = new CSVConfig();
expected.setDelimiter(';'); expected.setDelimiter(';');
expected.setValueDelimiter(' '); expected.setValueDelimiter(' ');
@ -57,7 +57,7 @@ public class CSVConfigGuesserTest extends TestCase {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("1234;abcd;1234\n"); sb.append("1234;abcd;1234\n");
sb.append("abcd;1234;abcd"); sb.append("abcd;1234;abcd");
ByteArrayInputStream in = new ByteArrayInputStream(sb.toString().getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
CSVConfigGuesser guesser = new CSVConfigGuesser(in); CSVConfigGuesser guesser = new CSVConfigGuesser(in);
CSVConfig guessed = guesser.guess(); CSVConfig guessed = guesser.guess();
assertEquals(expected.isFixedWidth(), guessed.isFixedWidth()); assertEquals(expected.isFixedWidth(), guessed.isFixedWidth());
@ -70,7 +70,7 @@ public class CSVConfigGuesserTest extends TestCase {
* 1,2,3,4 * 1,2,3,4
* *
*/ */
public void testConfigGuess2() { public void testConfigGuess2() throws Exception {
CSVConfig expected = new CSVConfig(); CSVConfig expected = new CSVConfig();
expected.setDelimiter(';'); expected.setDelimiter(';');
expected.setValueDelimiter(' '); expected.setValueDelimiter(' ');
@ -80,7 +80,7 @@ public class CSVConfigGuesserTest extends TestCase {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("1,2,3,4\n"); sb.append("1,2,3,4\n");
sb.append("abcd,1234,abcd,1234"); sb.append("abcd,1234,abcd,1234");
ByteArrayInputStream in = new ByteArrayInputStream(sb.toString().getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
CSVConfigGuesser guesser = new CSVConfigGuesser(in); CSVConfigGuesser guesser = new CSVConfigGuesser(in);
CSVConfig guessed = guesser.guess(); CSVConfig guessed = guesser.guess();
assertEquals(expected.isFixedWidth(), guessed.isFixedWidth()); assertEquals(expected.isFixedWidth(), guessed.isFixedWidth());

View File

@ -26,6 +26,7 @@ import org.apache.solr.common.util.DateUtil;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone;
/** /**
* *
@ -139,7 +140,7 @@ public class SolrQueryTest extends LuceneTestCase {
public void testFacetDateRange() { public void testFacetDateRange() {
SolrQuery q = new SolrQuery("dog"); SolrQuery q = new SolrQuery("dog");
Calendar calendar = Calendar.getInstance(Locale.UK); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.UK);
calendar.set(2010, 1, 1); calendar.set(2010, 1, 1);
Date start = calendar.getTime(); Date start = calendar.getTime();
calendar.set(2011, 1, 1); calendar.set(2011, 1, 1);

View File

@ -19,6 +19,7 @@ package org.apache.solr.client.solrj.embedded;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStreamReader;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@ -169,7 +170,7 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {
Document document = builder.parse(fis); Document document = builder.parse(fis);
fis.close(); fis.close();
fis = new FileInputStream(new File(tempDir, SOLR_PERSIST_XML)); fis = new FileInputStream(new File(tempDir, SOLR_PERSIST_XML));
String solrPersistXml = IOUtils.toString(fis); String solrPersistXml = IOUtils.toString(new InputStreamReader(fis, "UTF-8"));
//System.out.println("xml:" + solrPersistXml); //System.out.println("xml:" + solrPersistXml);
assertTrue("\"/solr/cores[@defaultCoreName='core0']\" doesn't match in:\n" + solrPersistXml, assertTrue("\"/solr/cores[@defaultCoreName='core0']\" doesn't match in:\n" + solrPersistXml,
exists("/solr/cores[@defaultCoreName='core0']", document)); exists("/solr/cores[@defaultCoreName='core0']", document));