Detailed information about defect clone:

16-C0.H1.M0.L0_T_S_07.war

 

Nickname of the defect

record-with-empty-item

Brief desctiption

Creation of new exam date in New Exam Date without exam date and time.

How to activate the defect

 

Visibility of the defect

Expected Actual

Parts

StudentService TeacherService DateUtility GradeDAO UserDAO
BaseStudentService E07TeacherService BaseDateUtility GradeTypeDaoCriteria UserDaoCriteria

URL to the defect source code

https://gitlab.kiv.zcu.cz/herout/TbUIS-UIS/blob/master/src/main/java/cz/zcu/kiv/matyasj/dp/service/users/error/E07TeacherService.java

Source code with the injected defect

/** * DELIBERATE ERROR * * This error method enables creation of new exam date for particular teacher and for subject * even without date and time of examination. * * @param teacher Teacher who wants to create a new exam * @param subjectId New exam date will be created for subject with this database id * @param dateOfTerm Date of new examination * @param maxParticipants Maximal number of participants * @return true if operation will be successfully completed, false otherwise */ @Override @ErrorMethod(errorMessage = "This method enables creation of new exam date without date and time of examination.") public boolean createNewExaminationTerm(Teacher teacher, Long subjectId, String dateOfTerm, String maxParticipants) { if (teacher == null) { log.error("Creating new examination term failed."); return false; } log.info("Creating new examination term for subject with id " + subjectId + ", teacher with id " + teacher.getId() + ", date " + dateOfTerm + " and maximal number of participants " + maxParticipants + "."); Date tmpDateOfTerm = null; if (!"".equals(dateOfTerm)) { tmpDateOfTerm = dateUtility.stringToDate(dateOfTerm); } int maxParticipantsInt = 0; try { maxParticipantsInt = Integer.parseInt(maxParticipants); } catch (Exception e) { log.warn("Maximal number of exam date participants exceeded! Creation of new examination term is being canceled."); } // Test if maximal number of participants is too low if (maxParticipantsInt < Integer.parseInt(propertyLoader.getProperty("examTermMinParticipants"))) { log.warn("Maximal number of exam date participants too low! Creation of new examination term is being canceled."); return false; } // Test if maximal number of participants is not exceeded if (maxParticipantsInt > Integer.parseInt(propertyLoader.getProperty("examTermMaxParticipants"))) { log.warn("Maximal number of exam date participants exceeded! Creation of new examination term is being canceled."); return false; } Subject subject = subjectDao.findOne(subjectId); if (subject == null) { log.error("Creating new examination term failed."); return false; } List<ExaminationDate> examinationDates = getAllExaminationTermsBySubject(subject); if (examinationDates.size() != 0) { ExaminationDate lastExam = null; int registeredExamsCount = 0; for (ExaminationDate exam : examinationDates) { if (exam.getTeacher().getUsername().equals(teacher.getUsername())) { lastExam = exam; registeredExamsCount++; } } if (lastExam != null) { // Teacher has already registered exam // Test max exam dates for this subject and teacher int maxExamTermNumber = Integer.parseInt(propertyLoader.getProperty("subjectMaxExamDate")); if (registeredExamsCount >= maxExamTermNumber) { log.warn("Teacher " + teacher.getFirstName() + " " + teacher.getLastName() + " is trying to create more than " + "max count of exam dates for this subject(" + maxExamTermNumber + ")!"); return false; } } } ExaminationDate newExaminationDate = new ExaminationDate(); newExaminationDate.setDateOfTest(tmpDateOfTerm); newExaminationDate.setMaxParticipants(maxParticipantsInt); newExaminationDate = examinationDateDao.save(newExaminationDate); Teacher tmpTeacher = (Teacher) userDao.findOne(teacher.getId()); Subject tmpSubject = subjectDao.findOne(subjectId); if (tmpSubject == null) { log.error("Creating new examination term failed."); return false; } newExaminationDate.setTeacher(tmpTeacher); newExaminationDate.setSubject(tmpSubject); newExaminationDate = examinationDateDao.save(newExaminationDate); if (newExaminationDate != null && newExaminationDate.getId() != null) { log.error(propertyLoader.getProperty("log.E07TeacherService.createNewExaminationTerm")); return true; } log.error("Creating new examination term failed."); return false; }

URL to the correct source code

https://gitlab.kiv.zcu.cz/herout/TbUIS-UIS/blob/master/src/main/java/cz/zcu/kiv/matyasj/dp/service/users/correct/BaseTeacherService.java

Correct source code

/** * This method creates new exam date for particular teacher and for subject. * * @param teacher Teacher who wants to create a new exam * @param subjectId New exam date will be created for subject with this database id * @param dateOfTerm Date of new examination * @param maxParticipants Maximal number of participants * @return true if operation will be successfully completed, false otherwise */ @Override public boolean createNewExaminationTerm(Teacher teacher, Long subjectId, String dateOfTerm, String maxParticipants) { if (teacher == null) { log.error("Creating new examination term failed."); return false; } log.info("Creating new examination term for subject with id " + subjectId + ", teacher with id " + teacher.getId() + ", date " + dateOfTerm + " and maximal number of participants " + maxParticipants + "."); Date tmpDateOfTerm = dateUtility.stringToDate(dateOfTerm); // Test if date is null if (tmpDateOfTerm == null) { log.warn("Date of new examination term is null! Creation of new examination term is being canceled."); return false; } // Test if date is in future if (!tmpDateOfTerm.after(new Date())) { log.warn("Date of new examination term is not in future! Creation of new examination term is being canceled."); return false; } int maxParticipantsInt = 0; try { maxParticipantsInt = Integer.parseInt(maxParticipants); } catch (Exception e) { log.warn("Maximal number of exam date participants exceeded! Creation of new examination term is being canceled."); } // Test if maximal number of participants is too low if (maxParticipantsInt < Integer.parseInt(propertyLoader.getProperty("examTermMinParticipants"))) { log.warn("Maximal number of exam date participants too low! Creation of new examination term is being canceled."); return false; } // Test if maximal number of participants is not exceeded if (maxParticipantsInt > Integer.parseInt(propertyLoader.getProperty("examTermMaxParticipants"))) { log.warn("Maximal number of exam date participants exceeded! Creation of new examination term is being canceled."); return false; } Subject subject = subjectDao.findOne(subjectId); if (subject == null) { log.error("Creating new examination term failed."); return false; } List<ExaminationDate> examinationDates = getAllExaminationTermsBySubject(subject); final int millisecondsInMinute = 60000; final int minutesInDay = 24 * 60; if (examinationDates.size() != 0) { ExaminationDate lastExam = null; int registeredExamsCount = 0; for (ExaminationDate exam : examinationDates) { if (exam.getTeacher().getUsername().equals(teacher.getUsername())) { if (lastExam == null || lastExam.getDateOfTest().before(exam.getDateOfTest())) { lastExam = exam; registeredExamsCount++; } } } if (lastExam != null) { // Teacher has already registered exam // Calculated time for exam dates comparing long latestExamTime = lastExam.getDateOfTest().getTime() / millisecondsInMinute; long newExamTime = tmpDateOfTerm.getTime() / millisecondsInMinute; // Test if date is same as previous examination date if (latestExamTime == newExamTime) { log.warn("Date of new examination term is same as the date of previous term! Creation of new examination term is being canceled."); return false; } // Test if date is at least 24 hours after previous examination date if ((newExamTime - latestExamTime) < minutesInDay) { log.warn("Date of new examination term is set sooner than 24 hours after previous exam date! Creation of new examination term is being canceled."); return false; } // Test max exam dates for this subject and teacher int maxExamTermNumber = Integer.parseInt(propertyLoader.getProperty("subjectMaxExamDate")); if (registeredExamsCount >= maxExamTermNumber) { log.warn("Teacher " + teacher.getFirstName() + " " + teacher.getLastName() + " is trying to create more than " + "max count of exam dates for this subject(" + maxExamTermNumber + ")!"); return false; } } } ExaminationDate newExaminationDate = new ExaminationDate(); newExaminationDate.setDateOfTest(tmpDateOfTerm); newExaminationDate.setMaxParticipants(maxParticipantsInt); newExaminationDate = examinationDateDao.save(newExaminationDate); Teacher tmpTeacher = (Teacher) userDao.findOne(teacher.getId()); Subject tmpSubject = subjectDao.findOne(subjectId); if (tmpSubject == null) { log.error("Creating new examination term failed."); return false; } newExaminationDate.setTeacher(tmpTeacher); newExaminationDate.setSubject(tmpSubject); newExaminationDate = examinationDateDao.save(newExaminationDate); if (newExaminationDate != null && newExaminationDate.getId() != null) { return true; } log.error("Creating new examination term failed."); return false; }

Logged information up to failure

2019-10-12 15:56:23.150 -- INFO LogHelper:31 - HHH000204: Processing PersistenceUnitInfo [name: cz.zcu.kiv.matyasj.dp] 2019-10-12 15:56:23.384 -- INFO Version:46 - HHH000412: Hibernate Core {5.4.1.Final} 2019-10-12 15:56:23.806 -- INFO Version:49 - HCANN000001: Hibernate Commons Annotations {5.1.0.Final} 2019-10-12 15:56:24.228 -- INFO C3P0ConnectionProvider:116 - HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/uis-web-db 2019-10-12 15:56:24.228 -- INFO C3P0ConnectionProvider:117 - HHH10001001: Connection properties: {password=****, useUnicode=true, handling_mode=DELAYED_ACQUISITION_AND_HOLD, characterEncoding=UTF-8, user=uis-web} 2019-10-12 15:56:24.228 -- INFO C3P0ConnectionProvider:120 - HHH10001003: Autocommit mode: false 2019-10-12 15:56:24.433 -- INFO C3P0ConnectionProvider:200 - HHH10001007: JDBC isolation level: <unknown> 2019-10-12 15:56:24.823 -- INFO Dialect:158 - HHH000400: Using dialect: org.hibernate.dialect.MySQL55Dialect 2019-10-12 15:56:26.620 -- INFO access:47 - HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@1bd5577e] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode. 2019-10-12 15:56:28.762 -- INFO access:47 - HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@2d45db20] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode. 2019-10-12 15:56:41.219 -- INFO JtaPlatformInitiator:52 - HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] 2019-10-12 15:56:41.453 -- INFO SecurityConfig:75 - SECURITY JDBC authentication process is running 2019-10-12 15:56:43.891 -- INFO SecurityConfig:93 - Authorization configuration process is running 2019-10-12 15:56:44.234 -- INFO BaseInitializer:97 - Initializing ... 2019-10-12 15:56:51.095 -- INFO BaseInitializer:463 - Initialized! 2019-10-12 15:56:51.220 -- INFO BaseInitializer:97 - Initializing ... 2019-10-12 15:59:34.204 -- INFO LoginController:30 - Request for login view 2019-10-12 15:59:42.363 -- INFO UserDaoCriteria:74 - User with username easyrider found. 2019-10-12 15:59:42.425 -- INFO SecurityConfig:121 - Success login - easyrider 2019-10-12 15:59:42.425 -- INFO SecurityConfig:125 - User login role: ROLE_TEACHER 2019-10-12 15:59:42.441 -- INFO UserDaoCriteria:74 - User with username easyrider found. 2019-10-12 15:59:42.456 -- INFO OverviewController:53 - Request for overview of teacher with id 27 for view. 2019-10-12 15:59:44.927 -- INFO NewExamDateController:44 - Request for retrieving new exam date form view. 2019-10-12 15:59:44.927 -- INFO UserDaoCriteria:74 - User with username easyrider found. 2019-10-12 15:59:44.943 -- INFO BaseTeacherService:92 - Getting list of taught subjects for teacher with id 27. 2019-10-12 16:00:21.487 -- INFO UserDaoCriteria:74 - User with username easyrider found. 2019-10-12 16:00:21.503 -- INFO NewExamDateController:95 - Request from user with id 27 for saving new exam date with subject id 8, date and maximal number of participants 1. 2019-10-12 16:00:21.503 -- INFO E07TeacherService:66 - Creating new examination term for subject with id 8, teacher with id 27, date and maximal number of participants 1. 2019-10-12 16:00:21.519 -- INFO BaseTeacherService:274 - Getting all examination terms by subject with id 8. 2019-10-12 16:00:21.581 -- INFO ExaminationDateDaoCriteria:141 - Returning list of 1 examination dates for subject with id 8. 2019-10-12 16:00:21.597 -- INFO BaseTeacherService:342 - Getting all examination terms by subject for subject with id 8. 2019-10-12 16:00:21.753 -- ERROR E07TeacherService:145 - INJECTED_ERROR: E07TeacherService_createNewExaminationTerm_enables_creation_of_exam_without_date_and_time 2019-10-12 16:00:21.753 -- INFO NewExamDateController:99 - Request for saving new exam date with subject id 8, date and maximal number of participants 1 was successful. 2019-10-12 16:00:21.753 -- INFO NewExamDateController:44 - Request for retrieving new exam date form view.

Overview of functional tests full log

Overview of acceptance tests full report