Detailed information about defect clone:
27-C1.H0.M0.L0_U_D_01.war
Nickname of the defect
wrong-select-from-DB
Brief desctiption
Select from DB "list of users" returns students only, table in List of All Teachers remains empty.
How to activate the defect
-
Click on Login in the header
-
Username
strict
, password pass
, click on Login button
-
Click on List of All Teachers
Visibility of the defect
Expected |
Actual |
|
|
Parts
StudentService |
TeacherService |
DateUtility |
GradeDAO |
UserDAO |
BaseStudentService
|
BaseTeacherService
|
BaseDateUtility
|
GradeTypeDaoCriteria
|
E01UserDao
|
URL to the defect source code
https://gitlab.kiv.zcu.cz/herout/TbUIS-UIS/blob/master/src/main/java/cz/zcu/kiv/matyasj/dp/dao/jpa/error/E01UserDao.java
Source code with the injected defect
/**
* DELIBERATE ERROR
*
* This error method returns just students instead of all users.
*
* @return List of all students
*/
@Override
@ErrorMethod(errorMessage = "This error method returns just students instead of all users.")
public List findAllUsers() {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery query = cb.createQuery(User.class);
Root root = query.from(User.class);
query.select(root);
List allUsers = entityManager.createQuery(query).getResultList();
List allUsersWithoutTeachers = new ArrayList<>();
for(User u : allUsers){
if(!(u instanceof Teacher)){
allUsersWithoutTeachers.add(u);
}
}
log.error(propertyLoader.getProperty("log.E01UserDao.findAllUsers"));
return allUsersWithoutTeachers;
}
URL to the correct source code
https://gitlab.kiv.zcu.cz/herout/TbUIS-UIS/blob/master/src/main/java/cz/zcu/kiv/matyasj/dp/dao/jpa/correct/UserDaoCriteria.java
Correct source code
/**
* Find all users from database and return them.
*
* @return List of all users
*/
@Override
public List findAllUsers() {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery query = cb.createQuery(User.class);
Root root = query.from(User.class);
query.select(root);
List users = entityManager.createQuery(query).getResultList();
log.info("Returning list of " + users.size() + " users.");
return users;
}
Logged information up to failure
2019-10-12 17:20:00.989 -- INFO LogHelper:31 - HHH000204: Processing PersistenceUnitInfo [name: cz.zcu.kiv.matyasj.dp]
2019-10-12 17:20:01.210 -- INFO Version:46 - HHH000412: Hibernate Core {5.4.1.Final}
2019-10-12 17:20:01.631 -- INFO Version:49 - HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2019-10-12 17:20:02.069 -- INFO C3P0ConnectionProvider:116 - HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/uis-web-db
2019-10-12 17:20:02.069 -- 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:20:02.069 -- INFO C3P0ConnectionProvider:120 - HHH10001003: Autocommit mode: false
2019-10-12 17:20:02.288 -- INFO C3P0ConnectionProvider:200 - HHH10001007: JDBC isolation level:
2019-10-12 17:20:02.678 -- INFO Dialect:158 - HHH000400: Using dialect: org.hibernate.dialect.MySQL55Dialect
2019-10-12 17:20:04.475 -- INFO access:47 - HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@4cf1ba4e] 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:20:06.647 -- INFO access:47 - HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@1f0b2ffb] 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:20:18.057 -- INFO JtaPlatformInitiator:52 - HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2019-10-12 17:20:18.322 -- INFO SecurityConfig:75 - SECURITY JDBC authentication process is running
2019-10-12 17:20:20.823 -- INFO SecurityConfig:93 - Authorization configuration process is running
2019-10-12 17:20:21.120 -- INFO BaseInitializer:97 - Initializing ...
2019-10-12 17:20:28.497 -- INFO BaseInitializer:463 - Initialized!
2019-10-12 17:20:28.622 -- INFO BaseInitializer:97 - Initializing ...
2019-10-12 17:20:56.761 -- INFO LoginController:30 - Request for login view
2019-10-12 17:21:05.148 -- INFO UserDaoCriteria:74 - User with username strict found.
2019-10-12 17:21:05.226 -- INFO SecurityConfig:121 - Success login - strict
2019-10-12 17:21:05.226 -- INFO SecurityConfig:125 - User login role: ROLE_TEACHER
2019-10-12 17:21:05.242 -- INFO UserDaoCriteria:74 - User with username strict found.
2019-10-12 17:21:05.257 -- INFO OverviewController:53 - Request for overview of teacher with id 32 for view.
2019-10-12 17:21:06.903 -- INFO ListOfAllTeachersController:39 - Request for retrieving list of all teachers view.
2019-10-12 17:21:06.903 -- INFO BaseTeacherService:680 - Getting all teachers.
2019-10-12 17:21:06.919 -- ERROR E01UserDao:60 - INJECTED_ERROR: E01UserDao_findAllUsers_returns_just_all_students_instead_of_all_users
Overview of functional tests full log
Overview of acceptance tests full report