Skip to content

Commit d1df605

Browse files
committed
fixed javadocs and catch(Throwable) issues
1 parent c0c542f commit d1df605

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

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

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public String[] getOptionValues(final String opt) {
506506
*
507507
* @param opt the name of the option.
508508
* @param <T> The return type for the method.
509-
* @return the value parsed into a particular object.
509+
* @return the value parsed into a particular object or null if the option is not set.
510510
* @throws ParseException if there are problems turning the option value into the desired type
511511
* @see PatternOptionBuilder
512512
* @since 1.5.0
@@ -521,7 +521,7 @@ public <T> T getParsedOptionValue(final char opt) throws ParseException {
521521
* @param opt the name of the option.
522522
* @param defaultValue the default value to return if opt is not set.
523523
* @param <T> The return type for the method.
524-
* @return the value parsed into a particular object.
524+
* @return the value parsed into a particular object or the defaultValue if the option is not set.
525525
* @throws ParseException if there are problems turning the option value into the desired type
526526
* @see PatternOptionBuilder
527527
* @since 1.7.0
@@ -536,7 +536,7 @@ public <T> T getParsedOptionValue(final char opt, final Supplier<T> defaultValue
536536
* @param opt the name of the option.
537537
* @param defaultValue the default value to return if opt is not set.
538538
* @param <T> The return type for the method.
539-
* @return the value parsed into a particular object.
539+
* @return the value parsed into a particular object or the defaultValue if the option is not set.
540540
* @throws ParseException if there are problems turning the option value into the desired type
541541
* @see PatternOptionBuilder
542542
* @since 1.7.0
@@ -550,7 +550,7 @@ public <T> T getParsedOptionValue(final char opt, final T defaultValue) throws P
550550
*
551551
* @param option the option.
552552
* @param <T> The return type for the method.
553-
* @return the value parsed into a particular object.
553+
* @return the value parsed into a particular object or null if the option is not set.
554554
* @throws ParseException if there are problems turning the option value into the desired type
555555
* @see PatternOptionBuilder
556556
* @since 1.5.0
@@ -565,7 +565,7 @@ public <T> T getParsedOptionValue(final Option option) throws ParseException {
565565
* @param option the option.
566566
* @param defaultValue the default value to return if opt is not set.
567567
* @param <T> The return type for the method.
568-
* @return the value parsed into a particular object.
568+
* @return the value parsed into a particular object or the defaultValue if the option is not set.
569569
* @throws ParseException if there are problems turning the option value into the desired type
570570
* @see PatternOptionBuilder
571571
* @since 1.7.0
@@ -581,8 +581,13 @@ public <T> T getParsedOptionValue(final Option option, final Supplier<T> default
581581
return get(defaultValue);
582582
}
583583
return (T) option.getConverter().apply(res);
584-
} catch (final Throwable e) {
585-
throw ParseException.wrap(e);
584+
} catch (final Error t) {
585+
throw t;
586+
} catch (final Exception t) {
587+
throw ParseException.wrap(t);
588+
} catch (final Throwable t) {
589+
// this should not be reached.
590+
throw new RuntimeException(t);
586591
}
587592
}
588593

@@ -592,7 +597,7 @@ public <T> T getParsedOptionValue(final Option option, final Supplier<T> default
592597
* @param option the option.
593598
* @param defaultValue the default value to return if opt is not set.
594599
* @param <T> The return type for the method.
595-
* @return the value parsed into a particular object.
600+
* @return the value parsed into a particular object or the defaultValue if the option is not set.
596601
* @throws ParseException if there are problems turning the option value into the desired type
597602
* @see PatternOptionBuilder
598603
* @since 1.7.0
@@ -606,7 +611,7 @@ public <T> T getParsedOptionValue(final Option option, final T defaultValue) thr
606611
*
607612
* @param optionGroup the option group.
608613
* @param <T> The return type for the method.
609-
* @return the value parsed into a particular object.
614+
* @return the value parsed into a particular object or null if no option in the OptionGroup is set.
610615
* @throws ParseException if there are problems turning the selected option value into the desired type
611616
* @see PatternOptionBuilder
612617
* @since 1.9.0
@@ -621,7 +626,7 @@ public <T> T getParsedOptionValue(final OptionGroup optionGroup) throws ParseExc
621626
* @param optionGroup the option group.
622627
* @param defaultValue the default value to return if opt is not set.
623628
* @param <T> The return type for the method.
624-
* @return the value parsed into a particular object.
629+
* @return the value parsed into a particular object or the defaultValue if no option in the OptionGroup is set.
625630
* @throws ParseException if there are problems turning the selected option value into the desired type
626631
* @see PatternOptionBuilder
627632
* @since 1.9.0
@@ -639,7 +644,7 @@ public <T> T getParsedOptionValue(final OptionGroup optionGroup, final Supplier<
639644
* @param optionGroup the option group.
640645
* @param defaultValue the default value to return if an option is not selected.
641646
* @param <T> The return type for the method.
642-
* @return the value parsed into a particular object.
647+
* @return the value parsed into a particular object or the defaultValue if no option in the OptionGroup is set.
643648
* @throws ParseException if there are problems turning the option value into the desired type
644649
* @see PatternOptionBuilder
645650
* @since 1.9.0
@@ -653,7 +658,7 @@ public <T> T getParsedOptionValue(final OptionGroup optionGroup, final T default
653658
*
654659
* @param opt the name of the option.
655660
* @param <T> The return type for the method.
656-
* @return the value parsed into a particular object.
661+
* @return the value parsed into a particular object or null if the option is not set.
657662
* @throws ParseException if there are problems turning the option value into the desired type
658663
* @see PatternOptionBuilder
659664
* @since 1.2
@@ -668,7 +673,7 @@ public <T> T getParsedOptionValue(final String opt) throws ParseException {
668673
* @param opt the name of the option.
669674
* @param defaultValue the default value to return if opt is not set.
670675
* @param <T> The return type for the method.
671-
* @return the value parsed into a particular object.
676+
* @return the value parsed into a particular object or the defaultValue if the option is not set.
672677
* @throws ParseException if there are problems turning the option value into the desired type
673678
* @see PatternOptionBuilder
674679
* @since 1.7.0
@@ -683,7 +688,7 @@ public <T> T getParsedOptionValue(final String opt, final Supplier<T> defaultVal
683688
* @param opt the name of the option.
684689
* @param defaultValue the default value to return if opt is not set.
685690
* @param <T> The return type for the method.
686-
* @return the value parsed into a particular object.
691+
* @return the value parsed into a particular object or the defaultValue if the option is not set.
687692
* @throws ParseException if there are problems turning the option value into the desired type
688693
* @see PatternOptionBuilder
689694
* @since 1.7.0
@@ -697,7 +702,7 @@ public <T> T getParsedOptionValue(final String opt, final T defaultValue) throws
697702
*
698703
* @param opt the name of the option.
699704
* @param <T> The array type for the return value.
700-
* @return the values parsed into an array of objects.
705+
* @return the values parsed into an array of objects or null if the option is not set.
701706
* @throws ParseException if there are problems turning the option value into the desired type
702707
* @see PatternOptionBuilder
703708
* @since 1.10.0
@@ -712,7 +717,7 @@ public <T> T[] getParsedOptionValues(final char opt) throws ParseException {
712717
* @param opt the name of the option.
713718
* @param defaultValue the default value to return if opt is not set.
714719
* @param <T> The array type for the return value.
715-
* @return the values parsed into an array of objects.
720+
* @return the values parsed into an array of objects or the defaultValue if the option is not set.
716721
* @throws ParseException if there are problems turning the option value into the desired type
717722
* @see PatternOptionBuilder
718723
* @since 1.10.0
@@ -727,7 +732,7 @@ public <T> T[] getParsedOptionValues(final char opt, final Supplier<T[]> default
727732
* @param opt the name of the option.
728733
* @param defaultValue the default value to return if opt is not set.
729734
* @param <T> The array type for the return value.
730-
* @return the values parsed into an array of objects.
735+
* @return the values parsed into an array of objects or the defaultValue if the option is not set.
731736
* @throws ParseException if there are problems turning the option value into the desired type
732737
* @see PatternOptionBuilder
733738
* @since 1.10.0
@@ -741,7 +746,7 @@ public <T> T[] getParsedOptionValues(final char opt, final T[] defaultValue) thr
741746
*
742747
* @param option the option.
743748
* @param <T> The array type for the return value.
744-
* @return the values parsed into an array of objects.
749+
* @return the values parsed into an array of objects or null if the option is not set.
745750
* @throws ParseException if there are problems turning the option value into the desired type
746751
* @see PatternOptionBuilder
747752
* @since 1.10.0
@@ -756,7 +761,7 @@ public <T> T[] getParsedOptionValues(final Option option) throws ParseException
756761
* @param option the option.
757762
* @param defaultValue the default value to return if opt is not set.
758763
* @param <T> The array type for the return value.
759-
* @return the values parsed into an array of objects.
764+
* @return the values parsed into an array of objects or the defaultValue if the option is not set.
760765
* @throws ParseException if there are problems turning the option value into the desired type
761766
* @see PatternOptionBuilder
762767
* @since 1.10.0
@@ -777,10 +782,14 @@ public <T> T[] getParsedOptionValues(final Option option, final Supplier<T[]> de
777782
result[i] = clazz.cast(option.getConverter().apply(values[i]));
778783
}
779784
return result;
780-
} catch (Throwable t) {
785+
} catch (final Error t) {
786+
throw t;
787+
} catch (final Exception t) {
781788
throw ParseException.wrap(t);
789+
} catch (final Throwable t) {
790+
// this should not be reached.
791+
throw new RuntimeException(t);
782792
}
783-
784793
}
785794

786795
/**
@@ -789,7 +798,7 @@ public <T> T[] getParsedOptionValues(final Option option, final Supplier<T[]> de
789798
* @param option the option.
790799
* @param defaultValue the default value to return if opt is not set.
791800
* @param <T> The array type for the return value.
792-
* @return the values parsed into an array of objects.
801+
* @return the values parsed into an array of objects or the defaultValue if the option is not set.
793802
* @throws ParseException if there are problems turning the option value into the desired type
794803
* @see PatternOptionBuilder
795804
* @since 1.10.0
@@ -803,7 +812,7 @@ public <T> T[] getParsedOptionValues(final Option option, final T[] defaultValue
803812
*
804813
* @param optionGroup the option group.
805814
* @param <T> The array type for the return value.
806-
* @return the values parsed into an array of objects.
815+
* @return the values parsed into an array of objects or null if no option in the OptionGroup is set.
807816
* @throws ParseException if there are problems turning the selected option value into the desired type
808817
* @see PatternOptionBuilder
809818
* @since 1.10.0
@@ -818,7 +827,7 @@ public <T> T[] getParsedOptionValues(final OptionGroup optionGroup) throws Parse
818827
* @param optionGroup the option group.
819828
* @param defaultValue the default value to return if opt is not set.
820829
* @param <T> The array type for the return value.
821-
* @return the values parsed into an array of objects.
830+
* @return the values parsed into an array of objects or null if no option in the OptionGroup is set.
822831
* @throws ParseException if there are problems turning the selected option value into the desired type
823832
* @see PatternOptionBuilder
824833
* @since 1.10.0
@@ -836,7 +845,7 @@ public <T> T[] getParsedOptionValues(final OptionGroup optionGroup, final Suppli
836845
* @param optionGroup the option group.
837846
* @param defaultValue the default value to return if an option is not selected.
838847
* @param <T> The array type for the return value.
839-
* @return the values parsed into an array of objects.
848+
* @return the values parsed into an array of objects or null if no option in the OptionGroup is set.
840849
* @throws ParseException if there are problems turning the option value into the desired type
841850
* @see PatternOptionBuilder
842851
* @since 1.10.0
@@ -850,7 +859,7 @@ public <T> T[] getParsedOptionValues(final OptionGroup optionGroup, final T[] de
850859
*
851860
* @param opt the name of the option.
852861
* @param <T> The array type for the return value.
853-
* @return the values parsed into an array of objects.
862+
* @return the values parsed into an array of objects or null if the option is not set.
854863
* @throws ParseException if there are problems turning the option value into the desired type
855864
* @see PatternOptionBuilder
856865
* @since 1.10.0
@@ -865,7 +874,7 @@ public <T> T[] getParsedOptionValues(final String opt) throws ParseException {
865874
* @param opt the name of the option.
866875
* @param defaultValue the default value to return if opt is not set.
867876
* @param <T> The array type for the return value.
868-
* @return the values parsed into an array of objects.
877+
* @return the values parsed into an array of objects or defaultValues if the option is not set.
869878
* @throws ParseException if there are problems turning the option value into the desired type
870879
* @see PatternOptionBuilder
871880
* @since 1.10.0
@@ -880,7 +889,7 @@ public <T> T[] getParsedOptionValues(final String opt, final Supplier<T[]> defau
880889
* @param opt the name of the option.
881890
* @param defaultValue the default value to return if opt is not set.
882891
* @param <T> The array type for the return value.
883-
* @return the values parsed into an array of objects.
892+
* @return the values parsed into an array of objects or defaultValues if the option is not set.
884893
* @throws ParseException if there are problems turning the option value into the desired type
885894
* @see PatternOptionBuilder
886895
* @since 1.10.0

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,9 +713,9 @@ public String getValue(final String defaultValue) {
713713
}
714714

715715
/**
716-
* Gets the values of this Option as a String array or null if there are no values.
716+
* Gets the values of this Option as a String array or an empty array if there are no values.
717717
*
718-
* @return the values of this Option as a String array or null if there are no values.
718+
* @return the values of this Option as a String array or an empty array if there are no values.
719719
*/
720720
public String[] getValues() {
721721
return hasNoValues() ? null : values.toArray(EMPTY_STRING_ARRAY);
@@ -731,9 +731,9 @@ public char getValueSeparator() {
731731
}
732732

733733
/**
734-
* Gets the values of this Option as a List or null if there are no values.
734+
* Gets the values of this Option as a List. Will return an empty list if there are no values.
735735
*
736-
* @return the values of this Option as a List or null if there are no values.
736+
* @return the values of this Option as a List or an empty List if there are no values.
737737
*/
738738
public List<String> getValuesList() {
739739
return values;

0 commit comments

Comments
 (0)