Skip to content

Commit c4d66ac

Browse files
committed
Add code to handle a possible uninitialized object
1 parent 8cebe44 commit c4d66ac

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/main/java/com/parallax/server/blocklyprop/services/impl/UserServiceImpl.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,25 @@ public void setConfiguration(Configuration configuration) {
5454

5555
@Override
5656
public User getUser(Long idUser) {
57-
return userDao.getUser(idUser).into(User.class);
57+
if (userDao != null) {
58+
return userDao.getUser(idUser).into(User.class);
59+
}
60+
else {
61+
LOG.error("UserDAO is not initialized before first use!");
62+
return null;
63+
}
64+
5865
}
5966

6067
@Override
6168
public List<UserRecord> getAllUsers() {
62-
return userDao.getAll();
69+
if (userDao != null) {
70+
return userDao.getAll();
71+
}
72+
else {
73+
LOG.error("UserDAO is not initialized before first use!");
74+
return null;
75+
}
6376
}
6477

6578
@Override
@@ -68,7 +81,12 @@ public String getUserScreenName(Long idUser) {
6881
String name = "";
6982

7083
try {
71-
name = userDao.getUser(idUser).getScreenname();
84+
if (userDao != null) {
85+
name = userDao.getUser(idUser).getScreenname();
86+
}
87+
else {
88+
LOG.error("UserDAO is not initialized before first use!");
89+
}
7290
}
7391
catch (NullPointerException ex) {
7492
LOG.error("Error retreiving name for userID: {}", idUser);

0 commit comments

Comments
 (0)