fix NPE in session.execute("a = $b x") when $b evaluates to null;
fix session.get(".commands") to be list of command names, rather than map.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@943079 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Activator.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Activator.java
index 7518b8f..75cee01 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Activator.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Activator.java
@@ -53,6 +53,11 @@
private OSGiCommands commands;
private OSGiConverters converters;
private ServiceRegistration convertersRegistration;
+
+ protected CommandProcessorImpl newProcessor(ThreadIO tio)
+ {
+ return new CommandProcessorImpl(threadio);
+ }
public void start(final BundleContext context) throws Exception
{
@@ -61,7 +66,7 @@
threadioRegistration = context.registerService(ThreadIO.class.getName(),
threadio, null);
- processor = new CommandProcessorImpl(threadio);
+ processor = newProcessor(threadio);
processorRegistration = context.registerService(CommandProcessor.class.getName(),
processor, null);
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java
index 5fcae56..8e84e79 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java
@@ -45,6 +45,7 @@
private final Object script;
private Token errTok;
+ private Token errTok2;
private List<Object> parms = null;
private List<Object> parmv = null;
@@ -289,6 +290,11 @@
List<Object> values = new ArrayList<Object>();
errTok = statement.get(0);
+
+ if ((statement.size() > 3) && Type.ASSIGN.equals(statement.get(1).type))
+ {
+ errTok2 = statement.get(2);
+ }
for (Token t : statement)
{
@@ -352,7 +358,12 @@
}
else
{
- value = execute(values.get(1), values.subList(2, values.size()));
+ cmd = values.get(1);
+ if (null == cmd)
+ {
+ throw new RuntimeException("Command name evaluates to null: " + errTok2);
+ }
+ value = execute(cmd, values.subList(2, values.size()));
}
return assignment(scmd, value);
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java
index c217e73..a37546f 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java
@@ -62,9 +62,9 @@
converters.remove(c);
}
- public Map<String, Object> getCommands()
+ public Set<String> getCommands()
{
- return commands;
+ return commands.keySet();
}
public Function getCommand(String name)
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProxy.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProxy.java
index a70a1e2..aca890c 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProxy.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProxy.java
@@ -44,11 +44,16 @@
this.function = function;
this.target = target;
}
+
+ public Object getTarget()
+ {
+ return (context != null ? context.getService(reference) : target);
+ }
public Object execute(CommandSession session, List<Object> arguments)
throws Exception
{
- Object tgt = (context != null ? context.getService(reference) : target);
+ Object tgt = getTarget();
try
{