Author: dbaum
Date: Mon Jun 21 12:37:57 2010
New Revision: 956547
URL: http://svn.apache.org/viewvc?rev=956547&view=rev
Log:
fix NPE/coercion error when passing null first argument FELIX-2432
Modified:
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java
felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser2.java
Modified:
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java
URL:
http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java?rev=956547&r1=956546&r2=956547&view=diff
==============================================================================
---
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java
(original)
+++
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java
Mon Jun 21 12:37:57 2010
@@ -171,7 +171,7 @@ public final class Reflective
{
params.append(", ");
}
- params.append(arg.getClass().getSimpleName());
+ params.append(arg == null ? "null" :
arg.getClass().getSimpleName());
}
throw new IllegalArgumentException(String.format(
@@ -275,6 +275,13 @@ public final class Reflective
else
{
out[i] = coerce(session, target, types[i], in.get(0));
+
+ if (out[i] == null && types[i].isArray() && in.size() > 0)
+ {
+ // don't coerce null to array FELIX-2432
+ out[i] = NO_MATCH;
+ }
+
if (out[i] != NO_MATCH)
{
in.remove(0);
Modified:
felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser2.java
URL:
http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser2.java?rev=956547&r1=956546&r2=956547&view=diff
==============================================================================
---
felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser2.java
(original)
+++
felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser2.java
Mon Jun 21 12:37:57 2010
@@ -35,7 +35,7 @@ public class TestParser2 extends TestCas
assertEquals("file://wibble#tag", c.execute("echo file://wibble#tag"));
assertEquals("file:", c.execute("echo file: //wibble#tag"));
-
+
assertEquals("PWD/*.java", c.execute("echo PWD/*.java"));
try
{
@@ -46,31 +46,37 @@ public class TestParser2 extends TestCas
{
// expected
}
-
+
assertEquals("ok", c.execute("// can't quote\necho ok\n"));
-
+
// quote in comment in closure
assertEquals("ok", c.execute("x = { // can't quote\necho ok\n}; x"));
assertEquals("ok", c.execute("x = {\n// can't quote\necho ok\n}; x"));
assertEquals("ok", c.execute("x = {// can't quote\necho ok\n}; x"));
}
+ public void testCoercion() throws Exception
+ {
+ Context c = new Context();
+ c.addCommand("echo", this);
+
+ // FELIX-2432
+ assertEquals("null x", c.execute("echo $expandsToNull x"));
+ }
+
public CharSequence echo(Object args[])
{
if (args == null)
{
- return "";
+ return "null args!";
}
StringBuilder sb = new StringBuilder();
for (Object arg : args)
{
- if (arg != null)
- {
- if (sb.length() > 0)
- sb.append(' ');
- sb.append(arg);
- }
+ if (sb.length() > 0)
+ sb.append(' ');
+ sb.append(String.valueOf(arg));
}
return sb.toString();
}