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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.2.2
    • 2.2.6, 3.0.0
    • karaf
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: