From 7f43570bfcc2f37af721ec2cb73afc9bbb7a0829 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Thu, 2 Feb 2023 06:47:12 -0800 Subject: [PATCH] Fix program crash when try to show command helper info (#24809) --- .../java/src/com/matter/controller/Main.java | 3 --- .../controller/commands/common/CommandManager.java | 10 ++++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/java-matter-controller/java/src/com/matter/controller/Main.java b/examples/java-matter-controller/java/src/com/matter/controller/Main.java index ffeefb43699a2e..0e24c6dc1c212d 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/Main.java +++ b/examples/java-matter-controller/java/src/com/matter/controller/Main.java @@ -112,9 +112,6 @@ public static void main(String[] args) { try { commandManager.run(args); - } catch (IllegalArgumentException e) { - logger.log(Level.INFO, "Arguments init failed with exception: " + e.getMessage()); - System.exit(1); } catch (Exception e) { logger.log(Level.INFO, "Run command failed with exception: " + e.getMessage()); System.exit(1); diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.java index 2e1b373873478a..47e184ec3ae4d7 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.java +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CommandManager.java @@ -96,8 +96,14 @@ public final void run(String[] args) throws Exception { // need skip over binary and command name and only get arguments String[] temp = Arrays.copyOfRange(args, 2, args.length); - command.initArguments(temp.length, temp); - showCommand(args[0], command); + try { + command.initArguments(temp.length, temp); + } catch (IllegalArgumentException e) { + logger.log(Level.INFO, "Arguments init failed with exception: " + e.getMessage()); + showCommand(args[0], command); + System.exit(1); + } + command.run(); }