Add null-safe ID handling in `GenreMapper` and fix minor logging format in `IPCManager`

- Ensure `GenreMapper` sets ID only if it's non-null and valid (> 0) to prevent potential NPEs.
- Adjust logging format in `IPCManager` for consistent indentation.
This commit is contained in:
Gustavo Henrique Santos Souza de Miranda 2025-11-29 02:50:07 -03:00
parent 7b61b2071e
commit 32fff9c725
2 changed files with 11 additions and 5 deletions

View File

@ -9,10 +9,16 @@ public class GenreMapper {
return null;
}
return GenreMessages.Genre.newBuilder()
.setId(entity.getId())
.setName(entity.getName())
.build();
GenreMessages.Genre.Builder builder = GenreMessages.Genre.newBuilder()
.setName(entity.getName());
// Only set ID when it's present and valid (> 0). Avoids NPE for null IDs.
Integer id = entity.getId();
if (id != null && id > 0) {
builder.setId(id);
}
return builder.build();
}
public static Genre toEntity(GenreMessages.Genre protobuf) {
if (protobuf == null) {

View File

@ -125,7 +125,7 @@ public class IPCManager {
}
logger.info("Closing IPC connection...");
logger.info("Closing IPC connection...");
running.set(false);
if (serverChannel != null && serverChannel.isOpen()) {