Fix the issue Felix-697
Check the unicity of method flag field.
Add the tests case provided by Loris in the test suite.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@693520 13f79535-47bb-0310-9956-ffa450edef68
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 8475aef..9554ea5 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
@@ -106,6 +106,12 @@
* This set contains method id.
*/
private List m_methods = new ArrayList(); // Contains method id.
+
+ /**
+ * List of fields injected as method flag in the class.
+ * This set contains field name generate from method id.
+ */
+ private List m_methodFlags = new ArrayList();
/**
* Constructor.
@@ -155,8 +161,6 @@
if (name.equals("<clinit>") || name.equals("class$")) { return super.visitMethod(access, name, desc, signature, exceptions); }
// The constructor is manipulated separately
if (name.equals("<init>")) {
- //TODO : do not manipulate non matching constructor.
-
// 1) change the constructor descriptor (add a component manager arg as first argument)
String newDesc = desc.substring(1);
@@ -185,8 +189,14 @@
if ((access & ACC_STATIC) == ACC_STATIC) { return super.visitMethod(access, name, desc, signature, exceptions); }
generateMethodHeader(access, name, desc, signature, exceptions);
- FieldVisitor flagField = cv.visitField(Opcodes.ACC_PRIVATE, generateMethodFlag(name, desc), "Z", null, null);
- flagField.visitEnd();
+
+
+ String id = generateMethodFlag(name, desc);
+ if (! m_methodFlags.contains(id)) {
+ FieldVisitor flagField = cv.visitField(Opcodes.ACC_PRIVATE, id, "Z", null, null);
+ flagField.visitEnd();
+ m_methodFlags.add(id);
+ }
MethodVisitor mv = super.visitMethod(ACC_PRIVATE, PREFIX + name, desc, signature, exceptions);
return new MethodCodeAdapter(mv, m_owner, ACC_PRIVATE, PREFIX + name, desc, m_fields);
@@ -382,7 +392,7 @@
* Generate a method flag name.
* @param name : method name.
* @param desc : method descriptor.
- * @return the method flag name.
+ * @return the method flag name
*/
private String generateMethodFlag(String name, String desc) {
return METHOD_FLAG_PREFIX + generateMethodId(name, desc);
@@ -473,6 +483,7 @@
createGetComponentInstanceMethod();
m_methods.clear();
+ m_methodFlags.clear();
cv.visitEnd();
}
diff --git a/ipojo/tests/manipulator/manipulation/pom.xml b/ipojo/tests/manipulator/manipulation/pom.xml
index ff3dc39..84e16c1 100644
--- a/ipojo/tests/manipulator/manipulation/pom.xml
+++ b/ipojo/tests/manipulator/manipulation/pom.xml
@@ -93,8 +93,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>1.4</source>
- <target>1.4</target>
+ <source>1.5</source>
+ <target>1.5</target>
</configuration>
</plugin>
</plugins>
diff --git a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PlopImpl.java b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PlopImpl.java
new file mode 100644
index 0000000..005dc0c
--- /dev/null
+++ b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PlopImpl.java
@@ -0,0 +1,11 @@
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import org.apache.felix.ipojo.test.scenarios.manipulation.service.Plop;
+//TODO this test requires source compatibility 1.5
+public class PlopImpl implements Plop {
+
+ public String getPlop() {
+ return "plop";
+ }
+
+}
diff --git a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/DuplicateMethod.java b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/DuplicateMethod.java
new file mode 100644
index 0000000..439135c
--- /dev/null
+++ b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/DuplicateMethod.java
@@ -0,0 +1,22 @@
+package org.apache.felix.ipojo.test.scenarios.manipulation;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.manipulation.service.Plop;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DuplicateMethod extends OSGiTestCase {
+
+
+ public void testDuplicateMethod() {
+ ComponentInstance instance = Utils.getComponentInstanceByName(context, "plopimpl", "plop");
+ ServiceReference ref = Utils.getServiceReferenceByName(context, Plop.class.getName(), "plop");
+ assertNotNull("Check plop", ref);
+ Plop plop = (Plop) context.getService(ref);
+ Object o = plop.getPlop();
+ assertEquals("Check result", "plop", o);
+ context.ungetService(ref);
+ instance.dispose();
+ }
+}
diff --git a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationTestSuite.java b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationTestSuite.java
index 5258e1b..cb5f92d 100644
--- a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationTestSuite.java
+++ b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationTestSuite.java
@@ -35,6 +35,7 @@
ots.addTestSuite(ExceptionTest.class);
ots.addTestSuite(POJOCreation.class);
ots.addTestSuite(NestedClassesTests.class);
+ ots.addTestSuite(DuplicateMethod.class);
return ots;
}
diff --git a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/service/Plop.java b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/service/Plop.java
new file mode 100644
index 0000000..1bb177c
--- /dev/null
+++ b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/service/Plop.java
@@ -0,0 +1,7 @@
+package org.apache.felix.ipojo.test.scenarios.manipulation.service;
+
+public interface Plop {
+
+ Object getPlop();
+
+}
diff --git a/ipojo/tests/manipulator/manipulation/src/main/resources/metadata.xml b/ipojo/tests/manipulator/manipulation/src/main/resources/metadata.xml
index 81053f8..0a467ea 100644
--- a/ipojo/tests/manipulator/manipulation/src/main/resources/metadata.xml
+++ b/ipojo/tests/manipulator/manipulation/src/main/resources/metadata.xml
@@ -115,4 +115,9 @@
<property field="publicInt"/>
</provides>
</component>
+
+ <!-- Check duplicate method issue -->
+ <component classname="org.apache.felix.ipojo.test.scenarios.component.PlopImpl" name="plopimpl">
+ <provides></provides>
+ </component>
</ipojo>