Karaf
  1. Karaf
  2. KARAF-913

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor 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

        Activity

        Hide
        Jean-Baptiste Onofré added a comment -

        This part is not related to Karaf, it's in Felix Gogo. Anyway, I'm going to submit a patch to Gogo.

        Show
        Jean-Baptiste Onofré added a comment - This part is not related to Karaf, it's in Felix Gogo. Anyway, I'm going to submit a patch to Gogo.
        Hide
        Andreas Pieber added a comment -

        is there a link to the gogo issue?

        Show
        Andreas Pieber added a comment - is there a link to the gogo issue?
        Hide
        Jean-Baptiste Onofré added a comment -

        In fact, a simple workaround could be done in the DefaultActionPreparator in Karaf (not related to Gogo).

        I do it.

        Show
        Jean-Baptiste Onofré added a comment - In fact, a simple workaround could be done in the DefaultActionPreparator in Karaf (not related to Gogo). I do it.

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development