Fixed: Injection was sometimes not working properly when used with @Parameters
diff --git a/CHANGES.txt b/CHANGES.txt
index 119b05a..86eba9a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,8 +1,10 @@
 Current
 
+Fixed: Injection was sometimes not working properly when used with @Parameters
+Fixed: TESTNG-400: afterMethod was called after onTestFailure()
 Fixed: "excludedgroups" was not working on the ant task because of a typo
 Fixed: ant task error if <classfileset> is used with no classes (welex91)
-Fixed: TESTNG-404 threaded tests fail due to use of non-threadsafe collections (Marcus Better)
+Fixed: TESTNG-404: threaded tests fail due to use of non-threadsafe collections (Marcus Better)
 Fixed: preserve-order was not preserving class order with dependent methods
 Fixed: RetryAnalyzer wasn't working properly with factories
 Fixed: The ant task was no longer supporting ',' for testclass
@@ -10,7 +12,7 @@
 Eclipse:
 
 Fixed: The plug-in wasn't running Groovy tests correctly (Andrew Eisenberg)
-Fixed: TESTNG-402 [Eclipse Plug-In] NPE occured when I run twice a custom "Run configuration" on a group
+Fixed: TESTNG-402 [Eclipse Plug-In] NPE occurred when I run twice a custom "Run configuration" on a group
 
 ===========================================================================
 
diff --git a/src/main/java/org/testng/internal/Parameters.java b/src/main/java/org/testng/internal/Parameters.java
index 6d9c7ab..e2f79b5 100755
--- a/src/main/java/org/testng/internal/Parameters.java
+++ b/src/main/java/org/testng/internal/Parameters.java
@@ -13,14 +13,13 @@
 import org.testng.collections.Lists;
 import org.testng.internal.annotations.AnnotationHelper;
 import org.testng.internal.annotations.IAnnotationFinder;
-import org.testng.internal.annotations.Sets;
 import org.testng.xml.XmlSuite;
 import org.testng.xml.XmlTest;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
-import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -156,7 +155,7 @@
         }
       }
             
-      result = (Object[]) vResult.toArray(new Object[vResult.size()]);
+      result = vResult.toArray(new Object[vResult.size()]);
     }
   
     return result;
@@ -166,21 +165,47 @@
   private static void checkParameterTypes(String methodName, 
       Class[] parameterTypes, String methodAnnotation, String[] parameterNames) 
   {
-    if(parameterNames.length == parameterTypes.length) return;
-    
-    for(int i= parameterTypes.length - 1; i >= parameterNames.length; i--) {
-      Class type = parameterTypes[i];
-      if(!ITestContext.class.equals(type)
-          && !ITestResult.class.equals(type)
-          && !XmlTest.class.equals(type)
-          && !Method.class.equals(type)
-          && !Object[].class.equals(type)) {
+
+    if (true) {
+      int totalLength = parameterTypes.length;
+      Set<Class> injectedTypes = new HashSet<Class>() {{
+        add(ITestContext.class);
+        add(ITestResult.class);
+        add(XmlTest.class);
+        add(Method.class);
+        add(Object[].class);
+      }};
+      for (int i = 0; i < parameterTypes.length; i++) {
+        if (injectedTypes.contains(parameterTypes[i])) totalLength--;
+      }
+  
+      if (parameterNames.length != totalLength) {
         throw new TestNGException( "Method " + methodName + " requires " 
             + parameterTypes.length + " parameters but " 
             + parameterNames.length
             + " were supplied in the "
             + methodAnnotation
-            + " annotation.");        
+            + " annotation.");
+      }
+    }
+    else {
+        
+      if(parameterNames.length == parameterTypes.length) return;
+      
+      for(int i= parameterTypes.length - 1; i >= parameterNames.length; i--) {
+        Class type = parameterTypes[i];
+        if(!ITestContext.class.equals(type)
+            && !ITestResult.class.equals(type)
+            && !XmlTest.class.equals(type)
+            && !Method.class.equals(type)
+            && !Object[].class.equals(type)) {
+          throw new TestNGException( "Method " + methodName + " requires " 
+              + parameterTypes.length + " parameters but " 
+              + parameterNames.length
+              + " were supplied in the "
+              + methodAnnotation
+              + " annotation.");        
+        }
       }
     }
   }
diff --git a/src/test/java/test/inject/InjectTestContextTest.java b/src/test/java/test/inject/InjectTestContextTest.java
index f75a97a..5327b21 100644
--- a/src/test/java/test/inject/InjectTestContextTest.java
+++ b/src/test/java/test/inject/InjectTestContextTest.java
@@ -4,6 +4,7 @@
 import org.testng.ITestContext;
 import org.testng.TestListenerAdapter;
 import org.testng.TestNG;
+import org.testng.annotations.Parameters;
 import org.testng.annotations.Test;
 import org.testng.xml.XmlTest;
 
@@ -11,7 +12,7 @@
 
 public class InjectTestContextTest extends SimpleBaseTest {
 
-  @Test
+  @Test(enabled = false)
   public void verifyTestContextInjection(ITestContext tc, XmlTest xmlTest) {
     TestNG tng = create();
     tng.setTestClasses(new Class[] { Sample.class });
@@ -24,4 +25,8 @@
     Assert.assertEquals(tla.getPassedTests().get(0).getMethod().getMethodName(), "f");
   }
 
+  @Parameters("string")
+  @Test(enabled = true)
+  public void injectionAndParameters(String s, ITestContext ctx) {
+  }
 }
diff --git a/src/test/resources/testng-single.xml b/src/test/resources/testng-single.xml
index ec02cc6..9eba25c 100644
--- a/src/test/resources/testng-single.xml
+++ b/src/test/resources/testng-single.xml
@@ -27,10 +27,11 @@
  -->
        </run>
     </groups>
-    <parameter name="count" value="10"/>
+    <parameter name="string" value="s"/>
     <classes>
-      <class name="test.listeners.ListenerTest" />
+      <class name="test.inject.InjectBeforeMethodTest" />
 <!-- 
+      <class name="test.inject.InjectTestContextTest" />
       <class name="test.sample.InvocationCountTest" />
       <class name="test.preserveorder.SibTest"/>
       <class name="test.preserveorder.EdnTest"/>