Fixed NPE and exceptiion while parsing config value (#2718)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
pull/2721/head
Christoph Weitkamp 2022-01-30 13:20:11 +01:00 committed by GitHub
parent 6193aa966e
commit 6edc413640
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -23,6 +23,7 @@ import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -47,6 +48,7 @@ import org.openhab.core.addon.marketplace.internal.community.model.DiscourseCate
import org.openhab.core.addon.marketplace.internal.community.model.DiscourseCategoryResponseDTO.DiscourseUser;
import org.openhab.core.addon.marketplace.internal.community.model.DiscourseTopicResponseDTO;
import org.openhab.core.addon.marketplace.internal.community.model.DiscourseTopicResponseDTO.DiscoursePostLink;
import org.openhab.core.config.core.ConfigParser;
import org.openhab.core.config.core.ConfigurableService;
import org.openhab.core.events.Event;
import org.openhab.core.events.EventPublisher;
@ -85,6 +87,7 @@ public class CommunityMarketplaceAddonService implements AddonService {
static final String CONFIG_URI = "system:marketplace";
static final String CONFIG_API_KEY = "apiKey";
static final String CONFIG_SHOW_UNPUBLISHED_ENTRIES_KEY = "showUnpublished";
private static final String CFG_REMOTE = "remote";
private static final String COMMUNITY_BASE_URL = "https://community.openhab.org";
private static final String COMMUNITY_MARKETPLACE_URL = COMMUNITY_BASE_URL + "/c/marketplace/69/l/latest";
@ -479,11 +482,12 @@ public class CommunityMarketplaceAddonService implements AddonService {
private boolean remoteEnabled() {
try {
Configuration configuration = configurationAdmin.getConfiguration("org.openhab.addons", null);
if (configuration.getProperties() != null) {
return (boolean) Objects.requireNonNullElse(configuration.getProperties().get("remote"), true);
} else {
Dictionary<String, Object> properties = configuration.getProperties();
if (properties == null) {
// if we can't determine a set property, we use true (default is remote enabled)
return true;
}
return ConfigParser.valueAsOrElse(properties.get(CFG_REMOTE), Boolean.class, true);
} catch (IOException e) {
return true;
}

View File

@ -21,6 +21,7 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -39,6 +40,7 @@ import org.openhab.core.addon.AddonType;
import org.openhab.core.addon.marketplace.MarketplaceAddonHandler;
import org.openhab.core.addon.marketplace.MarketplaceHandlerException;
import org.openhab.core.addon.marketplace.internal.json.model.AddonEntryDTO;
import org.openhab.core.config.core.ConfigParser;
import org.openhab.core.config.core.ConfigurableService;
import org.openhab.core.events.Event;
import org.openhab.core.events.EventPublisher;
@ -79,6 +81,7 @@ public class JsonAddonService implements AddonService {
private static final String CONFIG_URLS = "urls";
private static final String CONFIG_SHOW_UNSTABLE = "showUnstable";
private static final String CFG_REMOTE = "remote";
private static final Map<String, AddonType> TAG_ADDON_TYPE_MAP = Map.of( //
"automation", new AddonType("automation", "Automation"), //
@ -269,11 +272,12 @@ public class JsonAddonService implements AddonService {
private boolean remoteEnabled() {
try {
Configuration configuration = configurationAdmin.getConfiguration("org.openhab.addons", null);
if (configuration.getProperties() != null) {
return (boolean) Objects.requireNonNullElse(configuration.getProperties().get("remote"), true);
} else {
Dictionary<String, Object> properties = configuration.getProperties();
if (properties == null) {
// if we can't determine a set property, we use true (default is remote enabled)
return true;
}
return ConfigParser.valueAsOrElse(properties.get(CFG_REMOTE), Boolean.class, true);
} catch (IOException e) {
return true;
}