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:
parent
7b61b2071e
commit
32fff9c725
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue