Skip to content

Commit 32cd079

Browse files
committed
bug-fix: fixed runtime null pointer exception in the RoomDTO
1 parent 915a9e8 commit 32cd079

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/main/java/com/connect/dto/RoomDTO.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public RoomDTO(Room room) {
2020
this.roomId = room.getRoomId().toString();
2121
this.roomName = room.getRoomName();
2222
this.roomDescription = room.getRoomDescription();
23-
this.admin = room.getAdmin().getUsername();
23+
if (room.getAdmin() != null) {
24+
this.admin = room.getAdmin().getUsername();
25+
}
2426
}
2527
}

src/main/java/com/connect/service/RoomService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ public void init() {
3434
Optional<Room> room = roomRepository.findRoomByName(ROOM_NAME);
3535
if (room.isEmpty()) {
3636
// Have to create the first room.
37-
User admin = new User();
38-
admin.setUsername("ADITYA");
39-
admin.setUserRole(List.of(UserRole.ADMIN));
4037
Room generalRoom = new Room(
4138
ROOM_NAME,
4239
"A public space for all users to chat, ask questions, and share updates."

0 commit comments

Comments
 (0)