You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2011/12/13 17:45:14 UTC

svn commit: r1213776 - /karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/ArgumentCompleter.java

Author: gnodet
Date: Tue Dec 13 16:45:13 2011
New Revision: 1213776

URL: http://svn.apache.org/viewvc?rev=1213776&view=rev
Log:
Make sure no exception is thrown when using
old commands that do not implement the new method on the CompletableFunction interface

Modified:
    karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/ArgumentCompleter.java

Modified: karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/ArgumentCompleter.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/ArgumentCompleter.java?rev=1213776&r1=1213775&r2=1213776&view=diff
==============================================================================
--- karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/ArgumentCompleter.java (original)
+++ karaf/branches/karaf-2.2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/ArgumentCompleter.java Tue Dec 13 16:45:13 2011
@@ -99,9 +99,17 @@ public class ArgumentCompleter implement
         optionsCompleter = new StringsCompleter(options.keySet());
         // Build arguments completers
         argsCompleters = new ArrayList<Completer>();
+        optionalCompleters = new HashMap<String, Completer>();
 
         if (function instanceof CompletableFunction) {
-            optionalCompleters = ((CompletableFunction) function).getOptionalCompleters();
+            try {
+                Map completers = ((CompletableFunction) function).getOptionalCompleters();
+                if (completers != null) {
+                    optionalCompleters.putAll(completers);
+                }
+            } catch (AbstractMethodError err) {
+                // Allow old commands to not break the completers
+            }
             List<Completer> fcl = ((CompletableFunction) function).getCompleters();
             if (fcl != null) {
                 for (Completer c : fcl) {
@@ -111,7 +119,6 @@ public class ArgumentCompleter implement
                 argsCompleters.add(NullCompleter.INSTANCE);
             }
         } else {
-            optionalCompleters = new HashMap<String, Completer>();
             final Map<Integer, Method> methods = new HashMap<Integer, Method>();
             for (Class type = function.getActionClass(); type != null; type = type.getSuperclass()) {
                 for (Method method : type.getDeclaredMethods()) {
@@ -267,7 +274,7 @@ public class ArgumentCompleter implement
                     if (option != null) {
                         Completer optionValueCompleter = null;
                         String name = option.name();
-                        if (optionalCompleters != null && name != null) {
+                        if (name != null) {
                             optionValueCompleter = optionalCompleters.get(name);
                             if (optionValueCompleter == null) {
                                 String[] aliases = option.aliases();