From 3ea26b1f07e7c2c7a9cbd1008e64da6610d3ab32 Mon Sep 17 00:00:00 2001 From: dernasherbrezon Date: Sat, 20 Jan 2024 19:14:05 +0000 Subject: [PATCH] fix some npe --- src/main/java/ru/r2cloud/device/SdrServerDevice.java | 7 ++++++- src/main/java/ru/r2cloud/model/Transmitter.java | 11 +++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/r2cloud/device/SdrServerDevice.java b/src/main/java/ru/r2cloud/device/SdrServerDevice.java index 5cc32273..e4ee1e12 100644 --- a/src/main/java/ru/r2cloud/device/SdrServerDevice.java +++ b/src/main/java/ru/r2cloud/device/SdrServerDevice.java @@ -63,6 +63,9 @@ public void reCalculateFrequencyBands(List scheduledTransmitters) { List bandwidths = new ArrayList<>(); for (Transmitter curTransmitter : scheduledTransmitters) { + if (curTransmitter.getBaudRates().isEmpty()) { + continue; + } Integer maxBaudRate = Collections.max(curTransmitter.getBaudRates()); if (maxBaudRate == null) { continue; @@ -96,7 +99,9 @@ public void reCalculateFrequencyBands(List scheduledTransmitters) { } currentBandTransmitters.add(cur.getTransmitter()); } - transmittersPerBand.put(currentBand, currentBandTransmitters); + if (currentBand != null) { + transmittersPerBand.put(currentBand, currentBandTransmitters); + } LOG.info("[{}] active bands are:", id); for (Entry> cur : transmittersPerBand.entrySet()) { LOG.info(" {} - {}", cur.getKey().getLower(), cur.getKey().getUpper()); diff --git a/src/main/java/ru/r2cloud/model/Transmitter.java b/src/main/java/ru/r2cloud/model/Transmitter.java index 582e2038..f2a86ecd 100644 --- a/src/main/java/ru/r2cloud/model/Transmitter.java +++ b/src/main/java/ru/r2cloud/model/Transmitter.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Base64; +import java.util.Collections; import java.util.Date; import java.util.List; @@ -91,19 +92,19 @@ public Transmitter(Transmitter copy) { this.updated = new Date(copy.updated.getTime()); } } - + public int getPriorityIndex() { return priorityIndex; } - + public void setPriorityIndex(int priorityIndex) { this.priorityIndex = priorityIndex; } - + public long getFrequencyBand() { return frequencyBand; } - + public void setFrequencyBand(long frequencyBand) { this.frequencyBand = frequencyBand; } @@ -369,6 +370,8 @@ public static Transmitter fromJson(JsonObject asObject) { bauds.add(baudRatesArray.get(i).asInt()); } result.setBaudRates(bauds); + } else { + result.setBaudRates(Collections.emptyList()); } JsonValue modulation = asObject.get("modulation"); if (modulation != null) {