Index: core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java
===================================================================
--- core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java	(revision 1405)
+++ core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java	Wed Apr 14 10:18:44 CEST 2010
@@ -145,6 +145,10 @@
                && (txLogActivated = transactionLog.activate());
          if (log.isDebugEnabled()) log.debug("Generating state.  Can provide? {0}", canProvideState);
          oo = marshaller.startObjectOutput(out, false);
+
+         // new, started flag set to true 
+         marshaller.objectToObjectStream(true, oo);
+
          marshaller.objectToObjectStream(canProvideState, oo);
 
          if (canProvideState) {
@@ -300,20 +304,24 @@
       ObjectInput oi = null;
       try {
          oi = marshaller.startObjectInput(in, false);
+         // new started flag implementation
+         boolean started = (Boolean) marshaller.objectFromObjectStream(oi);
+         if (started) {
-         boolean canProvideState = (Boolean) marshaller.objectFromObjectStream(oi);
-         if (canProvideState) {
-            assertDelimited(oi);
-            if (transientState) applyInMemoryState(oi);
-            assertDelimited(oi);
-            if (persistentState) applyPersistentState(oi);
-            assertDelimited(oi);
-            applyTransactionLog(oi);
-            if (log.isDebugEnabled()) log.debug("State applied, closing object stream");
-         } else {
-            String msg = "Provider cannot provide state!";
-            if (log.isDebugEnabled()) log.debug(msg);
-            throw new StateTransferException(msg);
-         }
+            boolean canProvideState = (Boolean) marshaller.objectFromObjectStream(oi);
+            if (canProvideState) {
+               assertDelimited(oi);
+               if (transientState) applyInMemoryState(oi);
+               assertDelimited(oi);
+               if (persistentState) applyPersistentState(oi);
+               assertDelimited(oi);
+               applyTransactionLog(oi);
+               if (log.isDebugEnabled()) log.debug("State applied, closing object stream");
+            } else {
+               String msg = "Provider cannot provide state!";
+               if (log.isDebugEnabled()) log.debug(msg);
+               throw new StateTransferException(msg);
+            }
+         }
       } catch (StateTransferException ste) {
          throw ste;
       } catch (Exception e) {
Index: core/src/main/java/org/infinispan/remoting/InboundInvocationHandlerImpl.java
===================================================================
--- core/src/main/java/org/infinispan/remoting/InboundInvocationHandlerImpl.java	(revision 937)
+++ core/src/main/java/org/infinispan/remoting/InboundInvocationHandlerImpl.java	Wed Apr 14 10:19:54 CEST 2010
@@ -8,6 +8,8 @@
 import org.infinispan.factories.annotations.Inject;
 import org.infinispan.factories.scopes.Scope;
 import org.infinispan.factories.scopes.Scopes;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.marshall.Marshaller;
 import org.infinispan.remoting.responses.ExceptionResponse;
 import org.infinispan.remoting.responses.RequestIgnoredResponse;
 import org.infinispan.remoting.responses.Response;
@@ -18,6 +20,7 @@
 import org.infinispan.util.logging.LogFactory;
 
 import java.io.InputStream;
+import java.io.ObjectOutput;
 import java.io.OutputStream;
 
 /**
@@ -30,10 +33,12 @@
 public class InboundInvocationHandlerImpl implements InboundInvocationHandler {
    GlobalComponentRegistry gcr;
    private static final Log log = LogFactory.getLog(InboundInvocationHandlerImpl.class);
+   private Marshaller marshaller;
 
    @Inject
-   public void inject(GlobalComponentRegistry gcr) {
+   public void inject(GlobalComponentRegistry gcr, Marshaller marshaller) {
       this.gcr = gcr;
+      this.marshaller = marshaller;
    }
 
    public Response handle(CacheRpcCommand cmd) throws Throwable {
@@ -74,16 +79,37 @@
    }
 
    public void generateState(String cacheName, OutputStream o) throws StateTransferException {
-      getStateTransferManager(cacheName).generateState(o);
+      // getStateTransferManager(cacheName).generateState(o);
+      StateTransferManager manager = getStateTransferManager(cacheName);
+      if (manager == null) {
+         ObjectOutput oo = null;
+         try {
+            oo = marshaller.startObjectOutput(o, false);
+            marshaller.objectToObjectStream(false, oo); // new started flag set to false
+         } catch (Exception e) {
+            throw new StateTransferException(e);
+         } finally {
+            marshaller.finishObjectOutput(oo);
-   }
+         }
+      } else {
+         manager.generateState(o);
+      }
+   }
 
    private StateTransferManager getStateTransferManager(String cacheName) throws StateTransferException {
       ComponentRegistry cr = gcr.getNamedComponentRegistry(cacheName);
-      if (cr == null) {
-         String msg = "Cache named " + cacheName + " does not exist on this cache manager!";
-         log.info(msg);
-         throw new StateTransferException(msg);
-      }
+      if (cr == null)
+         return null;
+//      if (cr == null) {
+//         CacheManager manager = gcr.getComponent(CacheManager.class);
+//         manager.getCache(cacheName);
+//         cr = gcr.getNamedComponentRegistry(cacheName);
+//      }
+//      if (cr == null) {
+//         String msg = "Cache named " + cacheName + " does not exist on this cache manager!";
+//         log.info(msg);
+//         throw new StateTransferException(msg);
+//      }
 
       return cr.getComponent(StateTransferManager.class);
    }
Index: core/src/test/java/org/infinispan/statetransfer/StateTransferFunctionalTest.java
===================================================================
--- core/src/test/java/org/infinispan/statetransfer/StateTransferFunctionalTest.java	(revision 1239)
+++ core/src/test/java/org/infinispan/statetransfer/StateTransferFunctionalTest.java	Tue Apr 13 18:11:53 CEST 2010
@@ -152,6 +152,24 @@
       log.info("testInitialStateTransfer end - " + testCount);
    }
 
+   public void testInitialStateTransferCacheNotPresent() throws Exception {
+      testCount++;
+      log.info("testInitialStateTransferCacheNotPresent start - " + testCount);
+      Cache<Object, Object> cache1, cache2;
+      CacheManager cacheManager1 = createCacheManager();
+      cache1 = cacheManager1.getCache(cacheName);
+      writeInitialData(cache1);
+      cache2 = createCacheManager().getCache(cacheName);
+
+      // Pause to give caches time to see each other
+      TestingUtil.blockUntilViewsReceived(60000, cache1, cache2);
+      verifyInitialData(cache2);
+
+      cacheManager1.defineConfiguration("otherCache", config.clone());
+      cacheManager1.getCache("otherCache");
+      log.info("testInitialStateTransferCacheNotPresent end - " + testCount);
+   }
+
    public void testConcurrentStateTransfer() throws Exception {
       testCount++;
       log.info("testConcurrentStateTransfer start - " + testCount);
