Fix FELIX-3501. 

Store the state before its modification.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1338788 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
index 511ea30..4905c81 100644
--- a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
+++ b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
@@ -522,6 +522,8 @@
             m_sr = null;

         }

         stopping(); // Method called when holding the lock.

+        int oldState = m_state; // Create a variable to store the old state. Using a variable is important as

+                                // after the next instruction, the getState() method must return INVALID.

         m_state = INVALID; // Set here to avoid to create instances during the stops.

 

         Set col = m_componentInstances.keySet();

@@ -533,7 +535,7 @@
             index++;

         }

 

-        if (m_state == VALID) {

+        if (oldState == VALID) { // Check if the old state was valid.

             for (int i = 0; i < m_listeners.size(); i++) {

                 ((FactoryStateListener) m_listeners.get(i)).stateChanged(this, INVALID);

             }