Skip to content

Commit b805e90

Browse files
committed
Fix compiler warnings.
1 parent 043cbda commit b805e90

8 files changed

Lines changed: 16 additions & 21 deletions

File tree

src/main/java/org/apache/commons/cli/DefaultParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ public CommandLine parse(final Options options, final String[] arguments, final
578578
this.stopAtNonOption = stopAtNonOption;
579579
skipParsing = false;
580580
currentOption = null;
581-
expectedOpts = new ArrayList(options.getRequiredOptions());
581+
expectedOpts = new ArrayList<>(options.getRequiredOptions());
582582

583583
// clear the data from the groups
584584
for (final OptionGroup group : options.getOptionGroups()) {

src/main/java/org/apache/commons/cli/Parser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ protected void processProperties(final Properties properties) throws ParseExcept
329329

330330
protected void setOptions(final Options options) {
331331
this.options = options;
332-
this.requiredOptions = new ArrayList(options.getRequiredOptions());
332+
this.requiredOptions = new ArrayList<>(options.getRequiredOptions());
333333
}
334334

335335
/**

src/test/java/org/apache/commons/cli/CommandLineTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2929
public class CommandLineTest {
3030

3131
@Test
32-
public void testBuilder() throws Exception {
32+
public void testBuilder() {
3333
final CommandLine.Builder builder = new CommandLine.Builder();
3434
builder.addArg("foo").addArg("bar");
3535
builder.addOption(Option.builder("T").build());

src/test/java/org/apache/commons/cli/HelpFormatterTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testAccessors() {
6363
}
6464

6565
@Test
66-
public void testAutomaticUsage() throws Exception {
66+
public void testAutomaticUsage() {
6767
final HelpFormatter hf = new HelpFormatter();
6868
Options options;
6969
String expected = "usage: app [-a]";
@@ -101,7 +101,7 @@ public void testDefaultArgName() {
101101
}
102102

103103
@Test
104-
public void testFindWrapPos() throws Exception {
104+
public void testFindWrapPos() {
105105
final HelpFormatter hf = new HelpFormatter();
106106

107107
String text = "This is a test.";
@@ -148,7 +148,7 @@ public void testHeaderStartingWithLineSeparator() {
148148
}
149149

150150
@Test
151-
public void testHelpWithLongOptSeparator() throws Exception {
151+
public void testHelpWithLongOptSeparator() {
152152
final Options options = new Options();
153153
options.addOption("f", true, "the file");
154154
options.addOption(Option.builder("s").longOpt("size").desc("the size").hasArg().argName("SIZE").build());
@@ -329,7 +329,7 @@ public void testPrintOptionGroupUsage() {
329329
}
330330

331331
@Test
332-
public void testPrintOptions() throws Exception {
332+
public void testPrintOptions() {
333333
final StringBuffer sb = new StringBuffer();
334334
final HelpFormatter hf = new HelpFormatter();
335335
final int leftPad = 1;
@@ -458,9 +458,9 @@ public void testPrintUsage() {
458458
opts.addOption(optionC);
459459
final HelpFormatter helpFormatter = new HelpFormatter();
460460
final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
461-
final PrintWriter printWriter = new PrintWriter(bytesOut);
462-
helpFormatter.printUsage(printWriter, 80, "app", opts);
463-
printWriter.close();
461+
try (final PrintWriter printWriter = new PrintWriter(bytesOut)) {
462+
helpFormatter.printUsage(printWriter, 80, "app", opts);
463+
}
464464
assertEquals("usage: app [-a] [-b] [-c]" + EOL, bytesOut.toString());
465465
}
466466

@@ -565,7 +565,7 @@ public void testRtrim() {
565565
}
566566

567567
@Test
568-
public void testUsageWithLongOptSeparator() throws Exception {
568+
public void testUsageWithLongOptSeparator() {
569569
final Options options = new Options();
570570
options.addOption("f", true, "the file");
571571
options.addOption(Option.builder("s").longOpt("size").desc("the size").hasArg().argName("SIZE").build());

src/test/java/org/apache/commons/cli/PatternOptionBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void testClassPattern() throws Exception {
4949
}
5050

5151
@Test
52-
public void testEmptyPattern() throws Exception {
52+
public void testEmptyPattern() {
5353
final Options options = PatternOptionBuilder.parsePattern("");
5454
assertTrue(options.getOptions().isEmpty());
5555
}

src/test/java/org/apache/commons/cli/bug/BugCLI162Test.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ public class BugCLI162Test {
8484

8585
private static final String OPT_SQL_L = "sql";
8686

87-
private static final String OPT_SQL_SPLIT_DEFAULT = "###";
88-
89-
private static final String OPT_SQL_SPLIT_L = "splitSql";
90-
9187
private static final String OPT_STACK_TRACE = "t";
9288

9389
private static final String OPT_TIMING = "g";
@@ -113,7 +109,7 @@ public class BugCLI162Test {
113109
private StringWriter sw;
114110

115111
@Before
116-
public void setUp() throws Exception {
112+
public void setUp() {
117113
formatter = new HelpFormatter();
118114
sw = new StringWriter();
119115
}

src/test/java/org/apache/commons/cli/bug/BugCLI265Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class BugCLI265Test {
4141
private Options options;
4242

4343
@Before
44-
public void setUp() throws Exception {
44+
public void setUp() {
4545
parser = new DefaultParser();
4646

4747
final Option optionT1 = Option.builder("t1").hasArg().numberOfArgs(1).optionalArg(true).argName("t1_path").build();

src/test/java/org/apache/commons/cli/bug/BugCLI266Test.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.apache.commons.cli.Option;
2828
import org.apache.commons.cli.OptionGroup;
2929
import org.apache.commons.cli.Options;
30-
import org.apache.commons.cli.ParseException;
3130
import org.junit.Assert;
3231
import org.junit.Test;
3332

@@ -105,7 +104,7 @@ private Options getOptions() {
105104
}
106105

107106
@Test
108-
public void testOptionComparatorDefaultOrder() throws ParseException {
107+
public void testOptionComparatorDefaultOrder() {
109108
final HelpFormatter formatter = new HelpFormatter();
110109
final List<Option> options = new ArrayList<>(getOptions().getOptions());
111110
Collections.sort(options, formatter.getOptionComparator());
@@ -117,7 +116,7 @@ public void testOptionComparatorDefaultOrder() throws ParseException {
117116
}
118117

119118
@Test
120-
public void testOptionComparatorInsertedOrder() throws ParseException {
119+
public void testOptionComparatorInsertedOrder() {
121120
final Collection<Option> options = getOptions().getOptions();
122121
int i = 0;
123122
for (final Option o : options) {

0 commit comments

Comments
 (0)