788 - Waiting list bookings are not auto promoted #788#401
788 - Waiting list bookings are not auto promoted #788#401mariusmarin-dev wants to merge 3 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 4 days ago
In general, to fix this kind of issue you should declare local variables as primitive types (int, boolean, etc.) when they are never intended to hold null, even if the enclosing method returns a boxed type. Java will automatically box the primitive when returning it from a method with a boxed return type.
For this specific case in EventBookingManager.getPlacesAvailable, change the type of the local variables that are purely numeric counts/derived values and never assigned null from Integer to int. That includes placesAvailable, studentCount, and totalBooked. They are all initialized from non-null values (getOrDefault with a primitive default 0, stream reduce(0, Integer::sum), and Math.max(0, ...)), and only used in arithmetic and logging; Java will autobox them where an Object is needed (e.g. for the SLF4J logging call) and when returning from the method. This preserves existing functionality while eliminating unnecessary boxing/unboxing and aligning with the analysis warning.
Concretely:
- In the student-event branch, change
Integer studentCounttoint studentCountandInteger placesAvailabletoint placesAvailable. - In the non-student branch, change
Integer totalBookedtoint totalBookedandInteger placesAvailabletoint placesAvailable.
No new imports or methods are required.
| @@ -944,16 +944,16 @@ | ||
| // Calculate remaining capacity with a lower bound of zero (no negatives) | ||
| 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 studentCount = roleCounts.getOrDefault(Role.STUDENT, 0); | ||
| int placesAvailable = Math.max(0, numberOfPlaces - studentCount); | ||
|
|
||
| log.info("Event {} capacity: total={}, studentBooked={}, available={}, includeDeleted={}", | ||
| event.getId(), numberOfPlaces, studentCount, placesAvailable, includeDeletedUsersInCounts); | ||
| return placesAvailable; | ||
| } else { | ||
| // For other events, count all roles | ||
| Integer totalBooked = roleCounts.values().stream().reduce(0, Integer::sum); | ||
| Integer placesAvailable = Math.max(0, numberOfPlaces - totalBooked); | ||
| int totalBooked = roleCounts.values().stream().reduce(0, Integer::sum); | ||
| 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 4 days ago
In general, to fix this kind of issue you should use the primitive type (int, boolean, etc.) for variables that are never assigned null and are only involved in primitive operations. This avoids unnecessary boxing/unboxing and makes it clear that the value cannot be null.
In this specific case, both studentCount and placesAvailable in the student-event branch, and totalBooked and placesAvailable in the non-student branch, are always non-null and participate purely in arithmetic. They can be safely declared as int instead of Integer. The method return type remains Integer so callers are unaffected: when returning an int value, Java will autobox it to Integer. The early return null; remains as-is for the “no capacity” situation. No imports or additional methods are required; we only change the local variable declarations on lines 947–948 and 955–956 to use int rather than Integer.
Concretely:
- Change
Integer studentCount→int studentCount - Change
Integer placesAvailable(in the student branch) →int placesAvailable - Change
Integer totalBooked→int totalBooked - Change
Integer placesAvailable(in the non-student branch) →int placesAvailable
No other logic or logging needs to change, since log.info handles primitive and boxed numbers transparently via autoboxing/varargs.
| @@ -944,16 +944,16 @@ | ||
| // Calculate remaining capacity with a lower bound of zero (no negatives) | ||
| 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 studentCount = roleCounts.getOrDefault(Role.STUDENT, 0); | ||
| int placesAvailable = Math.max(0, numberOfPlaces - studentCount); | ||
|
|
||
| log.info("Event {} capacity: total={}, studentBooked={}, available={}, includeDeleted={}", | ||
| event.getId(), numberOfPlaces, studentCount, placesAvailable, includeDeletedUsersInCounts); | ||
| return placesAvailable; | ||
| } else { | ||
| // For other events, count all roles | ||
| Integer totalBooked = roleCounts.values().stream().reduce(0, Integer::sum); | ||
| Integer placesAvailable = Math.max(0, numberOfPlaces - totalBooked); | ||
| int totalBooked = roleCounts.values().stream().reduce(0, Integer::sum); | ||
| 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.