You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2013/12/13 20:47:07 UTC

[jira] [Commented] (SOLR-5555) CloudSolrServer need not declare to throw MalformedURLException

    [ https://issues.apache.org/jira/browse/SOLR-5555?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13847846#comment-13847846 ] 

ASF subversion and git services commented on SOLR-5555:
-------------------------------------------------------

Commit 1550824 from [~romseygeek] in branch 'dev/trunk'
[ https://svn.apache.org/r1550824 ]

SOLR-5555: CloudSolrServer and LBHttpSolrServer shouldn't throw MUE from constructors

> 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
>            Assignee: Alan Woodward
>         Attachments: SOLR-5555.patch, SOLR-5555.patch
>
>
> 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: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org