Sushil Bajracharya created SOLR-5555:
----------------------------------------
Summary: CloudSolrServer need not declare to throw
MalformedURLException
Key: SOLR-5555
URL: https://issues.apache.org/jira/browse/SOLR-5555
Project: Solr
Issue Type: Improvement
Components: SolrCloud
Affects Versions: 4.6
Reporter: Sushil Bajracharya
Currently CloudSolrServer declares to throw MalformedURLException for some of
its constructors. This does not seem necessary.
Details based on looking through Solr 4.6 release code:
CloudSolrServer has the following constructor that declares a checked exception
MalformedURLException..
{code}
public CloudSolrServer(String zkHost) throws MalformedURLException {
this.zkHost = zkHost;
this.myClient = HttpClientUtil.createClient(null);
this.lbServer = new LBHttpSolrServer(myClient);
this.lbServer.setRequestWriter(new BinaryRequestWriter());
this.lbServer.setParser(new BinaryResponseParser());
this.updatesToLeaders = true;
shutdownLBHttpSolrServer = true;
}
{code}
The only thing that seemed capable of throwing MalformedURLException seems to
be LBHttpSolrServer’s constructor:
{code}
public LBHttpSolrServer(HttpClient httpClient, String... solrServerUrl)
throws MalformedURLException {
this(httpClient, new BinaryResponseParser(), solrServerUrl);
}
{code}
which calls ..
{code}
public LBHttpSolrServer(HttpClient httpClient, ResponseParser parser,
String... solrServerUrl)
throws MalformedURLException {
clientIsInternal = (httpClient == null);
this.parser = parser;
if (httpClient == null) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(HttpClientUtil.PROP_USE_RETRY, false);
this.httpClient = HttpClientUtil.createClient(params);
} else {
this.httpClient = httpClient;
}
for (String s : solrServerUrl) {
ServerWrapper wrapper = new ServerWrapper(makeServer(s));
aliveServers.put(wrapper.getKey(), wrapper);
}
updateAliveList();
}
{code}
which calls ..
{code}
protected HttpSolrServer makeServer(String server) throws MalformedURLException
{
HttpSolrServer s = new HttpSolrServer(server, httpClient, parser);
if (requestWriter != null) {
s.setRequestWriter(requestWriter);
}
if (queryParams != null) {
s.setQueryParams(queryParams);
}
return s;
}
{code}
Note that makeServer(String server) above does not need to throw
MalformedURLException.. sine the only thing that seems capable of throwing
MalformedURLException is HttpSolrServer’s constructor (which does not):
{code}
public HttpSolrServer(String baseURL, HttpClient client, ResponseParser parser)
{
this.baseUrl = baseURL;
if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
}
if (baseUrl.indexOf('?') >= 0) {
throw new RuntimeException(
"Invalid base url for solrj. The base URL must not contain
parameters: "
+ baseUrl);
}
if (client != null) {
httpClient = client;
internalClient = false;
} else {
internalClient = true;
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 128);
params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 32);
params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, followRedirects);
httpClient = HttpClientUtil.createClient(params);
}
this.parser = parser;
}
{code}
I see nothing above that’d throw MalformedURLException. It is throwing a
RuntimeException when the baseUrl does not match certain pattern, may be that
was intended to be a MalformedURLException.
It seems like an error or oversight that CloudSolrServer declares to throw
MalformedURLException for some of its constructors.
This could be fixed by making LBHttpSolrServer not declare the
MalformedURLException, and thus other callers to it do not need to do so.
--
This message was sent by Atlassian JIRA
(v6.1.4#6159)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]