diff --git a/core/src/main/java/org/itsallcode/openfasttrace/core/cli/CliException.java b/core/src/main/java/org/itsallcode/openfasttrace/core/cli/CliException.java index 8ed80ce97..647ac2281 100644 --- a/core/src/main/java/org/itsallcode/openfasttrace/core/cli/CliException.java +++ b/core/src/main/java/org/itsallcode/openfasttrace/core/cli/CliException.java @@ -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; diff --git a/core/src/main/java/org/itsallcode/openfasttrace/core/cli/CommandLineInterpreter.java b/core/src/main/java/org/itsallcode/openfasttrace/core/cli/CommandLineInterpreter.java index 446cd481a..3f60a2da8 100644 --- a/core/src/main/java/org/itsallcode/openfasttrace/core/cli/CommandLineInterpreter.java +++ b/core/src/main/java/org/itsallcode/openfasttrace/core/cli/CommandLineInterpreter.java @@ -103,7 +103,7 @@ else if (argument.startsWith(SINGLE_CHAR_ARG_PREFIX)) } private void handleChainedSingleCharacterArguments(final ListIterator iterator, - final String argument) throws CliException + final String argument) { final String characters = SINGLE_CHAR_ARG_PREFIX_PATTERN.matcher(argument).replaceFirst("") .toLowerCase(Locale.ENGLISH); @@ -131,7 +131,6 @@ private void handleChainedSingleCharacterArguments(final ListIterator it } private void handleNamedArgument(final ListIterator iterator, final String argument) - throws CliException { final String argumentName = argument.replace("-", "").toLowerCase(Locale.ENGLISH); if (this.setters.containsKey(argumentName)) @@ -149,13 +148,13 @@ private static void handleUnnamedArgument(final List 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 iterator, - final String argumentName) throws CliException + final String argumentName) { final Method setter = this.setters.get(argumentName); if (setter.getParameterTypes().length != 1) @@ -190,7 +189,7 @@ private void handleExpectedNamedArgument(final ListIterator iterator, } } - private static T convertArgument(final String stringValue, final Class type) throws CliException + private static T convertArgument(final String stringValue, final Class type) { if (type.equals(String.class)) { @@ -200,12 +199,11 @@ private static T convertArgument(final String stringValue, final Class 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 convertEnum(final String stringValue, final Class type) throws CliException + private static T convertEnum(final String stringValue, final Class type) { @SuppressWarnings("rawtypes") final Class enumType = type; @@ -223,13 +221,13 @@ private static T convertEnum(final String stringValue, final Class 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 + "'"); } @@ -239,7 +237,7 @@ private static boolean isParameterName(final String text) return text.startsWith(SINGLE_CHAR_ARG_PREFIX); } - private void assignUnnamedArgument(final List unnamedArguments) throws CliException + private void assignUnnamedArgument(final List unnamedArguments) { final Method unnamedArgumentSetter = this.setters.get(UNNAMED_ARGUMENTS_SUFFIX); if (unnamedArgumentSetter != null) @@ -252,7 +250,7 @@ private void assignUnnamedArgument(final List unnamedArguments) throws C } } - private void assignValue(final Method setter, final Object value) throws CliException + private void assignValue(final Method setter, final Object value) { try { @@ -260,8 +258,7 @@ private void assignValue(final Method setter, final Object value) throws CliExce } 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); } } } diff --git a/doc/changes/changes_4.6.0.md b/doc/changes/changes_4.6.0.md index 4368a932a..b5e30ec45 100644 --- a/doc/changes/changes_4.6.0.md +++ b/doc/changes/changes_4.6.0.md @@ -8,4 +8,8 @@ We moved some GitHub action permissions from workflow-level to job-level. ## Security -* # \ No newline at end of file +* # + +## Refactoring + +* #543: Made `CliException` a `RuntimeException` \ No newline at end of file