Skip to content

Commit 0d76997

Browse files
committed
[chromecast] Do not cast the background discovery setting to String
The value comes back as a Boolean when the setting is written via REST, so @Modified throws ClassCastException, SCR swallows it and background discovery keeps running while the config reads as false. Accept either type, and make the field volatile since it is read from the discovery threads. Signed-off-by: Jason Hubbard <jasonahubbard@gmail.com>
1 parent bf60793 commit 0d76997

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/discovery/ChromecastDiscoveryParticipant.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class ChromecastDiscoveryParticipant implements MDNSDiscoveryParticipant
5454
private static final String PROPERTY_DEVICE_ID = "id";
5555
private static final String SERVICE_TYPE = "_googlecast._tcp.local.";
5656

57-
private boolean isAutoDiscoveryEnabled = true;
57+
private volatile boolean isAutoDiscoveryEnabled = true;
5858

5959
@Activate
6060
protected void activate(ComponentContext componentContext) {
@@ -68,10 +68,17 @@ protected void modified(ComponentContext componentContext) {
6868

6969
private void activateOrModifyService(ComponentContext componentContext) {
7070
Dictionary<String, @Nullable Object> properties = componentContext.getProperties();
71-
String autoDiscoveryPropertyValue = (String) properties
72-
.get(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY);
73-
if (autoDiscoveryPropertyValue != null && !autoDiscoveryPropertyValue.isBlank()) {
74-
isAutoDiscoveryEnabled = Boolean.valueOf(autoDiscoveryPropertyValue);
71+
Object autoDiscoveryPropertyValue = properties.get(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY);
72+
// Do not cast to String: the value arrives as a Boolean when the setting is written through
73+
// the REST API (or any JSON-typed config source), and a ClassCastException thrown out of
74+
// @Modified is swallowed by SCR - leaving background discovery silently still enabled.
75+
if (autoDiscoveryPropertyValue instanceof Boolean booleanValue) {
76+
isAutoDiscoveryEnabled = booleanValue;
77+
} else if (autoDiscoveryPropertyValue != null) {
78+
String value = autoDiscoveryPropertyValue.toString();
79+
if (!value.isBlank()) {
80+
isAutoDiscoveryEnabled = Boolean.parseBoolean(value);
81+
}
7582
}
7683
}
7784

0 commit comments

Comments
 (0)