Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Exception thrown in case of command line validation errors.
*/
public class CliException extends Exception
public class CliException extends RuntimeException
{
private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ else if (argument.startsWith(SINGLE_CHAR_ARG_PREFIX))
}

private void handleChainedSingleCharacterArguments(final ListIterator<String> iterator,
final String argument) throws CliException
final String argument)
{
final String characters = SINGLE_CHAR_ARG_PREFIX_PATTERN.matcher(argument).replaceFirst("")
.toLowerCase(Locale.ENGLISH);
Expand Down Expand Up @@ -131,7 +131,6 @@ private void handleChainedSingleCharacterArguments(final ListIterator<String> it
}

private void handleNamedArgument(final ListIterator<String> iterator, final String argument)
throws CliException
{
final String argumentName = argument.replace("-", "").toLowerCase(Locale.ENGLISH);
if (this.setters.containsKey(argumentName))
Expand All @@ -149,13 +148,13 @@ private static void handleUnnamedArgument(final List<String> unnamedArguments, f
unnamedArguments.add(argument);
}

private static void reportUnexpectedNamedArgument(final String argument) throws CliException
private static void reportUnexpectedNamedArgument(final String argument)
{
throw new CliException("Unexpected parameter '" + argument + "' is not allowed");
}

private void handleExpectedNamedArgument(final ListIterator<String> iterator,
final String argumentName) throws CliException
final String argumentName)
{
final Method setter = this.setters.get(argumentName);
if (setter.getParameterTypes().length != 1)
Expand Down Expand Up @@ -190,7 +189,7 @@ private void handleExpectedNamedArgument(final ListIterator<String> iterator,
}
}

private static <T> T convertArgument(final String stringValue, final Class<T> type) throws CliException
private static <T> T convertArgument(final String stringValue, final Class<T> type)
{
if (type.equals(String.class))
{
Expand All @@ -200,12 +199,11 @@ private static <T> T convertArgument(final String stringValue, final Class<T> ty
{
return convertEnum(stringValue, type);
}
throw new CliException(
"Type '" + type + "' not supported for converting argument '" + stringValue + "'");
throw new CliException("Type '" + type + "' not supported for converting argument '" + stringValue + "'");
}

@SuppressWarnings("unchecked")
private static <T> T convertEnum(final String stringValue, final Class<T> type) throws CliException
private static <T> T convertEnum(final String stringValue, final Class<T> type)
{
@SuppressWarnings("rawtypes")
final Class enumType = type;
Expand All @@ -223,13 +221,13 @@ private static <T> T convertEnum(final String stringValue, final Class<T> type)
}
}

private static void reportUnsupportedSetterArgumentCount(final Method setter) throws CliException
private static void reportUnsupportedSetterArgumentCount(final Method setter)
{
throw new CliException("Unsupported argument count for setter '" + setter
+ "'. Only one argument is allowed.");
}

private static void reportMissingParameterValue(final String argumentName) throws CliException
private static void reportMissingParameterValue(final String argumentName)
{
throw new CliException("No value for argument '" + argumentName + "'");
}
Expand All @@ -239,7 +237,7 @@ private static boolean isParameterName(final String text)
return text.startsWith(SINGLE_CHAR_ARG_PREFIX);
}

private void assignUnnamedArgument(final List<String> unnamedArguments) throws CliException
private void assignUnnamedArgument(final List<String> unnamedArguments)
{
final Method unnamedArgumentSetter = this.setters.get(UNNAMED_ARGUMENTS_SUFFIX);
if (unnamedArgumentSetter != null)
Expand All @@ -252,16 +250,15 @@ private void assignUnnamedArgument(final List<String> unnamedArguments) throws C
}
}

private void assignValue(final Method setter, final Object value) throws CliException
private void assignValue(final Method setter, final Object value)
{
try
{
setter.invoke(this.argumentsReceiver, value);
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
{
throw new CliException(
"Error calling setter " + setter + " with argument '" + value + "'", e);
throw new CliException("Error calling setter " + setter + " with argument '" + value + "'", e);
}
}
}
6 changes: 5 additions & 1 deletion doc/changes/changes_4.6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ We moved some GitHub action permissions from workflow-level to job-level.

## Security

* #
* #

## Refactoring

* #543: Made `CliException` a `RuntimeException`
Loading