fix NPE in APS plugins

This commit is contained in:
Milos Kozak 2019-08-31 10:09:53 +02:00
parent 5d9277abdb
commit e732c31043
6 changed files with 80 additions and 42 deletions

View file

@ -18,6 +18,8 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import javax.annotation.Nullable;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -60,6 +62,7 @@ public class DetermineBasalAdapterAMAJS {
mScriptReader = scriptReader;
}
@Nullable
public DetermineBasalResultAMA invoke() {
if (L.isEnabled(L.APS)) {

View file

@ -29,6 +29,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.HardLimits;
import info.nightscout.androidaps.utils.Profiler;
import info.nightscout.androidaps.utils.Round;
@ -193,7 +194,8 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
isTempTarget
);
} catch (JSONException e) {
log.error("Unable to set data: " + e.toString());
FabricPrivacy.logException(e);
return;
}
@ -201,6 +203,13 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
if (L.isEnabled(L.APS))
Profiler.log(log, "AMA calculation", start);
// Fix bug determine basal
if (determineBasalResultAMA == null) {
if (L.isEnabled(L.APS))
log.error("SMB calculation returned null");
lastDetermineBasalAdapterAMAJS = null;
lastAPSResult = null;
lastAPSRun = 0;
} else {
if (determineBasalResultAMA.rate == 0d && determineBasalResultAMA.duration == 0 && !TreatmentsPlugin.getPlugin().isTempBasalInProgress())
determineBasalResultAMA.tempBasalRequested = false;
@ -217,6 +226,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
lastDetermineBasalAdapterAMAJS = determineBasalAdapterAMAJS;
lastAPSResult = determineBasalResultAMA;
lastAPSRun = now;
}
RxBus.INSTANCE.send(new EventOpenAPSUpdateGui());
//deviceStatus.suggested = determineBasalResultAMA.json;

View file

@ -16,6 +16,8 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import javax.annotation.Nullable;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
@ -48,6 +50,7 @@ public class DetermineBasalAdapterMAJS {
mScriptReader = scriptReader;
}
@Nullable
public DetermineBasalResultMA invoke() {
DetermineBasalResultMA determineBasalResultMA = null;

View file

@ -26,6 +26,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.HardLimits;
import info.nightscout.androidaps.utils.Profiler;
import info.nightscout.androidaps.utils.Round;
@ -170,7 +171,8 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
try {
determineBasalAdapterMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate(), iobTotal, glucoseStatus, mealData);
} catch (JSONException e) {
log.error("Unhandled exception", e);
FabricPrivacy.logException(e);
return;
}
if (L.isEnabled(L.APS))
Profiler.log(log, "MA calculation", start);
@ -179,6 +181,13 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
long now = System.currentTimeMillis();
DetermineBasalResultMA determineBasalResultMA = determineBasalAdapterMAJS.invoke();
if (determineBasalResultMA == null) {
if (L.isEnabled(L.APS))
log.error("MA calculation returned null");
lastDetermineBasalAdapterMAJS = null;
lastAPSResult = null;
lastAPSRun = 0;
} else {
// Fix bug determinef basal
if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !TreatmentsPlugin.getPlugin().isTempBasalInProgress())
determineBasalResultMA.tempBasalRequested = false;
@ -194,6 +203,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS;
lastAPSResult = determineBasalResultMA;
lastAPSRun = now;
}
RxBus.INSTANCE.send(new EventOpenAPSUpdateGui());
}

View file

@ -18,6 +18,8 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import javax.annotation.Nullable;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -69,6 +71,7 @@ public class DetermineBasalAdapterSMBJS {
}
@Nullable
public DetermineBasalResultSMB invoke() {

View file

@ -32,6 +32,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.HardLimits;
import info.nightscout.androidaps.utils.Profiler;
import info.nightscout.androidaps.utils.Round;
@ -219,7 +220,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
advancedFiltering.value()
);
} catch (JSONException e) {
log.error(e.getMessage());
FabricPrivacy.logException(e);
return;
}
@ -228,6 +229,13 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke();
if (L.isEnabled(L.APS))
Profiler.log(log, "SMB calculation", start);
if (determineBasalResultSMB == null) {
if (L.isEnabled(L.APS))
log.error("SMB calculation returned null");
lastDetermineBasalAdapterSMBJS = null;
lastAPSResult = null;
lastAPSRun = 0;
} else {
// TODO still needed with oref1?
// Fix bug determine basal
if (determineBasalResultSMB.rate == 0d && determineBasalResultSMB.duration == 0 && !TreatmentsPlugin.getPlugin().isTempBasalInProgress())
@ -246,6 +254,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
lastDetermineBasalAdapterSMBJS = determineBasalAdapterSMBJS;
lastAPSResult = determineBasalResultSMB;
lastAPSRun = now;
}
RxBus.INSTANCE.send(new EventOpenAPSUpdateGui());
//deviceStatus.suggested = determineBasalResultAMA.json;