From 99b1436fbfb8c367808a9260d18e845c997b68fc Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 5 Jul 2024 08:49:09 -0700 Subject: Clear attribute on null result --- .../org/traccar/handler/ComputedAttributesHandler.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java index d286866a5..b7d7a5ed5 100644 --- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java +++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java @@ -146,14 +146,9 @@ public class ComputedAttributesHandler extends BasePositionHandler { .collect(Collectors.toUnmodifiableList()); for (Attribute attribute : attributes) { if (attribute.getAttribute() != null) { - Object result = null; try { - result = computeAttribute(attribute, position); - } catch (JexlException error) { - LOGGER.warn("Attribute computation error", error); - } - if (result != null) { - try { + Object result = computeAttribute(attribute, position); + if (result != null) { switch (attribute.getAttribute()) { case "valid": position.setValid((Boolean) result); @@ -194,9 +189,13 @@ public class ComputedAttributesHandler extends BasePositionHandler { } break; } - } catch (ClassCastException error) { - LOGGER.warn("Attribute cast error", error); + } else { + position.getAttributes().remove(attribute.getAttribute()); } + } catch (JexlException error) { + LOGGER.warn("Attribute computation error", error); + } catch (ClassCastException error) { + LOGGER.warn("Attribute cast error", error); } } } -- cgit v1.2.3