Buggy code:
private static final int FLAG_FLUSHED = 2 << 8 ; private static final int FLAG_PRE_FLUSHED = 2 << 9 ; private static final int FLAG_FLUSHED_DIRTY = 2 << 10 ; private static final int FLAG_IMPL_CACHE = 2 << 11 ; private static final int FLAG_INVERSES = 2 << 12 ; private static final int FLAG_NO_UNPROXY = 2 << 13 ; private static final int FLAG_VERSION_CHECK = 2 << 14 ; private static final int FLAG_VERSION_UPDATE = 2 << 15 ; private static final int FLAG_DETACHING = 2 << 16 ; private static final Localizer _loc = Localizer . forPackage ( StateManagerImpl . class ) ; private PersistenceCapable _pc = null ; private ClassMetaData _meta = null ; private BitSet _loaded = null ; private BitSet _dirty = null ; private BitSet _flush = null ; private int _flags = 0 ; private Object _id = null ; private Object _oid = null ; private final BrokerImpl _broker ; private PCState _state = PCState . TRANSIENT ; private Object _version = null ; private Object _loadVersion = null ; private Object _lock = null ; private int _readLockLevel = - 1 ; private int _writeLockLevel = - 1 ; private SingleFieldManager _single = null ; private SaveFieldManager _saved = null ; private FieldManager _fm = null ; private Object _impl = null ; private Object [ ] _fieldImpl = null ; private StateManagerImpl _owner = null ; private ValueMetaData _ownerMeta = null ; protected StateManagerImpl ( Object id , ClassMetaData meta , BrokerImpl broker ) { } void setOwner ( StateManagerImpl owner , ValueMetaData ownerMeta ) { } boolean isLoading ( ) { } void setLoading ( boolean loading ) { } private void setPCState ( PCState state ) { } public void initialize ( Class cls , PCState state ) { } protected void initialize ( PersistenceCapable pc , PCState state ) { } public boolean isIntercepting ( ) { } private boolean fireLifecycleEvent ( int type ) { } public void load ( FetchConfiguration fetch ) { } protected boolean load ( FetchConfiguration fetch , int loadMode , BitSet exclude , Object sdata , boolean forWrite ) { } public Object getManagedInstance ( ) { } public PersistenceCapable getPersistenceCapable ( ) { } public ClassMetaData getMetaData ( ) { } public OpenJPAStateManager getOwner ( ) { } public ValueMetaData getOwnerMetaData ( ) { } public boolean isEmbedded ( ) { } public boolean isFlushed ( ) { } public boolean isFlushedDirty ( ) { } public BitSet getLoaded ( ) { } public BitSet getFlushed ( ) { } public BitSet getDirty ( ) { } public BitSet getUnloaded ( FetchConfiguration fetch ) { } private BitSet getUnloadedInternal ( FetchConfiguration fetch , int mode , BitSet exclude ) { if ( exclude == ( StoreContext . EXCLUDE_ALL ) ) return null ; BitSet fields = null ; FieldMetaData [ ] fmds = _meta . getFields ( ) ; Set fgs = null ; boolean load ; for ( int i = 0 ; i < ( fmds . length ) ; i ++ ) { if ( ( exclude != null ) && ( exclude . get ( i ) ) ) continue ; switch ( mode ) { case StateManagerImpl . LOAD_SERIALIZE : load = ! ( fmds [ i ] . isTransient ( ) ) ; break ; case StateManagerImpl . LOAD_FGS : load = false ; if ( fgs == null ) fgs = new HashSet ( fmds . length ) ; fgs . add ( fmds [ i ] ) ; break ; default : load = true ; } if ( load ) { if ( fields == null ) fields = new BitSet ( fmds . length ) ; fields . set ( i ) ; } <START_BUG> if ( fgs != null ) { <END_BUG> if ( fields == null ) fields = new BitSet ( fmds . length ) ; BitSet fgFields = fetch . requiresFetch ( fgs , fmds ) ; for ( int j = 0 ; j < ( fgFields . length ( ) ) ; j ++ ) { if ( ( ( fgFields . get ( j ) ) && ( ! ( fields . get ( j ) ) ) ) && ( ! ( _loaded . get ( j ) ) ) ) fields . set ( j ) ; } } } return fields ; } public StoreContext getContext ( ) { } BrokerImpl getBroker ( ) { } public Object getId ( ) { } public Object getObjectId ( ) { } public void setObjectId ( Object oid ) { } public boolean assignObjectId ( boolean flush ) { } private boolean assignObjectId ( boolean flush , boolean preFlushing ) { } private void assertObjectIdAssigned ( boolean recache ) { } private boolean assignField ( int field , boolean preFlushing ) { } public Object getLock ( ) { } public void setLock ( Object lock ) { } public Object getVersion ( ) { } public void setVersion ( Object version ) { } Object getLoadVersion ( ) { } public void setNextVersion ( Object version ) { } private void assignVersionField ( Object version ) { } public PCState getPCState ( ) { } public synchronized Object getImplData ( ) { } public synchronized Object setImplData ( Object data , boolean cacheable ) { } public boolean isImplDataCacheable ( ) { } public Object getImplData ( int field ) { } public Object setImplData ( int field , Object data ) { } public synchronized boolean isImplDataCacheable ( int field ) { } public Object getIntermediate ( int field ) { } public void setIntermediate ( int field , Object data ) { } private synchronized Object getExtraFieldData ( int field , boolean isLoaded ) { } private synchronized Object setExtraFieldData ( int field , Object data , boolean loaded ) { }

Fix:
if ( ( fgs != null ) && ( fetch != null ) ) {