From e12e7a321f6031d91dce3b7dc8c388f31303267b Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 28 May 2024 15:18:45 +0200 Subject: [PATCH 1/3] Fix NPE when trying to resolve guards --- .../zilla/runtime/engine/internal/registry/EngineManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineManager.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineManager.java index 4d8da63eff..979ad86063 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineManager.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineManager.java @@ -430,7 +430,7 @@ private NameResolver( this.matchName = NamespaceAdapter.PATTERN_NAME.matcher(""); } - private long resolve( + private synchronized long resolve( String name) { long id = 0L; From bcc351bf4549dc47144b7ebd4e681c2ca3679979 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 29 May 2024 09:17:20 +0200 Subject: [PATCH 2/3] fix --- .../internal/registry/EngineManager.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineManager.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineManager.java index 979ad86063..6125256149 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineManager.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineManager.java @@ -421,31 +421,33 @@ private void unregister( private final class NameResolver { private final int namespaceId; - private final Matcher matchName; + private final ThreadLocal matchName; private NameResolver( int namespaceId) { this.namespaceId = namespaceId; - this.matchName = NamespaceAdapter.PATTERN_NAME.matcher(""); + this.matchName = new ThreadLocal<>(); } - private synchronized long resolve( + private long resolve( String name) { long id = 0L; - - if (name != null && matchName.reset(name).matches()) + if (name != null) { - String ns = matchName.group("namespace"); - String n = matchName.group("name"); + matchName.set(NamespaceAdapter.PATTERN_NAME.matcher(name)); + if (matchName.get().matches()) + { + String ns = matchName.get().group("namespace"); + String n = matchName.get().group("name"); - int nsid = ns != null ? supplyId.applyAsInt(ns) : namespaceId; - int nid = supplyId.applyAsInt(n); + int nsid = ns != null ? supplyId.applyAsInt(ns) : namespaceId; + int nid = supplyId.applyAsInt(n); - id = NamespacedId.id(nsid, nid); + id = NamespacedId.id(nsid, nid); + } } - return id; } From 9a319b0b45e367a7e6dd5e8683cde48c33089740 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 30 May 2024 10:14:18 +0200 Subject: [PATCH 3/3] fix --- .../internal/registry/EngineManager.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineManager.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineManager.java index 6125256149..425f9d5113 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineManager.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineManager.java @@ -427,26 +427,23 @@ private NameResolver( int namespaceId) { this.namespaceId = namespaceId; - this.matchName = new ThreadLocal<>(); + this.matchName = ThreadLocal.withInitial(() -> NamespaceAdapter.PATTERN_NAME.matcher("")); } private long resolve( String name) { long id = 0L; - if (name != null) + Matcher matchName = this.matchName.get(); + if (name != null && matchName.reset(name).matches()) { - matchName.set(NamespaceAdapter.PATTERN_NAME.matcher(name)); - if (matchName.get().matches()) - { - String ns = matchName.get().group("namespace"); - String n = matchName.get().group("name"); + String ns = matchName.group("namespace"); + String n = matchName.group("name"); - int nsid = ns != null ? supplyId.applyAsInt(ns) : namespaceId; - int nid = supplyId.applyAsInt(n); + int nsid = ns != null ? supplyId.applyAsInt(ns) : namespaceId; + int nid = supplyId.applyAsInt(n); - id = NamespacedId.id(nsid, nid); - } + id = NamespacedId.id(nsid, nid); } return id; }