toString()-Aufruf in try/catch, damit eine nicht darstellbare SyslogMessage die Broker-Verbindung nicht trennt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
marwe
Marwe Saai 2026-11-23 18:25:56 +01:00
parent 8a9b9f9dba
commit b9a17a82af
1 changed files with 12 additions and 1 deletions

View File

@ -82,6 +82,17 @@ public class MqttAdapter {
void verarbeite(byte[] payload) {
SyslogDecoder.decode(payload)
.filter(SyslogDecoder::isRelevant)
.ifPresent(m -> ziel.accept(m.toString()));
.ifPresent(m -> {
String text;
try {
text = m.toString();
} catch (RuntimeException e) {
// z.B. host == null -> NullPointerException; ohne catch
// würde Paho die Broker-Verbindung trennen
System.err.println("SyslogMessage nicht darstellbar: " + e);
return;
}
ziel.accept(text);
});
}
}