Buggy code:
public class DetachManager implements DetachState { private static Localizer _loc = Localizer . forPackage ( DetachManager . class ) ; private final BrokerImpl _broker ; private final boolean _copy ; private final boolean _full ; private final ProxyManager _proxy ; private final DetachOptions _opts ; private final OpCallbacks _call ; private final boolean _failFast ; private boolean _flushed = false ; private final IdentityMap _detached ; private final DetachManager . DetachFieldManager _fullFM ; static boolean preSerialize ( StateManagerImpl sm ) { } static boolean writeDetachedState ( StateManagerImpl sm , ObjectOutput out , BitSet idxs ) throws IOException { } private static void preDetach ( Broker broker , StateManagerImpl sm , BitSet idxs ) { int detachMode = broker . getDetachState ( ) ; int loadMode = StateManagerImpl . LOAD_FGS ; BitSet exclude = null ; if ( detachMode == ( DETACH_LOADED ) ) exclude = StoreContext . EXCLUDE_ALL ; else if ( detachMode == ( DETACH_ALL ) ) loadMode = StateManagerImpl . LOAD_ALL ; try { sm . load ( broker . getFetchConfiguration ( ) , loadMode , exclude , null , false ) ; } catch ( ObjectNotFoundException onfe ) { } if ( idxs != null ) { <START_BUG> if ( detachMode == ( DETACH_FGS ) ) <END_BUG> DetachManager . setFetchGroupFields ( broker , sm , idxs ) ; else idxs . or ( sm . getLoaded ( ) ) ; FieldMetaData [ ] fmds = sm . getMetaData ( ) . getFields ( ) ; for ( int i = 0 ; i < ( fmds . length ) ; i ++ ) if ( fmds [ i ] . isLRS ( ) ) idxs . clear ( i ) ; } } private static Object getDetachedState ( StateManagerImpl sm , BitSet fields ) { } private static boolean flushDirty ( StateManagerImpl sm ) { } private static void setFetchGroupFields ( Broker broker , StateManagerImpl sm , BitSet idxs ) { } public DetachManager ( BrokerImpl broker , boolean full , OpCallbacks call ) { } public Object detach ( Object toDetach ) { } public Object [ ] detachAll ( Collection instances ) { } private List invokeAfterDetach ( Collection objs , List exceps ) { } private List add ( List exceps , RuntimeException re ) { } private void throwExceptions ( List exceps ) { } private Object detachInternal ( Object toDetach ) { } private static boolean useDetachedStateManager ( StateManagerImpl sm , DetachOptions opts ) { } private static class DetachFieldManager extends TransferFieldManager { protected StateManagerImpl sm ; public void setStateManager ( StateManagerImpl sm ) { } public void detachVersion ( ) { } public void reproxy ( DetachedStateManager dsm ) { } protected PersistenceCapable getDetachedPersistenceCapable ( ) { } } private class InstanceDetachFieldManager extends DetachManager . DetachFieldManager { private final PersistenceCapable _to ; private final DetachedStateManager _detSM ; public InstanceDetachFieldManager ( PersistenceCapable to , DetachedStateManager detSM ) { } protected PersistenceCapable getDetachedPersistenceCapable ( ) { } public void detachFields ( BitSet fgfields ) { } private void detachField ( PersistenceCapable from , int i , boolean fg ) { } public void storeBooleanField ( int field , boolean curVal ) { } public void storeByteField ( int field , byte curVal ) { } public void storeCharField ( int field , char curVal ) { } public void storeDoubleField ( int field , double curVal ) { } public void storeFloatField ( int field , float curVal ) { } public void storeIntField ( int field , int curVal ) { } public void storeLongField ( int field , long curVal ) { } public void storeShortField ( int field , short curVal ) { } public void storeStringField ( int field , String curVal ) { } public void storeObjectField ( int field , Object curVal ) { } private Object reproxy ( Object obj , int field ) { } private Object detachField ( Object curVal , int field ) { } private void detachArray ( Object array , FieldMetaData fmd ) { } private void detachCollection ( Collection coll , Collection orig , FieldMetaData fmd ) { } private void detachMap ( Map map , Map orig , FieldMetaData fmd ) { } } }

Fix:
if ( detachMode == ( DETACH_FETCH_GROUPS ) )