Skip to content

Commit

Permalink
A null pointer exception caused by a set command without para. Fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefa authored and stefa committed Dec 2, 2021
1 parent 29cec90 commit b184ed8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/de/sgollmer/solvismax/Version.java
Expand Up @@ -15,7 +15,7 @@

public class Version {

private String serverVersion = "01.05.00";
private String serverVersion = "01.05.01-rc1";
private String appendix = "3 heating circuits beta";

public static Version getInstance() {
Expand Down
9 changes: 8 additions & 1 deletion src/de/sgollmer/solvismax/connection/CommandHandler.java
Expand Up @@ -429,6 +429,13 @@ private void set(final IReceivedData receivedDat) throws JsonException, TypeExce
}

SingleData<?> singleData = receivedDat.getSingleData();

if (singleData == null) {
logger.warn("Command set channel <" + description.getId()
+ "> without setting parameters received! Command ignored.");
return;
}

boolean ignored;
try {
ignored = solvis.setFromExternal(description, singleData);
Expand Down Expand Up @@ -575,7 +582,7 @@ public synchronized void abort() {
public void handleControlEnable(final Solvis solvis) {
boolean enable = true;
for (ClientAssignments client : this.clients) {

enable &= client.getControlEnableStatus(solvis) != ControlEnableStatus.FALSE;
}
solvis.controlEnable(enable);
Expand Down
Expand Up @@ -25,6 +25,7 @@ public class JsonPackage implements IReceivedData {
protected Command command;
protected Frame data;
private Solvis solvis = null;
private String receivedString = null;

public JsonPackage() {
}
Expand Down Expand Up @@ -75,9 +76,9 @@ void receive(final InputStream stream, final int timeout) throws IOException, Js
Helper.read(stream, receivedData, timeout);

Frame receivedFrame = new Frame();
String receivedString = new String(receivedData, CHARSET);
this.receivedString = new String(receivedData, CHARSET);
long timeStamp = System.currentTimeMillis();
receivedFrame.from(receivedString, 0, timeStamp);
receivedFrame.from(this.receivedString, 0, timeStamp);
if (receivedFrame.size() > 0) {
Element e = receivedFrame.get(0);
this.command = Command.valueOf(e.name);
Expand Down Expand Up @@ -122,4 +123,8 @@ public SingleData<?> getSingleData() {
public String getClientId() {
return null;
}

protected String getReceivedString() {
return this.receivedString;
}
}
9 changes: 9 additions & 0 deletions src/de/sgollmer/solvismax/connection/transfer/SetPackage.java
Expand Up @@ -8,9 +8,14 @@
package de.sgollmer.solvismax.connection.transfer;

import de.sgollmer.solvismax.connection.IReceivedData;
import de.sgollmer.solvismax.log.LogManager;
import de.sgollmer.solvismax.log.LogManager.ILogger;
import de.sgollmer.solvismax.model.objects.data.SingleData;

public class SetPackage extends JsonPackage implements IReceivedData {

private static final ILogger logger = LogManager.getInstance().getLogger(SetPackage.class);

SetPackage() {
this.command = Command.SET;
}
Expand All @@ -26,7 +31,11 @@ void finish() {
this.id = e.name;
if (e.value instanceof SingleValue) {
this.singleData = ((SingleValue) e.value).getData();
} else {
logger.warn("Data parameter can't be interpreted. Package: " + this.getReceivedString());
}
} else {
logger.warn("Data parameter is empty. Package: " + this.getReceivedString());
}
this.data = null;
}
Expand Down
Expand Up @@ -336,7 +336,7 @@ public boolean mustBackuped() {
// }
//
public SingleData<?> normalize(final SingleData<?> data) throws TypeException {
if (data.get() == null) {
if (data == null || data.get() == null) {
return null;
}
if (data instanceof IntegerValue && this.getDivisor() != 1) {
Expand Down

0 comments on commit b184ed8

Please sign in to comment.