From b63a6047d3d57b31adf4ea37d45b48abc728b8ad Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 30 Jul 2013 14:42:08 -0700 Subject: [PATCH] WebSocket - better protection on metadata cache --- .../common/events/JettyAnnotatedImpl.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/JettyAnnotatedImpl.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/JettyAnnotatedImpl.java index b4e75768402..73377aaf890 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/JettyAnnotatedImpl.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/JettyAnnotatedImpl.java @@ -31,15 +31,17 @@ public class JettyAnnotatedImpl implements EventDriverImpl public EventDriver create(Object websocket, WebSocketPolicy policy) { Class websocketClass = websocket.getClass(); - JettyAnnotatedMetadata metadata = cache.get(websocketClass); - if (metadata == null) + synchronized (cache) { - JettyAnnotatedScanner scanner = new JettyAnnotatedScanner(); - metadata = scanner.scan(websocketClass); - cache.put(websocketClass,metadata); + JettyAnnotatedMetadata metadata = cache.get(websocketClass); + if (metadata == null) + { + JettyAnnotatedScanner scanner = new JettyAnnotatedScanner(); + metadata = scanner.scan(websocketClass); + cache.put(websocketClass,metadata); + } + return new JettyAnnotatedEventDriver(policy,websocket,metadata); } - - return new JettyAnnotatedEventDriver(policy,websocket,metadata); } @Override @@ -58,6 +60,6 @@ public class JettyAnnotatedImpl implements EventDriverImpl @Override public String toString() { - return String.format("{} [cache.count=%d]",this.getClass().getSimpleName(),cache.size()); + return String.format("%s [cache.count=%d]",this.getClass().getSimpleName(),cache.size()); } }