FELIX-4159 : Error when declaring a multivalued property using the OSGi 4.3 Annotation DS standard

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1499468 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/ds-annotations/changelog.txt b/scrplugin/ds-annotations/changelog.txt
index 1dc6f69..3b4a1ee 100644
--- a/scrplugin/ds-annotations/changelog.txt
+++ b/scrplugin/ds-annotations/changelog.txt
@@ -1,3 +1,9 @@
+Changes from 1.2.4 to 1.2.2
+---------------------------
+** Bug
+    * [FELIX-4159] - Error when declaring a multivalued property using the OSGi 4.3 Annotation DS standard
+
+
 Changes from 1.2.2 to 1.2.0
 ----------------------------
 ** Bug
diff --git a/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java b/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
index b8778ba..f044df6 100644
--- a/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
+++ b/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
@@ -179,12 +179,41 @@
                     final String type = (typeSep == -1 ? PropertyType.String.name() : prefix.substring(typeSep + 1));
 
                     final PropertyType propType = PropertyType.valueOf(type);
-                    final PropertyDescription pd = new PropertyDescription(cad);
-                    describedClass.add(pd);
-                    pd.setName(key);
-                    pd.setValue(value);
-                    pd.setType(propType);
-                    pd.setUnbounded(PropertyUnbounded.DEFAULT);
+                    // FELIX-4159 : check if this is a multi value prop
+                    final List<PropertyDescription> existingProps = describedClass.getDescriptions(PropertyDescription.class);
+                    PropertyDescription found = null;
+                    for(final PropertyDescription current : existingProps) {
+                        if ( current.getName().equals(key) ) {
+                            found = current;
+                            break;
+                        }
+                    }
+                    if ( found == null ) {
+                        final PropertyDescription pd = new PropertyDescription(cad);
+                        describedClass.add(pd);
+                        pd.setName(key);
+                        pd.setValue(value);
+                        pd.setType(propType);
+                        pd.setUnbounded(PropertyUnbounded.DEFAULT);
+                    } else {
+                        if ( propType != found.getType() ) {
+                            throw new SCRDescriptorException("Multi value property '" + key + "' has different types: "
+                                    + found.getType() + " & " + propType,
+                                    describedClass.getSource());
+                        }
+                        if ( found.getValue() != null ) {
+                            final String[] values = new String[2];
+                            values[0] = found.getValue();
+                            values[1] = value;
+                            found.setMultiValue(values);
+                        } else {
+                            final String[] oldValues = found.getMultiValue();
+                            final String[] newValues = new String[oldValues.length + 1];
+                            System.arraycopy(oldValues, 0, newValues, 0, oldValues.length);
+                            newValues[oldValues.length] = value;
+                            found.setMultiValue(newValues);
+                        }
+                    }
                 }
             }
         }