Buggy code:
public class JDBCStoreManager implements JDBCStore , StoreManager { private static final Localizer _loc = Localizer . forPackage ( JDBCStoreManager . class ) ; private StoreContext _ctx = null ; private JDBCConfiguration _conf = null ; private DBDictionary _dict = null ; private SQLFactory _sql = null ; private JDBCLockManager _lm = null ; private DataSource _ds = null ; private JDBCStoreManager . RefCountConnection _conn = null ; private boolean _active = false ; private Set _stmnts = Collections . synchronizedSet ( new HashSet ( ) ) ; private static final Constructor < JDBCStoreManager . ClientConnection > clientConnectionImpl ; private static final Constructor < JDBCStoreManager . RefCountConnection > refCountConnectionImpl ; private static final Constructor < JDBCStoreManager . CancelStatement > cancelStatementImpl ; private static final Constructor < JDBCStoreManager . CancelPreparedStatement > cancelPreparedStatementImpl ; public StoreContext getContext ( ) { } public void setContext ( StoreContext ctx ) { } public void setContext ( StoreContext ctx , JDBCConfiguration conf ) { } public JDBCConfiguration getConfiguration ( ) { } public DBDictionary getDBDictionary ( ) { } public SQLFactory getSQLFactory ( ) { } public JDBCLockManager getLockManager ( ) { } public JDBCFetchConfiguration getFetchConfiguration ( ) { } public void beginOptimistic ( ) { } public void rollbackOptimistic ( ) { } public void begin ( ) { } public void commit ( ) { } public void rollback ( ) { } public void retainConnection ( ) { } public void releaseConnection ( ) { } public Object getClientConnection ( ) { } public Connection getConnection ( ) { } protected DataSource getDataSource ( ) { } public boolean exists ( OpenJPAStateManager sm , Object context ) { } private boolean exists ( ClassMapping mapping , Object oid , Object context ) { } public boolean syncVersion ( OpenJPAStateManager sm , Object context ) { } public int compareVersion ( OpenJPAStateManager state , Object v1 , Object v2 ) { } public boolean initialize ( OpenJPAStateManager sm , PCState state , FetchConfiguration fetch , Object context ) { } protected boolean initializeState ( OpenJPAStateManager sm , PCState state , JDBCFetchConfiguration fetch , ConnectionInfo info ) throws ClassNotFoundException , SQLException { } private void setInverseRelation ( OpenJPAStateManager owner , ClassMapping mapping , Result res ) { } protected void setMappedBy ( OpenJPAStateManager sm , FieldMapping mappedByFieldMapping , Object mappedByObject ) { ClassMapping mapping = ( ( ClassMapping ) ( sm . getMetaData ( ) ) ) ; <START_BUG> FieldMapping [ ] fms = mapping . getDeclaredFieldMappings ( ) ; <END_BUG> for ( int i = 0 ; i < ( fms . length ) ; i ++ ) { if ( ( fms [ i ] ) == mappedByFieldMapping ) { sm . storeObject ( fms [ i ] . getIndex ( ) , mappedByObject ) ; return ; } } } protected void getVersion ( ClassMapping mapping , OpenJPAStateManager sm , Result res ) throws SQLException { } protected boolean isEmptyResult ( Result res ) throws SQLException { } protected Class getType ( Result res , ClassMapping mapping ) { } private Boolean customLoad ( OpenJPAStateManager sm , ClassMapping mapping , PCState state , JDBCFetchConfiguration fetch ) throws ClassNotFoundException , SQLException { } private Result getInitializeStateResult ( OpenJPAStateManager sm , ClassMapping mapping , JDBCFetchConfiguration fetch , int subs ) throws SQLException { } private Result getInitializeStateUnionResult ( final OpenJPAStateManager sm , ClassMapping mapping , final ClassMapping [ ] mappings , final JDBCFetchConfiguration fetch ) throws SQLException { } private boolean selectPrimaryKey ( OpenJPAStateManager sm , ClassMapping mapping , JDBCFetchConfiguration fetch ) throws SQLException { } public boolean load ( OpenJPAStateManager sm , BitSet fields , FetchConfiguration fetch , int lockLevel , Object context ) { } private void removeLoadedFields ( OpenJPAStateManager sm , BitSet fields ) { } public Collection loadAll ( Collection sms , PCState state , int load , FetchConfiguration fetch , Object context ) { } public void beforeStateChange ( OpenJPAStateManager sm , PCState fromState , PCState toState ) { } public Collection flush ( Collection sms ) { } public boolean cancelAll ( ) { } public boolean assignObjectId ( OpenJPAStateManager sm , boolean preFlush ) { } public boolean assignField ( OpenJPAStateManager sm , int field , boolean preFlush ) { } public Class getManagedType ( Object oid ) { } public Class getDataStoreIdType ( ClassMetaData meta ) { } public Object copyDataStoreId ( Object oid , ClassMetaData meta ) { } public Object newDataStoreId ( Object val , ClassMetaData meta ) { } public Id newDataStoreId ( long id , ClassMapping mapping , boolean subs ) { } public ResultObjectProvider executeExtent ( ClassMetaData meta , final boolean subclasses , FetchConfiguration fetch ) { } private BitSet selectExtent ( Select sel , ClassMapping mapping , JDBCFetchConfiguration fetch , boolean subclasses ) { } public StoreQuery newQuery ( String language ) { } public FetchConfiguration newFetchConfiguration ( ) { } public Seq getDataStoreIdSequence ( ClassMetaData meta ) { } public Seq getValueSequence ( FieldMetaData fmd ) { } public void close ( ) { } private void connect ( boolean ref ) { } protected JDBCStoreManager . RefCountConnection connectInternal ( ) throws SQLException { } public Connection getNewConnection ( ) { } public Object find ( Object oid , ValueMapping vm , JDBCFetchConfiguration fetch ) { } public Object load ( ClassMapping mapping , JDBCFetchConfiguration fetch , BitSet exclude , Result result ) throws SQLException { } private BitSet excludeInverseRelation ( ClassMapping mapping , ConnectionInfo info , BitSet exclude ) { } private void load ( ClassMapping mapping , OpenJPAStateManager sm , JDBCFetchConfiguration fetch , Result res ) throws SQLException { } private FieldMapping load ( ClassMapping mapping , OpenJPAStateManager sm , JDBCFetchConfiguration fetch , Result res , FieldMapping eagerToMany ) throws SQLException { } public boolean select ( Select sel , ClassMapping mapping , int subs , OpenJPAStateManager sm , BitSet fields , JDBCFetchConfiguration fetch , int eager , boolean ident , boolean outer ) { }

Fix:
FieldMapping [ ] fms = mapping . getFieldMappings ( ) ;