Skip to content

Commit 637aef8

Browse files
committed
Fix NullPointerException when using path variables and no APNonce/generator is provided (#519)
1 parent 89c2dd1 commit 637aef8

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

src/main/java/airsquared/blobsaver/app/Controller.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void clearEffectHandler(Event evt) {
104104

105105
@SuppressWarnings("unused")
106106
public void checkRequirements(ObservableValue<?> ignored, String ignored2, String identifier) {
107-
identifier = Utils.defaultIfNull(Devices.modelToIdentifier(identifier), identifier);
107+
identifier = Utils.defIfNull(Devices.modelToIdentifier(identifier), identifier);
108108
if (!Utils.isEmptyOrNull(identifier) && Devices.doesRequireBoardConfig(identifier)) {
109109
boardConfigField.setDisable(false);
110110
boardConfigField.setEffect(Utils.borderGlow);
@@ -125,7 +125,7 @@ public void checkRequirements(ObservableValue<?> ignored, String ignored2, Strin
125125
@SuppressWarnings("unused")
126126
public void deviceTypeChoiceBoxHandler() {
127127
deviceModelChoiceBox.setItems(Devices.getModelsForType(deviceTypeChoiceBox.getValue()));
128-
versionLabel.setText(Utils.defaultIfNull(Devices.getOSNameForType(deviceTypeChoiceBox.getValue()), "Version"));
128+
versionLabel.setText(Utils.defIfNull(Devices.getOSNameForType(deviceTypeChoiceBox.getValue()), "Version"));
129129
}
130130

131131
public void checkForUpdatesHandler() { Utils.checkForUpdates(true); }

src/main/java/airsquared/blobsaver/app/TSS.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ private String parsePath(String input) {
173173

174174
var variables = Map.of("${DeviceIdentifier}", deviceIdentifier,
175175
"${BoardConfig}", getBoardConfig(),
176-
"${APNonce}", apnonce,
177-
"${Generator}", generator,
176+
"${APNonce}", Utils.defIfNull(apnonce, "UnknownAPNonce"),
177+
"${Generator}", Utils.defIfNull(generator, "UnknownGenerator"),
178178
"${DeviceModel}", Devices.identifierToModel(deviceIdentifier),
179179
"${ECID}", ecid);
180180
for (Map.Entry<String, String> entry : variables.entrySet()) {
@@ -187,16 +187,11 @@ private String parsePathWithVersion(Utils.IOSVersion ios) {
187187
if (!savePath.contains("${")) return savePath;
188188
var template = savePath;
189189

190-
Map<String, String> variables;
191-
if (ios.versionString() != null) {
192-
variables = Map.of("${FullVersionString}", ios.versionString(),
193-
"${BuildID}", ios.buildid(),
194-
"${MajorVersion}", ios.versionString().replaceFirst("\\..*", ""));
195-
} else {
196-
variables = Map.of("${FullVersionString}", "UnknownVersion",
197-
"${BuildID}", "UnknownBuildID",
198-
"${MajorVersion}", "UnknownVersion");
199-
}
190+
var majorVersion = ios.versionString() != null ? ios.versionString().replaceFirst("\\..*", "") : "UnknownVersion";
191+
Map<String, String> variables = Map.of(
192+
"${FullVersionString}", Utils.defIfNull(ios.versionString(), "UnknownVersion"),
193+
"${BuildID}", Utils.defIfNull(ios.buildid(), "UnknownBuildID"),
194+
"${MajorVersion}", majorVersion);
200195
for (Map.Entry<String, String> entry : variables.entrySet()) {
201196
template = template.replace(entry.getKey(), entry.getValue());
202197
}
@@ -318,7 +313,7 @@ private ArrayList<String> constructArgs() {
318313
}
319314

320315
private String getBoardConfig() {
321-
return Utils.defaultIfNull(boardConfig, Devices.getBoardConfig(deviceIdentifier));
316+
return Utils.defIfNull(boardConfig, Devices.getBoardConfig(deviceIdentifier));
322317
}
323318

324319
private void parseTSSLog(String tsscheckerLog) throws TSSException {

src/main/java/airsquared/blobsaver/app/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ static boolean isEmptyOrNull(String s) {
444444
return s == null || s.isEmpty();
445445
}
446446

447-
static <T> T defaultIfNull(T object, T def) {
447+
static <T> T defIfNull(T object, T def) {
448448
return (object == null) ? def : object;
449449
}
450450

0 commit comments

Comments
 (0)