Fix a possible NullPointerException

This commit is contained in:
Quentin Legot 2023-03-24 10:56:05 +01:00
parent e7b9f75035
commit 8d50ce6725

View File

@ -30,11 +30,11 @@ public class ProportionalFair extends Scheduler {
avg = avg / (bandwidthTable.length * bandwidthTable[0].length); avg = avg / (bandwidthTable.length * bandwidthTable[0].length);
averageBandwiths.add(avg); averageBandwiths.add(avg);
} }
User selectedUser = null; User selectedUser;
for(int ts = 0; ts < 2; ts++){ for(int ts = 0; ts < 2; ts++){
for(int sp = 0; sp < 100; sp++){ for(int sp = 0; sp < 100; sp++){
selectedUser = selectionUtilisateur(ts, sp, users, averageBandwiths); selectedUser = selectionUtilisateur(ts, sp, users, averageBandwiths);
if (selectedUser.getPacketsToSend().size() != 0) { if (selectedUser != null && !selectedUser.getPacketsToSend().isEmpty()) {
selectedUser.getPacketsSent().add(selectedUser.getPacketsToSend().get(0)); selectedUser.getPacketsSent().add(selectedUser.getPacketsToSend().get(0));
selectedUser.getPacketsToSend().remove(selectedUser.getPacketsToSend().get(0)); selectedUser.getPacketsToSend().remove(selectedUser.getPacketsToSend().get(0));
frame[ts][sp].setUser(selectedUser); frame[ts][sp].setUser(selectedUser);