Buggy code:
public class UpdateAncestorUnitDAO extends BaseDAO < Boolean > { private int unitId ; public UpdateAncestorUnitDAO ( HttpServlet servlet , int unitId ) { } @ Override protected Boolean processData ( Connection connection ) throws Exception { int level = UnitFieldDAO . level ( connection , unitId ) ; if ( ( level != 2 ) && ( level != 3 ) ) return false ; for ( int fatherId = unitId ; ; level -- ) { fatherId = UnitFieldDAO . fatherId ( connection , fatherId ) ; <START_BUG> if ( fatherId == 0 ) <END_BUG> break ; String sql = ( level == 3 ) ? "UPDATE<seq2seq4repair_space>tab_unit<seq2seq4repair_space>CROSS<seq2seq4repair_space>JOIN<seq2seq4repair_space>(" + ( ( ( ( ( ( ( "SELECT<seq2seq4repair_space>sum(A.unitnum)<seq2seq4repair_space>AS<seq2seq4repair_space>sumUnitNum<seq2seq4repair_space>" + "FROM<seq2seq4repair_space>tab_unit<seq2seq4repair_space>AS<seq2seq4repair_space>A<seq2seq4repair_space>" ) + "WHERE<seq2seq4repair_space>A.valid<seq2seq4repair_space>=<seq2seq4repair_space>1" ) + "<seq2seq4repair_space>AND<seq2seq4repair_space>A.fatherid<seq2seq4repair_space>=<seq2seq4repair_space>?" ) + ")<seq2seq4repair_space>AS<seq2seq4repair_space>B<seq2seq4repair_space>" ) + "SET<seq2seq4repair_space>unitNum<seq2seq4repair_space>=<seq2seq4repair_space>B.sumUnitNum<seq2seq4repair_space>" ) + "WHERE<seq2seq4repair_space>valid<seq2seq4repair_space>=<seq2seq4repair_space>1" ) + "<seq2seq4repair_space>AND<seq2seq4repair_space>id<seq2seq4repair_space>=<seq2seq4repair_space>?" ) : "UPDATE<seq2seq4repair_space>tab_unit<seq2seq4repair_space>CROSS<seq2seq4repair_space>JOIN<seq2seq4repair_space>(" + ( ( ( ( ( ( ( ( ( ( ( ( ( "SELECT<seq2seq4repair_space>round(sum(A.area),2)<seq2seq4repair_space>AS<seq2seq4repair_space>sumArea," + "<seq2seq4repair_space>sum(A.population1)<seq2seq4repair_space>AS<seq2seq4repair_space>sumPopulation1," ) + "<seq2seq4repair_space>sum(A.population2)<seq2seq4repair_space>AS<seq2seq4repair_space>sumPopulation2," ) + "<seq2seq4repair_space>sum(A.unitnum)<seq2seq4repair_space>AS<seq2seq4repair_space>sumUnitNum<seq2seq4repair_space>" ) + "FROM<seq2seq4repair_space>tab_unit<seq2seq4repair_space>AS<seq2seq4repair_space>A<seq2seq4repair_space>" ) + "WHERE<seq2seq4repair_space>A.valid<seq2seq4repair_space>=<seq2seq4repair_space>1" ) + "<seq2seq4repair_space>AND<seq2seq4repair_space>A.fatherid<seq2seq4repair_space>=<seq2seq4repair_space>?" ) + ")<seq2seq4repair_space>AS<seq2seq4repair_space>B<seq2seq4repair_space>" ) + "SET<seq2seq4repair_space>area<seq2seq4repair_space>=<seq2seq4repair_space>B.sumArea," ) + "<seq2seq4repair_space>population1<seq2seq4repair_space>=<seq2seq4repair_space>B.sumPopulation1," ) + "<seq2seq4repair_space>population2<seq2seq4repair_space>=<seq2seq4repair_space>B.sumPopulation2," ) + "<seq2seq4repair_space>unitnum<seq2seq4repair_space>=<seq2seq4repair_space>B.sumUnitNum<seq2seq4repair_space>" ) + "WHERE<seq2seq4repair_space>valid<seq2seq4repair_space>=<seq2seq4repair_space>1" ) + "<seq2seq4repair_space>AND<seq2seq4repair_space>id<seq2seq4repair_space>=<seq2seq4repair_space>?" ) ; PreparedStatement ps = connection . prepareStatement ( sql ) ; ps . setInt ( 1 , fatherId ) ; ps . setInt ( 2 , fatherId ) ; ps . executeUpdate ( ) ; } return true ; } }

Fix:
if ( fatherId <= 0 )