Buggy code:
public static final int XARETVAL_RBPROTO = 105 ; public static final int XARETVAL_RBTIMEOUT = 106 ; public static final int XARETVAL_RBTRANSIENT = 107 ; public static final int XARETVAL_NODISSOCIATE = 108 ; public static final int XARETVAL_XATWOPHASE = 13 ; public static final int XARETVAL_XAPROMOTED = 12 ; public static final int XARETVAL_XADEFERRED = 11 ; public static final int XARETVAL_XACOMMFAIL = 10 ; public static final int XARETVAL_XANOMIGRATE = 9 ; public static final int XARETVAL_XAHEURHAZ = 8 ; public static final int XARETVAL_XAHEURCOM = 7 ; public static final int XARETVAL_XAHEURRB = 6 ; public static final int XARETVAL_XAHEURMIX = 5 ; public static final int XARETVAL_XARETRY = 4 ; public static final int XARETVAL_XARDONLY = 3 ; public static final int XARETVAL_XAOK = 0 ; public static final int XARETVAL_XAERASYNC = - 2 ; public static final int XARETVAL_XAERRMERR = - 3 ; public static final int XARETVAL_XAERNOTA = - 4 ; public static final int XARETVAL_XAERINVAL = - 5 ; public static final int XARETVAL_XAERPROTO = - 6 ; public static final int XARETVAL_XAERRMFAIL = - 7 ; public static final int XARETVAL_XAERDUPID = - 8 ; public static final int XARETVAL_XAEROUTSIDE = - 9 ; public static final int XARETVAL_XAEROPENRES = - 10 ; public static final int XAFUNC_NONE = 0 ; public static final int XAFUNC_COMMIT = 1 ; public static final int XAFUNC_END = 2 ; public static final int XAFUNC_FORGET = 3 ; public static final int XAFUNC_PREPARE = 4 ; public static final int XAFUNC_RECOVER = 5 ; public static final int XAFUNC_ROLLBACK = 6 ; public static final int XAFUNC_START = 7 ; public static final String XAFUNCSTR_NONE = "No<seq2seq4repair_space>XA<seq2seq4repair_space>Function" ; public static final String XAFUNCSTR_COMMIT = "XAResource.commit()" ; public static final String XAFUNCSTR_END = "XAResource.end()" ; public static final String XAFUNCSTR_FORGET = "XAResource.forget()" ; public static final String XAFUNCSTR_PREPARE = "XAResource.prepare()" ; public static final String XAFUNCSTR_RECOVER = "XAResource.recover()" ; public static final String XAFUNCSTR_ROLLBACK = "XAResource.rollback()" ; public static final String XAFUNCSTR_START = "XAResource.start()" ; public int nextElement = 0 ; protected static Vector xaResourceSameRMGroup_ = new Vector ( ) ; protected int sameRMGroupIndex_ = 0 ; protected NetXAResource nextSameRM_ = null ; protected boolean ignoreMe_ = false ; public SqlException exceptionsOnXA = null ; XAConnection xaconn_ ; NetXAConnection conn_ ; int rmId_ ; NetXACallInfo [ ] callInfoArray_ = new NetXACallInfo [ NetXAResource . INITIAL_CALLINFO_ELEMENTS ] ; int numXACallInfo_ = NetXAResource . INITIAL_CALLINFO_ELEMENTS ; int connectionCount_ = 1 ; int activeXATransCount_ = 0 ; String rmIdx_ ; String rmIdy_ ; int port_ ; String ipaddr_ ; private List specialRegisters_ = Collections . synchronizedList ( new LinkedList ( ) ) ; public NetXAResource ( XAConnection xaconn , int rmId , String userId , String password , org . apache . derby . client . net . NetXAConnection conn ) { } public void commit ( Xid xid , boolean onePhase ) throws XAException { } public void end ( Xid xid , int flags ) throws XAException { } public void forget ( Xid xid ) throws XAException { } public int getTransactionTimeout ( ) throws XAException { } public int prepare ( Xid xid ) throws XAException { exceptionsOnXA = null ; if ( conn_ . agent_ . loggingEnabled ( ) ) { conn_ . agent_ . logWriter_ . traceEntry ( this , "prepare" , xid ) ; } if ( conn_ . isPhysicalConnClosed ( ) ) { connectionClosedFailure ( ) ; } NetAgent netAgent = conn_ . netAgent_ ; int rc = XAResource . XA_OK ; NetXACallInfo callInfo = callInfoArray_ [ conn_ . currXACallInfoOffset_ ] ; callInfo . xid_ = xid ; callInfo . xaResource_ = this ; callInfo . xaRetVal_ = NetXAResource . XARETVAL_XAOK ; try { netAgent . beginWriteChainOutsideUOW ( ) ; netAgent . netConnectionRequest_ . writeXaPrepare ( conn_ ) ; netAgent . flowOutsideUOW ( ) ; rc = netAgent . netConnectionReply_ . readXaPrepare ( conn_ ) ; if ( ( ( callInfo . xaRetVal_ ) != ( NetXAResource . XARETVAL_XAOK ) ) && ( ( callInfo . xaRetVal_ ) != ( NetXAResource . XARETVAL_XARDONLY ) ) ) { callInfo . xaFunction_ = NetXAResource . XAFUNC_PREPARE ; rc = xaRetValErrorAccumSQL ( callInfo , rc ) ; callInfo . xaRetVal_ = NetXAResource . XARETVAL_XAOK ; } netAgent . endReadChain ( ) ; } catch ( SqlException sqle ) { rc = XAException . XAER_RMERR ; exceptionsOnXA = org . apache . derby . client . am . Utils . accumulateSQLException ( sqle , exceptionsOnXA ) ; } finally { conn_ . pendingEndXACallinfoOffset_ = - 1 ; } <START_BUG> if ( rc != ( XAResource . XA_OK ) ) { <END_BUG> throwXAException ( rc , false ) ; } if ( conn_ . agent_ . loggingEnabled ( ) ) { conn_ . agent_ . logWriter_ . traceExit ( this , "prepare" , rc ) ; } return rc ; } public Xid [ ] recover ( int flag ) throws XAException { } public void rollback ( Xid xid ) throws XAException { } public boolean setTransactionTimeout ( int seconds ) throws XAException { } public synchronized void start ( Xid xid , int flags ) throws XAException { } protected void throwXAException ( int rc ) throws XAException { } private String getXAExceptionText ( int rc ) { } protected void throwXAException ( int rc , boolean resetFlag ) throws XAException { } private void setXaStateForXAException ( int rc ) { } public boolean isSameRM ( XAResource xares ) throws XAException { } public static boolean xidsEqual ( Xid xid1 , Xid xid2 ) { } public List getSpecialRegisters ( ) { } public void addSpecialRegisters ( String s ) { } private void connectionClosedFailure ( ) throws XAException { } private String getXAFuncStr ( int xaFunc ) { } protected int xaRetValErrorAccumSQL ( NetXACallInfo callInfo , int currentRC ) { } private String processLocalHost ( String serverName ) { } protected void removeXaresFromSameRMchain ( ) { } public void initForReuse ( ) { } }

Fix:
if ( ( rc != ( XAResource . XA_OK ) ) && ( rc != ( XAResource . XA_RDONLY ) ) ) {