Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
fix potential null pointer access in classic and basic UI (#5829)
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
  • Loading branch information
maggu2810 authored and sjsf committed Jul 2, 2018
1 parent 288b698 commit c22a665
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 31 deletions.
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.smarthome.core.library.items.NumberItem;
import org.eclipse.smarthome.core.library.types.QuantityType;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.StateDescription;
import org.eclipse.smarthome.core.types.StateOption;
import org.eclipse.smarthome.core.types.util.UnitUtils;
import org.eclipse.smarthome.model.sitemap.Mapping;
Expand Down Expand Up @@ -88,12 +89,15 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep

JsonObject jsonObject = new JsonObject();
StringBuilder rowSB = new StringBuilder();
if (selection.getMappings().size() == 0 && item != null && item.getStateDescription() != null) {
for (StateOption option : item.getStateDescription().getOptions()) {
jsonObject.addProperty(option.getValue(), option.getLabel());
rowMappingLabel = buildRow(selection, option.getLabel(), option.getValue(), item, state, rowSB);
if (rowMappingLabel != null) {
mappingLabel = rowMappingLabel;
if (selection.getMappings().size() == 0 && item != null) {
final StateDescription stateDescription = item.getStateDescription();
if (stateDescription != null) {
for (StateOption option : stateDescription.getOptions()) {
jsonObject.addProperty(option.getValue(), option.getLabel());
rowMappingLabel = buildRow(selection, option.getLabel(), option.getValue(), item, state, rowSB);
if (rowMappingLabel != null) {
mappingLabel = rowMappingLabel;
}
}
}
} else {
Expand Down
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.QuantityType;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.StateDescription;
import org.eclipse.smarthome.core.types.StateOption;
import org.eclipse.smarthome.core.types.util.UnitUtils;
import org.eclipse.smarthome.model.sitemap.Mapping;
Expand Down Expand Up @@ -86,13 +87,16 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep
snippetName = "rollerblind";
} else if (item instanceof GroupItem && ((GroupItem) item).getBaseItem() instanceof RollershutterItem) {
snippetName = "rollerblind";
} else if (item.getStateDescription() != null && item.getStateDescription().getOptions().size() > 0
&& item.getStateDescription().getOptions().size() <= MAX_BUTTONS) {
// Render with buttons only when a max of MAX_BUTTONS options are defined
snippetName = "buttons";
nbButtons = item.getStateDescription().getOptions().size();
} else {
snippetName = "switch";
final StateDescription stateDescription = item.getStateDescription();
final int optsSize = stateDescription == null ? -1 : stateDescription.getOptions().size();
if (optsSize > 0 && optsSize <= MAX_BUTTONS) {
// Render with buttons only when a max of MAX_BUTTONS options are defined
snippetName = "buttons";
nbButtons = optsSize;
} else {
snippetName = "switch";
}
}
} else {
snippetName = "buttons";
Expand Down Expand Up @@ -121,10 +125,15 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep
buildButton(s, mapping.getLabel(), mapping.getCmd(), -1, nbButtons > 1, item, state, buttons);
}
} else {
for (StateOption option : item.getStateDescription().getOptions()) {
// Truncate the button label to MAX_LABEL_SIZE characters
buildButton(s, option.getLabel(), option.getValue(), MAX_LABEL_SIZE, nbButtons > 1, item, state,
buttons);
if (item != null) {
final StateDescription stateDescription = item.getStateDescription();
if (stateDescription != null) {
for (StateOption option : stateDescription.getOptions()) {
// Truncate the button label to MAX_LABEL_SIZE characters
buildButton(s, option.getLabel(), option.getValue(), MAX_LABEL_SIZE, nbButtons > 1, item,
state, buttons);
}
}
}
}
snippet = StringUtils.replace(snippet, "%buttons%", buttons.toString());
Expand Down
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.smarthome.core.library.items.NumberItem;
import org.eclipse.smarthome.core.library.types.QuantityType;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.StateDescription;
import org.eclipse.smarthome.core.types.StateOption;
import org.eclipse.smarthome.core.types.util.UnitUtils;
import org.eclipse.smarthome.model.sitemap.Mapping;
Expand Down Expand Up @@ -71,11 +72,14 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep
}

StringBuilder rowSB = new StringBuilder();
if (selection.getMappings().size() == 0 && item != null && item.getStateDescription() != null) {
for (StateOption option : item.getStateDescription().getOptions()) {
rowMappedValue = buildRow(selection, option.getLabel(), option.getValue(), item, state, rowSB);
if (rowMappedValue != null) {
mappedValue = rowMappedValue;
if (selection.getMappings().size() == 0 && item != null) {
final StateDescription stateDescription = item.getStateDescription();
if (stateDescription != null) {
for (StateOption option : stateDescription.getOptions()) {
rowMappedValue = buildRow(selection, option.getLabel(), option.getValue(), item, state, rowSB);
if (rowMappedValue != null) {
mappedValue = rowMappedValue;
}
}
}
} else {
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.QuantityType;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.StateDescription;
import org.eclipse.smarthome.core.types.StateOption;
import org.eclipse.smarthome.core.types.util.UnitUtils;
import org.eclipse.smarthome.model.sitemap.Mapping;
Expand Down Expand Up @@ -72,13 +73,16 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep
snippetName = "rollerblind";
} else if (item instanceof GroupItem && ((GroupItem) item).getBaseItem() instanceof RollershutterItem) {
snippetName = "rollerblind";
} else if (item.getStateDescription() != null && item.getStateDescription().getOptions().size() > 0
&& item.getStateDescription().getOptions().size() <= MAX_BUTTONS) {
// Render with buttons only when a max of MAX_BUTTONS options are defined
snippetName = "buttons";
nbButtons = item.getStateDescription().getOptions().size();
} else {
snippetName = "switch";
final StateDescription stateDescription = item.getStateDescription();
final int optsSize = stateDescription == null ? -1 : stateDescription.getOptions().size();
if (optsSize > 0 && optsSize <= MAX_BUTTONS) {
// Render with buttons only when a max of MAX_BUTTONS options are defined
snippetName = "buttons";
nbButtons = optsSize;
} else {
snippetName = "switch";
}
}
} else {
snippetName = "buttons";
Expand Down Expand Up @@ -114,10 +118,15 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep
buildButton(s, mapping.getLabel(), mapping.getCmd(), -1, nbButtons > 1, item, state, buttons);
}
} else {
for (StateOption option : item.getStateDescription().getOptions()) {
// Truncate the button label to MAX_LABEL_SIZE characters
buildButton(s, option.getLabel(), option.getValue(), MAX_LABEL_SIZE, nbButtons > 1, item, state,
buttons);
if (item != null) {
final StateDescription stateDescription = item.getStateDescription();
if (stateDescription != null) {
for (StateOption option : stateDescription.getOptions()) {
// Truncate the button label to MAX_LABEL_SIZE characters
buildButton(s, option.getLabel(), option.getValue(), MAX_LABEL_SIZE, nbButtons > 1, item,
state, buttons);
}
}
}
}
snippet = StringUtils.replace(snippet, "%buttons%", buttons.toString());
Expand Down

0 comments on commit c22a665

Please sign in to comment.