Repository: adobe-consulting-services/acs-aem-commons
Issue: Adding an async index throws Exception as it tries to remove the unique property which does not exist.

Try adding an index which is async (but not unique => by definition). It throws following Exception:

``` java
05.12.2014 09:43:02.147 *INFO* [CM Event Dispatcher (Fire ConfigurationEvent: pid=com.adobe.acs.commons.oak.impl.EnsurePropertyIndex.9fe8dd22-995c-4688-a7ec-7a8b43fd9538)] com.adobe.acs.commons.oak.impl.EnsurePropertyIndex creating index givenName
05.12.2014 09:43:02.159 *ERROR* [CM Event Dispatcher (Fire ConfigurationEvent: pid=com.adobe.acs.commons.oak.impl.EnsurePropertyIndex.9fe8dd22-995c-4688-a7ec-7a8b43fd9538)] com.adobe.acs.commons.oak.impl.EnsurePropertyIndex Unable to create index
javax.jcr.PathNotFoundException: unique not found on /oak:index/givenName
    at org.apache.jackrabbit.oak.jcr.session.NodeImpl$11.perform(NodeImpl.java:616)
    at org.apache.jackrabbit.oak.jcr.session.NodeImpl$11.perform(NodeImpl.java:611)
    at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:293)
    at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:113)
    at org.apache.jackrabbit.oak.jcr.session.NodeImpl.getProperty(NodeImpl.java:611)
    at com.adobe.acs.commons.oak.impl.EnsurePropertyIndex.createOrUpdateIndex(EnsurePropertyIndex.java:113)
    at com.adobe.acs.commons.oak.impl.EnsurePropertyIndex.activate(EnsurePropertyIndex.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.felix.scr.impl.helper.BaseMethod.invokeMethod(BaseMethod.java:231)
    at org.apache.felix.scr.impl.helper.BaseMethod.access$500(BaseMethod.java:39)
    at org.apache.felix.scr.impl.helper.BaseMethod$Resolved.invoke(BaseMethod.java:624)
    at org.apache.felix.scr.impl.helper.BaseMethod.invoke(BaseMethod.java:508)
    at org.apache.felix.scr.impl.helper.ActivateMethod.invoke(ActivateMethod.java:149)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:315)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:127)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:871)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:838)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:850)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:419)
    at org.apache.felix.scr.impl.config.ConfigurableComponentHolder.configurationUpdated(ConfigurableComponentHolder.java:334)
    at org.apache.felix.scr.impl.config.ConfigurationSupport.configurationEvent(ConfigurationSupport.java:290)
    at org.apache.felix.cm.impl.ConfigurationManager$FireConfigurationEvent.sendEvent(ConfigurationManager.java:2032)
    at org.apache.felix.cm.impl.ConfigurationManager$FireConfigurationEvent.run(ConfigurationManager.java:2002)
    at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:103)
    at java.lang.Thread.run(Thread.java:745)
```

Tested with AEM 6.0.1 - OAK 1.0.8 FP


Changed files:
bundle/src/main/java/com/adobe/acs/commons/oak/impl/EnsurePropertyIndex.java

diff --git a/bundle/src/main/java/com/adobe/acs/commons/oak/impl/EnsurePropertyIndex.java b/bundle/src/main/java/com/adobe/acs/commons/oak/impl/EnsurePropertyIndex.java
index ca604b18d..47d5d2ee2 100644
--- a/bundle/src/main/java/com/adobe/acs/commons/oak/impl/EnsurePropertyIndex.java
+++ b/bundle/src/main/java/com/adobe/acs/commons/oak/impl/EnsurePropertyIndex.java
@@ -110,7 +110,9 @@ public class EnsurePropertyIndex {
         if (def.unique) {
             indexNode.setProperty(PN_UNIQUE, true);
         } else if (indexNode.hasProperty(PN_ASYNC)) {
-            indexNode.getProperty(PN_UNIQUE).remove();
+        	if(indexNode.hasNode(PN_UNIQUE)){
+        		indexNode.getProperty(PN_UNIQUE).remove();	
+        	}
         }
         if (def.declaringNodeTypes != null && def.declaringNodeTypes.length > 0) {
             Value[] values = new Value[def.declaringNodeTypes.length];