Skip to content

788 - Waiting list bookings are not auto promoted #788#401

Open
mariusmarin-dev wants to merge 5 commits intomainfrom
788_auto_promotion
Open

788 - Waiting list bookings are not auto promoted #788#401
mariusmarin-dev wants to merge 5 commits intomainfrom
788_auto_promotion

Conversation

@mariusmarin-dev
Copy link

No description provided.

// 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

The variable 'placesAvailable' is only assigned values of primitive type and is never 'null', but it is declared with the boxed type 'Integer'.

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 placesAvailable to int placesAvailable.
  • On line 961, change Integer placesAvailable to int placesAvailable.
Suggested changeset 1
src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/EventBookingManager.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/EventBookingManager.java b/src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/EventBookingManager.java
--- a/src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/EventBookingManager.java
+++ b/src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/EventBookingManager.java
@@ -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);
 
EOF
@@ -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);

Copilot is powered by AI and may make mistakes. Always verify output.
// 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

The variable 'placesAvailable' is only assigned values of primitive type and is never 'null', but it is declared with the boxed type 'Integer'.

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.

Suggested changeset 1
src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/EventBookingManager.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/EventBookingManager.java b/src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/EventBookingManager.java
--- a/src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/EventBookingManager.java
+++ b/src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/EventBookingManager.java
@@ -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);
 
EOF
@@ -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);

Copilot is powered by AI and may make mistakes. Always verify output.
@github-actions
Copy link

Coverage Report

Overall Project 31.46%
Files changed 96.24%

File Coverage
EventBookingManager.java 65.58% -0.07%
EventBookingPersistenceManager.java 62.87% -1.1%
PgEventBookings.java 54.32%

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments