From 58897bfaa575b29a47971f35545b1cb03a71bf56 Mon Sep 17 00:00:00 2001 From: Gerard Downes Date: Wed, 18 May 2022 09:04:32 +0100 Subject: [PATCH] Capture and ignore exceptions in the CQLParser getOperationAndTableName method used by Cassandra 4.x to address https://github.com/newrelic/newrelic-java-agent/issues/827 --- .../instrumentation/cassandra/CQLParser.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/instrumentation/cassandra-datastax-4.0.0/src/main/java/com/nr/agent/instrumentation/cassandra/CQLParser.java b/instrumentation/cassandra-datastax-4.0.0/src/main/java/com/nr/agent/instrumentation/cassandra/CQLParser.java index 2368a38152..2ec0947ece 100644 --- a/instrumentation/cassandra-datastax-4.0.0/src/main/java/com/nr/agent/instrumentation/cassandra/CQLParser.java +++ b/instrumentation/cassandra-datastax-4.0.0/src/main/java/com/nr/agent/instrumentation/cassandra/CQLParser.java @@ -66,21 +66,25 @@ public class CQLParser { } public OperationAndTableName getOperationAndTableName(String rawQuery) { - rawQuery = rawQuery.replaceAll(COMMENT_PATTERN, "").trim(); + try { + rawQuery = rawQuery.replaceAll(COMMENT_PATTERN, "").trim(); - String operation = null; - String tableName = null; - for (Pattern pattern : PATTERNS) { - Matcher matcher = pattern.matcher(rawQuery); - if (matcher.find()) { - if (matcher.groupCount() >= 1) { - operation = matcher.group(1); + String operation = null; + String tableName = null; + for (Pattern pattern : PATTERNS) { + Matcher matcher = pattern.matcher(rawQuery); + if (matcher.find()) { + if (matcher.groupCount() >= 1) { + operation = matcher.group(1); + } + if (matcher.groupCount() == 2) { + tableName = matcher.group(2); + } + return new OperationAndTableName(operation, tableName); } - if (matcher.groupCount() == 2) { - tableName = matcher.group(2); - } - return new OperationAndTableName(operation, tableName); } + } catch (Exception ex) { + return null; } return null; }