Skip to content

Update org.apache.solr.cli classes to not use deprecated methods.#4142

Merged
epugh merged 9 commits into
apache:mainfrom
epugh:fix_commons_cli_deprecated_calls
Feb 26, 2026
Merged

Update org.apache.solr.cli classes to not use deprecated methods.#4142
epugh merged 9 commits into
apache:mainfrom
epugh:fix_commons_cli_deprecated_calls

Conversation

@epugh

@epugh epugh commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

Description

The org.apache.solr.cli.* classes are using various deprecated methods from Commons CLI and Commons Exec libraries.

This PR updates them. In the process I also took what I've learned in Java coding, and went through and cleaned up various lint warnings.

I also got a NICE clean up in ZkSubcommandsTest, there was a bunch of cruft in it.

Nothing here is user facing.

One thing I did not tackle, is we need to flip our assertsEquals... We do assertEquals(actual,expected) but we should be doing assertEquals(expected,actuals).

Solution

Make edits, rerun the tests.

Tests

Just existing tests.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates the org.apache.solr.cli classes to eliminate the use of deprecated methods from Commons CLI and Commons Exec libraries. As part of this modernization effort, the PR also addresses various lint warnings and performs code cleanup including:

  • Updating Option.builder().build() to Option.builder().get() across all CLI tool classes
  • Replacing DefaultExecutor constructor with DefaultExecutor.Builder<>().get()
  • Removing deprecated cloudSolrClient.connect() calls
  • Converting a class to a record (SolrProcessManager.SolrProcess)
  • Modernizing string operations (length() > 0isEmpty())
  • Improving thread interruption handling (Thread.interrupted()Thread.currentThread().interrupt())
  • Converting string concatenation to text blocks
  • Various test cleanup and simplifications

Changes:

  • Commons CLI deprecated method replacements (.build().get() for Option builders)
  • Commons Exec deprecated method replacements (DefaultExecutor constructor → builder pattern)
  • Code modernization (records, text blocks, improved interrupt handling)
  • Test cleanup (removed unused variables, simplified code, fixed typos)

Reviewed changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ZkSubcommandsTest.java Test cleanup: removed unused variables and imports, updated ACL provider setup
TestSolrCLIRunExample.java Updated to use RandomizingCloudHttp2SolrClientBuilder, modernized thread handling, fixed variable initialization
TestExportTool.java Removed unnecessary string concatenation in assertions
StreamToolTest.java Added IOException to method signature
SolrProcessManagerTest.java Updated method calls to use record accessors (getPort() → port()), improved comment grammar
PostToolTest.java Added try-with-resources for BufferedWriter, converted to text block
CLITestHelper.java Added assert statements for null checks
ApiToolTest.java Removed unused Exception from method signature
Multiple Tool classes Updated Option.builder().build() to .get() throughout
SolrCLI.java Updated HelpFormatter API usage, modernized DefaultParser usage
RunExampleTool.java Converted JSON strings to text blocks, improved interrupt handling, fixed executor instantiation
SolrProcessManager.java Converted SolrProcess class to record, modernized stream operations
StatusTool.java Updated Option builders, simplified return statement
AuthTool.java Added block scope to switch cases, converted strings to text blocks
AssertTool.java Renamed and inverted logic of isSolrRunningOn → isSolrStoppedOn for clarity
Various tools Removed deprecated cloudSolrClient.connect() calls, improved thread sleep patterns

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread solr/core/src/java/org/apache/solr/cli/RunExampleTool.java Outdated
Comment thread solr/core/src/java/org/apache/solr/cli/RunExampleTool.java Outdated
@epugh

epugh commented Feb 17, 2026

Copy link
Copy Markdown
Contributor Author

Here is what the formatting of the --help looks like now, it's almost exact same as previously:

➜  dev git:(fix_commons_cli_deprecated_calls) ✗ bin/solr create -h
usage:  bin/solr create -c <NAME> [-d <DIR>] [-h] [-n <NAME>] [-rf <#>] [-s <HOST>] [-sh <#>] [-u <credentials>] [-v] [-z <HOST>]

Creates a core or collection depending on whether Solr is running in standalone (core) or SolrCloud mode (collection).
If you are using standalone mode you must run this command on the Solr server itself.

List of options:
                                                                                                                        
-h, --help                          Print this message.                                                                 
-v, --verbose                       Enable verbose command output.                                                      
-c, --name <NAME>                   Name of collection or core to create.                                               
-sh, --shards <#>                   Number of shards; default is 1.                                                     
-rf, --replication-factor <#>       Number of copies of each document across the collection (replicas per shard);       
                                     default is 1.                                                                      
-d, --conf-dir <DIR>                Configuration directory to copy when creating the new collection; default is        
                                     _default.                                                                          
-n, --conf-name <NAME>              Configuration name; default is the collection name.                                 
-u, --credentials <credentials>     Credentials in the format username:password. Example: --credentials solr:SolrRocks  
-s, --solr-url <HOST>               Base Solr URL, which can be used to determine the zk-host if that's not known;      
                                     defaults to: http://localhost:8983.                                                
-z, --zk-host <HOST>                Zookeeper connection string; unnecessary if ZK_HOST is defined in solr.in.sh;       
                                     otherwise, defaults to localhost:9983.                                             


Please see the Reference Guide for more tools documentation: https://solr.apache.org/guide/solr/latest/deployment-guide/solr-control-script-reference.html
➜  dev git:(fix_commons_cli_deprecated_calls) ✗ 

@epugh epugh requested a review from dsmiley February 19, 2026 15:15
@epugh epugh requested a review from malliaridis February 25, 2026 15:21
@epugh

epugh commented Feb 25, 2026

Copy link
Copy Markdown
Contributor Author

I've updated this merge conflicts and I'm looking for some plus 1's. I'm hoping to merge this on Thursday and then take another run at removing more code from our bin/solr scripts aroudn the "bin/solr start -h" command!

@epugh

epugh commented Feb 26, 2026

Copy link
Copy Markdown
Contributor Author

Manual testing done.

@epugh epugh merged commit c1ac036 into apache:main Feb 26, 2026
5 of 6 checks passed
epugh added a commit that referenced this pull request Feb 26, 2026
)

Update calls that use deprecated methods, and general review of code quality.  Use more modern java patterns where possible.

(cherry picked from commit c1ac036)

@malliaridis malliaridis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this is fine. I didn't find the time to review it earlier, but better late than never.

I left a few notes / questions here, but overall this is a nice cleanup. This starts to look a lot like Kotlin syntax. 😁

+ " }\n"
+ " }");
"""
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation of these json objects could be reduced to line up with the opening bracket

return;
}
// Create a new TableDefinition with empty headers to suppress the header row
java.util.List<String> emptyHeaders =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is java.util.List not imported? Why is it written out here? Same applies to values below.

@Override
public int compareTo(ReplicaHealth other) {
if (this == other) return 0;
if (other == null) return 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the removal of this line not making a difference in performance?

}
try (var cloudSolrClient = CLIUtils.getCloudSolrClient(zkHost)) {
echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...");
cloudSolrClient.connect();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the following command run the connect command already, which is why you removed this line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants