788 - Waiting list bookings are not auto promoted #788#401
788 - Waiting list bookings are not auto promoted #788#401mariusmarin-dev wants to merge 5 commits intomainfrom
Conversation
| // For Student events we only limit the number of students, other roles do not count against the capacity | ||
| Integer studentCount = roleCounts.getOrDefault(Role.STUDENT, 0); | ||
| return Math.max(0, numberOfPlaces - studentCount); | ||
| Integer placesAvailable = Math.max(0, numberOfPlaces - studentCount); |
Check warning
Code scanning / CodeQL
Boxed variable is never null Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 16 hours ago
In general, to fix a "boxed variable is never null" issue, you should change the variable’s type from the boxed type (e.g. Integer, Boolean) to the corresponding primitive type (int, boolean) when all assignments are from primitive expressions and there is no need to represent null. This improves clarity and avoids unnecessary boxing/unboxing.
Here, we keep the method return type as Integer because it legitimately may return null when numberOfPlaces is null. We only change the local variable placesAvailable in both branches from Integer to int, since its value is always derived from primitive arithmetic and is never null. This change is local, does not alter any method contracts, and does not require any additional imports or helper methods. Specifically:
- On line 953, change
Integer placesAvailabletoint placesAvailable. - On line 961, change
Integer placesAvailabletoint placesAvailable.
| @@ -950,7 +950,7 @@ | ||
| if (isStudentEvent) { | ||
| // For Student events we only limit the number of students, other roles do not count against the capacity | ||
| Integer studentCount = roleCounts.getOrDefault(Role.STUDENT, 0); | ||
| Integer placesAvailable = Math.max(0, numberOfPlaces - studentCount); | ||
| int placesAvailable = Math.max(0, numberOfPlaces - studentCount); | ||
|
|
||
| log.info("Event {} capacity: total={}, studentBooked={}, available={}, includeDeleted={}", | ||
| event.getId(), numberOfPlaces, studentCount, placesAvailable, includeDeletedUsersInCounts); | ||
| @@ -958,7 +958,7 @@ | ||
| } else { | ||
| // For other events, count all roles | ||
| Integer totalBooked = roleCounts.values().stream().reduce(0, Integer::sum); | ||
| Integer placesAvailable = Math.max(0, numberOfPlaces - totalBooked); | ||
| int placesAvailable = Math.max(0, numberOfPlaces - totalBooked); | ||
| log.info("Event {} capacity: total={}, totalBooked={}, available={}, includeDeleted={}", | ||
| event.getId(), numberOfPlaces, totalBooked, placesAvailable, includeDeletedUsersInCounts); | ||
|
|
| // For other events, count all roles | ||
| Integer totalBooked = roleCounts.values().stream().reduce(0, Integer::sum); | ||
| return Math.max(0, numberOfPlaces - totalBooked); | ||
| Integer placesAvailable = Math.max(0, numberOfPlaces - totalBooked); |
Check warning
Code scanning / CodeQL
Boxed variable is never null Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 16 hours ago
In general, when a local variable is only ever assigned primitive values and is never null, declare it with the corresponding primitive type instead of the boxed type. This avoids automatic boxing/unboxing and makes nullability intentions clear.
Here, we should change the type of the local variable placesAvailable in the non-student-event branch from Integer to int. The calculation Math.max(0, numberOfPlaces - totalBooked) already produces a primitive int; using int for placesAvailable removes an unnecessary boxing conversion when returning it as an Integer from the method (autoboxing will still occur at the return statement, which is appropriate because the method’s contract allows returning null in the numberOfPlaces == null case). This change is localized to a single line around 961 in src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/EventBookingManager.java and does not alter any logic or method signatures. No additional imports or methods are required.
| @@ -958,7 +958,7 @@ | ||
| } else { | ||
| // For other events, count all roles | ||
| Integer totalBooked = roleCounts.values().stream().reduce(0, Integer::sum); | ||
| Integer placesAvailable = Math.max(0, numberOfPlaces - totalBooked); | ||
| int placesAvailable = Math.max(0, numberOfPlaces - totalBooked); | ||
| log.info("Event {} capacity: total={}, totalBooked={}, available={}, includeDeleted={}", | ||
| event.getId(), numberOfPlaces, totalBooked, placesAvailable, includeDeletedUsersInCounts); | ||
|
|
Coverage Report
|
|



No description provided.