Buggy code:
public class AnswerRatingOperations extends AbstractOperations { private final CalibrationOperations calibrationOperations ; private final WorkerCalibrationOperations workerCalibrationOperations ; private final ExperimentOperations experimentOperations ; public AnswerRatingOperations ( DSLContext create , CalibrationOperations calibrationOperations , WorkerCalibrationOperations workerCalibrationOperations , ExperimentOperations experimentOperations ) { } public Result < RatingRecord > getRatingsOfAnswer ( AnswerRecord answerRecord ) { } public Result < AnswerRecord > getAnswersOfWorkerFromExperiment ( int expID , int workerID ) { } public Result < AnswerRecord > getAnswersOfExperiment ( int expID ) { } public Map < WorkerRecord , List < AnswerRecord > > getGoodAnswersOfExperiment ( int expID , int threshold ) { } public Map < WorkerRecord , Integer > getNumOfGoodAnswersOfExperiment ( int expID , int threshold ) { } public Map < WorkerRecord , List < RatingRecord > > getGoodRatingsOfExperiment ( int expID , int threshold ) { } public Map < WorkerRecord , Integer > getNumOfGoodRatingsOfExperiment ( int expID , int threshold ) { } public Result < RatingRecord > getGoodRatingsOfAnswer ( AnswerRecord answerRecord , int threshold ) { } public void setQualityToRatings ( Map < RatingRecord , Integer > map ) { } public void setQualityToAnswer ( AnswerRecord answer , int quality ) { } public AnswerRecord insertNewAnswer ( AnswerRecord answerRecord ) throws IllegalArgumentException , IllegalStateException { } private int getAnswerCount ( int workerID , int experimentID ) { } public void setAnswerQualityAssured ( AnswerRecord answerRecord ) { } public Rating insertRating ( Rating rating ) throws IllegalArgumentException , IllegalStateException { } private void addToExperimentCalibration ( int workerID , int experimentId ) { } public Optional < AnswerRecord > getAnswer ( int answerID ) { } public Range < AnswerRecord , Integer > getAnswersFrom ( int expid , int cursor , boolean next , int limit ) { } public Optional < RatingRecord > getRating ( int id ) { } public List < Rating > getRatings ( int answerId ) { } public int getNumberOfFinalGoodAnswers ( int idExperiment ) { <START_BUG> return create . fetchCount ( DSL . selectFrom ( ANSWER ) . where ( EXPERIMENT . eq ( idExperiment ) ) . and ( QUALITY_ASSURED . eq ( true ) ) . and ( QUALITY . greaterThan ( DSL . select ( RESULT_QUALITY_THRESHOLD ) . from ( EXPERIMENT ) . where ( ID_EXPERIMENT . eq ( idExperiment ) ) ) ) ) ; <END_BUG> } public boolean allAnswersHaveMaxRatings ( int experiment ) { } public List < RatingRecord > getRelatedRatings ( int answersID ) { } public Optional < AnswerRecord > getAnswerFromRating ( Rating rating ) { } public void setSystemResponseField ( AnswerRecord answerRecord , String systemResponse ) { } public void updateAnswer ( AnswerRecord answer ) { } public List < AnswerRecord > getDuplicates ( long hash , int experiment , double threshold ) { } public List < AnswerRecord > getAnswersWithoutHash ( int expID ) { } }

Fix:
return create . fetchCount ( DSL . selectFrom ( ANSWER ) . where ( EXPERIMENT . eq ( idExperiment ) ) . and ( QUALITY_ASSURED . eq ( true ) ) . and ( QUALITY . greaterOrEqual ( DSL . select ( RESULT_QUALITY_THRESHOLD ) . from ( EXPERIMENT ) . where ( ID_EXPERIMENT . eq ( idExperiment ) ) ) ) ) ;