Detailed information about defect clone:
14-C0.H1.M0.L0_D_U_01.war
Nickname of the defect
off-by-one-date-input-record
Brief desctiption
Date in New Exam Date is shifted to next day.
How to activate the defect
-
Click on Login in the header
-
Username
pedant
, password pass
, click on Login button
-
Click on New Exam Date
-
Enter
2050-01-02 10:00
in Date and time of examination
-
Click on Save new exam date
-
Click on My Exam dates
Visibility of the defect
Parts
StudentService |
TeacherService |
DateUtility |
GradeDAO |
UserDAO |
BaseStudentService
|
BaseTeacherService
|
E01DateUtility
|
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/utils/dates/error/E01DateUtility.java
Source code with the injected defect
/**
* DELIBERATE ERROR
*
* This method returns Date object from string representation given in
* method parameter + 1 Day.
*
* @param stringDate String representation of date
* @return Date object
*/
@Override
@ErrorMethod(errorMessage = "This method returns Date object from string representation given in method parameter + 1 Day.")
public Date stringToDate(String stringDate) {
Date date;
try {
switch (stringDate.length()) {
case 16: // yyyy-MM-dd HH:mm
date = sdfDateAndTime.parse(stringDate);
date = new Date(date.getTime() + 86400000);
log.error(propertyLoader.getProperty("log.E01DateUtility.stringToDate"));
return date;
case 10: // yyyy-MM-dd
date = sdfDate.parse(stringDate);
date = new Date(date.getTime() + 86400000);
log.error(propertyLoader.getProperty("log.E01DateUtility.stringToDate"));
return date;
case 5: // HH:mm
date = sdfTime.parse(stringDate);
date = new Date(date.getTime() + 86400000);
log.error(propertyLoader.getProperty("log.E01DateUtility.stringToDate"));
return date;
}
} catch (ParseException e) {
log.error("Error during date parsing!", e);
}
return null;
}
URL to the correct source code
https://gitlab.kiv.zcu.cz/herout/TbUIS-UIS/blob/master/src/main/java/cz/zcu/kiv/matyasj/dp/utils/dates/correct/BaseDateUtility.java
Correct source code
/**
* This method returns Date object from string representation given in
* method parameter.
*
* @param stringDate String representation of date
* @return Date object
*/
@Override
public Date stringToDate(String stringDate) {
try {
switch (stringDate.length()) {
case 16: // yyyy-MM-dd HH:mm
log.info("Parsing string representation of date to Date object");
return sdfDateAndTime.parse(stringDate);
case 10: // yyyy-MM-dd
log.info("Parsing string representation of date to Date object");
return sdfDate.parse(stringDate);
case 5: // HH:mm
log.info("Parsing string representation of date to Date object");
return sdfTime.parse(stringDate);
}
} catch (ParseException e) {
log.error("Error during date parsing!", e);
}
return null;
}
Logged information up to failure
2019-10-12 17:49:54.906 -- INFO LogHelper:31 - HHH000204: Processing PersistenceUnitInfo [name: cz.zcu.kiv.matyasj.dp]
2019-10-12 17:49:55.124 -- INFO Version:46 - HHH000412: Hibernate Core {5.4.1.Final}
2019-10-12 17:49:55.524 -- INFO Version:49 - HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2019-10-12 17:49:55.946 -- INFO C3P0ConnectionProvider:116 - HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/uis-web-db
2019-10-12 17:49:55.946 -- INFO C3P0ConnectionProvider:117 - HHH10001001: Connection properties: {password=****, useUnicode=true, handling_mode=DELAYED_ACQUISITION_AND_HOLD, characterEncoding=UTF-8, user=uis-web}
2019-10-12 17:49:55.946 -- INFO C3P0ConnectionProvider:120 - HHH10001003: Autocommit mode: false
2019-10-12 17:49:56.149 -- INFO C3P0ConnectionProvider:200 - HHH10001007: JDBC isolation level:
2019-10-12 17:49:56.524 -- INFO Dialect:158 - HHH000400: Using dialect: org.hibernate.dialect.MySQL55Dialect
2019-10-12 17:49:58.266 -- INFO access:47 - HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@24b4cee9] 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 17:50:00.703 -- INFO access:47 - HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@29ab7ccc] 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 17:50:14.425 -- INFO JtaPlatformInitiator:52 - HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2019-10-12 17:50:14.706 -- INFO SecurityConfig:75 - SECURITY JDBC authentication process is running
2019-10-12 17:50:17.084 -- INFO SecurityConfig:93 - Authorization configuration process is running
2019-10-12 17:50:17.412 -- INFO BaseInitializer:97 - Initializing ...
2019-10-12 17:50:24.039 -- INFO BaseInitializer:463 - Initialized!
2019-10-12 17:50:24.179 -- INFO BaseInitializer:97 - Initializing ...
2019-10-12 17:56:14.661 -- INFO LoginController:30 - Request for login view
2019-10-12 17:56:20.943 -- INFO UserDaoCriteria:74 - User with username pedant found.
2019-10-12 17:56:21.021 -- INFO SecurityConfig:121 - Success login - pedant
2019-10-12 17:56:21.021 -- INFO SecurityConfig:125 - User login role: ROLE_TEACHER
2019-10-12 17:56:21.053 -- INFO UserDaoCriteria:74 - User with username pedant found.
2019-10-12 17:56:21.068 -- INFO OverviewController:53 - Request for overview of teacher with id 30 for view.
2019-10-12 17:56:23.774 -- INFO NewExamDateController:44 - Request for retrieving new exam date form view.
2019-10-12 17:56:23.774 -- INFO UserDaoCriteria:74 - User with username pedant found.
2019-10-12 17:56:23.789 -- INFO BaseTeacherService:92 - Getting list of taught subjects for teacher with id 30.
2019-10-12 17:57:16.090 -- INFO UserDaoCriteria:74 - User with username pedant found.
2019-10-12 17:57:16.106 -- INFO NewExamDateController:95 - Request from user with id 30 for saving new exam date with subject id 1, date 2019-10-15 10:00 and maximal number of participants 1.
2019-10-12 17:57:16.106 -- INFO BaseTeacherService:385 - Creating new examination term for subject with id 1, teacher with id 30, date 2019-10-15 10:00 and maximal number of participants 1.
2019-10-12 17:57:16.106 -- ERROR E01DateUtility:79 - INJECTED_ERROR: E01DateUtility_stringToDate_returns_Date_object_from_string_representation_given_in_method_parameter_+1_day
Overview of functional tests full log
Overview of acceptance tests full report