Source:
<code>public void handleEvent(JsonObject json) { int zone = 0; JsonObject param = json.get("params").getAsJsonArray().get(0).getAsJsonObject(); if (param.has("output")) { String output_str = param.get("output").getAsString(); Pattern pattern = Pattern.compile(".*zone=(\\d+)"); <START> Matcher m = pattern.matcher(output_str); <END> if (m.matches()) { zone = Integer.parseInt(m.group(1)); } } if (json.get("method").getAsString().equalsIgnoreCase("notifyPlayingContentInfo")) { String uri = param.get("uri").getAsString(); if (param.has("broadcastFreq")) { int freq = param.get("broadcastFreq").getAsInt(); listener.updateBroadcastFreq(freq); checkRadioPreset(uri); } listener.updateInputSource(zone, uri); listener.updateSeekStation(""); } if (json.get("method").getAsString().equalsIgnoreCase("notifyVolumeInformation")) { int volume = param.get("volume").getAsInt(); volume = Math.round(100 * (volume - min_volume) / (max_volume - min_volume)); listener.updateVolume(zone, volume); String mute = param.get("mute").getAsString(); listener.updateMute(zone, mute.equalsIgnoreCase("on")); } if (json.get("method").getAsString().equalsIgnoreCase("notifyPowerStatus")) { String power = param.get("status").getAsString(); listener.updatePowerStatus(zone, power.equalsIgnoreCase("active")); } listener.updateConnectionState(true); }</code><technical_language>Wow, a LOT of potential for NPEs (and in following)..</technical_language>

Target:
public void handleEvent(JsonObject json) { int zone = 0; JsonObject param; try { param = json.getAsJsonArray("params").get(0).getAsJsonObject(); } catch (NullPointerException e) { logger.debug("Invalid json in handleEvent"); return; } catch (IndexOutOfBoundsException e) { logger.debug("Invalid json in handleEvent"); return; } if (param == null) { logger.debug("Unable to get params form json in handleEvent"); return; } if (param.has("output")) { String outputStr = param.get("output").getAsString(); Pattern pattern = Pattern.compile(".*zone=(\\d+)"); Matcher m = pattern.matcher(outputStr); if (m.matches()) { try { zone = Integer.parseInt(m.group(1)); } catch (NumberFormatException e) { logger.error("This should never happen, pattern should only match integers"); return; } } } if (json.get("method").getAsString().equalsIgnoreCase("notifyPlayingContentInfo")) { SonyAudioInput input = new SonyAudioInput(); ; input.input = param.get("uri").getAsString(); if (param.has("broadcastFreq")) { int freq = param.get("broadcastFreq").getAsInt(); input.radio_freq = Optional.of(freq); checkRadioPreset(input.input); } listener.updateInput(zone, input); listener.updateSeekStation(""); } if (json.get("method").getAsString().equalsIgnoreCase("notifyVolumeInformation")) { SonyAudioVolume volume = new SonyAudioVolume(); int rawVolume = param.get("volume").getAsInt(); volume.volume = Math.round(100 * (rawVolume - min_volume) / (max_volume - min_volume)); volume.mute = param.get("mute").getAsString().equalsIgnoreCase("on"); listener.updateVolume(zone, volume); } if (json.get("method").getAsString().equalsIgnoreCase("notifyPowerStatus")) { String power = param.get("status").getAsString(); listener.updatePowerStatus(zone, power.equalsIgnoreCase("active")); } listener.updateConnectionState(true); }