Uploaded image for project: 'Karaf'
  1. Karaf
  2. KARAF-913

Omitted @Command on Gogo plugin is hard to debug because of NPE

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.2.2
    • Fix Version/s: 2.2.6, 3.0.0
    • Component/s: karaf-shell
    • Labels:
      None

      Description

      If you forget to put a @Command annotation on your OsgiCommandSupport subclass, and you try to execute that command with a syntax error (perhaps you forget an argument) then you'll get the following under-informative error in the shell:

      Error executing command: java.lang.NullPointerException

      The root cause (discovered by stepping in the debugger) is in DefaultActionPreparer.prepare() line 291 where this line of code:

      Command command = action.getClass().getAnnotation(Command.class);

      is not followed by a null check. In fact, there are several places in that method where the result of getAnnotation() is not checked. I propose one of the following two solutions:
      1) add null checks
      2) throw an informative exception in CommandProcessorImpl.addCommand() if the @Command is missing

        Attachments

          Activity

            People

            • Assignee:
              jbonofre Jean-Baptiste Onofré
              Reporter:
              cdolan Chris Dolan
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: