Fix FELIX-2430
The super() invocation was not correctly computed. It wrongly guess that it is the first <init> call, but not necessary. Now, the super call detection check for the super class name.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@955965 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
index dc046e2..7fec41e 100644
--- a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
+++ b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
@@ -48,6 +48,11 @@
     private boolean m_superDetected;

     

     /**

+     * The super class. 

+     */

+    private String m_superClass;

+    

+    /**

      * Set of contained fields.

      */

     private Set m_fields;

@@ -63,11 +68,12 @@
      * @param desc the constructor descriptor

      * @param name the name

      */

-    public ConstructorCodeAdapter(final MethodVisitor mv, final String owner, Set fields, int access, String name, String desc) {

+    public ConstructorCodeAdapter(final MethodVisitor mv, final String owner, Set fields, int access, String name, String desc, String superClass) {

         super(mv, access, name, desc);

         m_owner = owner;

         m_superDetected = false;

         m_fields = fields;

+        m_superClass = superClass;

     }

     

     /**

@@ -137,7 +143,8 @@
     public void visitMethodInsn(int opcode, String owner, String name, String desc) {

         

         // A method call is detected, check if it is the super call :

-        if (!m_superDetected && name.equals("<init>")) {

+        // the first init is not necessary the super call, so check that it is really the super class.

+        if (!m_superDetected && name.equals("<init>")  && owner.equals(m_superClass)) {

             m_superDetected = true; 

             // The first invocation is the super call

             // 1) Visit the super constructor :

diff --git a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
index a80105d..5b851e9 100644
--- a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
+++ b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
@@ -203,7 +203,7 @@
 

             // Insert the new constructor

             MethodVisitor mv = super.visitMethod(ACC_PRIVATE, "<init>", newDesc, signature, exceptions);

-            return new ConstructorCodeAdapter(mv, m_owner, m_fields, ACC_PRIVATE, name, newDesc);

+            return new ConstructorCodeAdapter(mv, m_owner, m_fields, ACC_PRIVATE, name, newDesc, m_superclass);

         }

         

         if ((access & ACC_SYNTHETIC) == ACC_SYNTHETIC && name.startsWith("access$")) { 

diff --git a/ipojo/tests/core/service-providing/pom.xml b/ipojo/tests/core/service-providing/pom.xml
index 2ded653..9a27648 100644
--- a/ipojo/tests/core/service-providing/pom.xml
+++ b/ipojo/tests/core/service-providing/pom.xml
@@ -93,7 +93,6 @@
             </goals>

             <configuration>

               <ignoreAnnotations>true</ignoreAnnotations>

-              <ignoreEmbeddedSchemas>true</ignoreEmbeddedSchemas>

             </configuration>

           </execution>

         </executions>

diff --git a/ipojo/tests/manipulator/creation/pom.xml b/ipojo/tests/manipulator/creation/pom.xml
index 027daaf..b67984f 100644
--- a/ipojo/tests/manipulator/creation/pom.xml
+++ b/ipojo/tests/manipulator/creation/pom.xml
@@ -85,6 +85,7 @@
 			<plugin>

 				<groupId>org.apache.felix</groupId>

 				<artifactId>maven-ipojo-plugin</artifactId>

+                <version>1.7.0-SNAPSHOT</version>

 				<executions>

 					<execution>

 						<goals>

diff --git a/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CallSuperConstructorWithNew.java b/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CallSuperConstructorWithNew.java
new file mode 100644
index 0000000..e147d09
--- /dev/null
+++ b/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CallSuperConstructorWithNew.java
@@ -0,0 +1,10 @@
+package org.apache.felix.ipojo.test.scenarios.component;
+
+public class CallSuperConstructorWithNew extends ParentClass {
+    
+    public CallSuperConstructorWithNew() {
+        super(new StringBuffer("test"));
+        System.out.println("plop");
+    } 
+
+}
diff --git a/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ParentClass.java b/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ParentClass.java
index 052ca83..5b6b99f 100644
--- a/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ParentClass.java
+++ b/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ParentClass.java
@@ -6,6 +6,10 @@
 
     public ParentClass(final String n) {
         name = n;
+    }
+    
+    public ParentClass(final StringBuffer n) {
+        name = n.toString();
     } 
 
 }
diff --git a/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/POJOCreation.java b/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/POJOCreation.java
index 605e339..b9fa25f 100644
--- a/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/POJOCreation.java
+++ b/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/POJOCreation.java
@@ -233,6 +233,14 @@
         }

     }

     

+    public void testSuperCallWithNew() {

+        try {

+            helper.createComponentInstance("org.apache.felix.ipojo.test.scenarios.component.CallSuperConstructorWithNew");

+        } catch (Throwable e) {

+            fail(e.getMessage());

+        }

+    }

+    

     public void testSuperCallWithBC() {

         try {

             helper.createComponentInstance("org.apache.felix.ipojo.test.scenarios.component.CallSuperConstructorWithBC");

diff --git a/ipojo/tests/manipulator/creation/src/main/resources/metadata.xml b/ipojo/tests/manipulator/creation/src/main/resources/metadata.xml
index 947c46f..3fdacde 100644
--- a/ipojo/tests/manipulator/creation/src/main/resources/metadata.xml
+++ b/ipojo/tests/manipulator/creation/src/main/resources/metadata.xml
@@ -57,6 +57,7 @@
 	

 	<!-- Try calling super constructors -->

 	 <component classname="org.apache.felix.ipojo.test.scenarios.component.CallSuperConstructor" immediate="true"/>

+     <component classname="org.apache.felix.ipojo.test.scenarios.component.CallSuperConstructorWithNew" immediate="true"/>

 	 <component classname="org.apache.felix.ipojo.test.scenarios.component.CallSuperConstructorWithBC" immediate="true"/>

 	 

 	 <!--  Several constructors -->