Buggy code:
public class AnnualTeachingCredits extends AnnualTeachingCredits_Base { public AnnualTeachingCredits ( Teacher teacher , AnnualCreditsState annualCreditsState ) { } public boolean isPastResume ( ) { } public static AnnualTeachingCredits readByYearAndTeacher ( ExecutionYear executionYear , Teacher teacher ) { } public boolean isClosed ( ) { } @ Atomic public void calculateCredits ( ) { setMasterDegreeThesesCredits ( AnnualTeachingCredits . calculateMasterDegreeThesesCredits ( getTeacher ( ) , getAnnualCreditsState ( ) . getExecutionYear ( ) ) ) ; setPhdDegreeThesesCredits ( AnnualTeachingCredits . calculatePhdDegreeThesesCredits ( getTeacher ( ) , getAnnualCreditsState ( ) . getExecutionYear ( ) ) ) ; setProjectsTutorialsCredits ( AnnualTeachingCredits . calculateProjectsTutorialsCredits ( getTeacher ( ) , getAnnualCreditsState ( ) . getExecutionYear ( ) ) ) ; BigDecimal effectiveTeachingLoad = BigDecimal . ZERO ; BigDecimal teachingCredits = BigDecimal . ZERO ; BigDecimal managementFunctionsCredits = BigDecimal . ZERO ; BigDecimal reductionServiceCredits = BigDecimal . ZERO ; BigDecimal serviceExemptionCredits = BigDecimal . ZERO ; BigDecimal othersCredits = BigDecimal . ZERO ; BigDecimal annualTeachingLoad = BigDecimal . ZERO ; BigDecimal yearCredits = BigDecimal . ZERO ; BigDecimal yearCreditsForFinalCredits = BigDecimal . ZERO ; BigDecimal annualTeachingLoadFinalCredits = BigDecimal . ZERO ; boolean hasOrientantionCredits = false ; boolean hasFinalAndAccumulatedCredits = false ; for ( ExecutionSemester executionSemester : getAnnualCreditsState ( ) . getExecutionYear ( ) . getExecutionPeriodsSet ( ) ) { TeacherAuthorization teacherAuthorization = getTeacher ( ) . getTeacherAuthorization ( executionSemester . getAcademicInterval ( ) ) . orElse ( null ) ; boolean activeContractedTeacherForSemester = ( ( teacherAuthorization != null ) && ( teacherAuthorization . isContracted ( ) ) ) && ( PersonProfessionalData . isTeacherActiveForSemester ( getTeacher ( ) , executionSemester ) ) ; boolean activeExternalTeacher = ( teacherAuthorization != null ) && ( ! ( teacherAuthorization . isContracted ( ) ) ) ; if ( activeContractedTeacherForSemester || activeExternalTeacher ) { BigDecimal thisSemesterManagementFunctionCredits = new BigDecimal ( TeacherCredits . calculateManagementFunctionsCredits ( getTeacher ( ) , executionSemester ) ) ; managementFunctionsCredits = managementFunctionsCredits . add ( thisSemesterManagementFunctionCredits ) ; serviceExemptionCredits = serviceExemptionCredits . add ( new BigDecimal ( TeacherCredits . calculateServiceExemptionCredits ( getTeacher ( ) , executionSemester ) ) ) ; BigDecimal thisSemesterTeachingLoad = new BigDecimal ( TeacherCredits . calculateMandatoryLessonHours ( getTeacher ( ) , executionSemester ) ) ; annualTeachingLoad = annualTeachingLoad . add ( thisSemesterTeachingLoad ) . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) ; TeacherService teacherService = TeacherService . getTeacherServiceByExecutionPeriod ( getTeacher ( ) , executionSemester ) ; BigDecimal thisSemesterCreditsReduction = BigDecimal . ZERO ; if ( teacherService != null ) { effectiveTeachingLoad = effectiveTeachingLoad . add ( new BigDecimal ( teacherService . getDegreeTeachingServices ( ) . stream ( ) . filter ( ( d ) -> ! ( d . getProfessorship ( ) . getExecutionCourse ( ) . getProjectTutorialCourse ( ) ) ) . mapToDouble ( ( d ) -> d . getEfectiveLoad ( ) ) . sum ( ) ) ) ; teachingCredits = teachingCredits . add ( new BigDecimal ( teacherService . getTeachingDegreeCredits ( ) ) ) ; thisSemesterCreditsReduction = teacherService . getReductionServiceCredits ( ) ; othersCredits = othersCredits . add ( new BigDecimal ( teacherService . getOtherServiceCredits ( ) ) ) ; } reductionServiceCredits = reductionServiceCredits . add ( thisSemesterCreditsReduction ) ; BigDecimal reductionAndManagement = thisSemesterManagementFunctionCredits . add ( thisSemesterCreditsReduction ) ; BigDecimal thisSemesterYearCredits = thisSemesterTeachingLoad ; if ( ( thisSemesterTeachingLoad . compareTo ( reductionAndManagement ) ) > 0 ) { thisSemesterYearCredits = reductionAndManagement ; } else { setHasAnyLimitation ( true ) ; } yearCredits = yearCredits . add ( thisSemesterYearCredits ) ; boolean isTeacherMonitorCategory = getTeacher ( ) . getCategory ( executionSemester . getAcademicInterval ( ) ) . map ( ( tc ) -> tc . getProfessionalCategory ( ) ) . map ( ( pc ) -> pc . isTeacherMonitorCategory ( ) ) . orElse ( false ) ; if ( activeContractedTeacherForSemester && ( ! isTeacherMonitorCategory ) ) { yearCreditsForFinalCredits = yearCreditsForFinalCredits . add ( thisSemesterYearCredits ) ; annualTeachingLoadFinalCredits = annualTeachingLoadFinalCredits . add ( thisSemesterTeachingLoad ) ; if ( ( executionSemester . getSemester ( ) ) == 2 ) { hasFinalAndAccumulatedCredits = true ; } else { hasOrientantionCredits = true ; } } } } <START_BUG> setEffectiveTeachingLoad ( effectiveTeachingLoad ) ; <END_BUG> setTeachingCredits ( teachingCredits ) ; setManagementFunctionCredits ( managementFunctionsCredits ) ; setCreditsReduction ( reductionServiceCredits ) ; setServiceExemptionCredits ( serviceExemptionCredits ) ; setOthersCredits ( othersCredits ) ; setAnnualTeachingLoad ( annualTeachingLoad ) ; yearCredits = yearCredits . add ( teachingCredits ) . add ( serviceExemptionCredits ) . add ( othersCredits ) ; yearCreditsForFinalCredits = yearCreditsForFinalCredits . add ( teachingCredits ) . add ( serviceExemptionCredits ) . add ( othersCredits ) ; if ( hasOrientantionCredits ) { yearCredits = yearCredits . add ( getMasterDegreeThesesCredits ( ) ) . add ( getPhdDegreeThesesCredits ( ) ) . add ( getProjectsTutorialsCredits ( ) ) . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) ; yearCreditsForFinalCredits = yearCreditsForFinalCredits . add ( getMasterDegreeThesesCredits ( ) ) . add ( getPhdDegreeThesesCredits ( ) ) . add ( getProjectsTutorialsCredits ( ) ) ; } setYearCredits ( yearCredits ) ; BigDecimal accumulatedCredits = BigDecimal . ZERO ; BigDecimal finalCredits = BigDecimal . ZERO ; if ( hasFinalAndAccumulatedCredits ) { finalCredits = yearCreditsForFinalCredits . subtract ( annualTeachingLoadFinalCredits ) . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) ; BigDecimal lastYearAccumulated = getPreviousAccumulatedCredits ( ) ; accumulatedCredits = finalCredits . add ( lastYearAccumulated ) . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) ; } setFinalCredits ( finalCredits ) ; setAccumulatedCredits ( accumulatedCredits ) ; setLastModifiedDate ( new DateTime ( ) ) ; } private BigDecimal getPreviousAccumulatedCredits ( ) { } public AnnualTeachingCreditsDocument getLastTeacherCreditsDocument ( Boolean withConfidencialInformation ) { } public static BigDecimal calculateProjectsTutorialsCredits ( Teacher teacher , ExecutionYear executionYear ) { } public static BigDecimal calculatePhdDegreeThesesCredits ( Teacher teacher , ExecutionYear executionYear ) { } public static BigDecimal calculateMasterDegreeThesesCredits ( Teacher teacher , ExecutionYear executionYear ) { } }

Fix:
setEfectiveTeachingLoad ( effectiveTeachingLoad ) ;