From a192f0c84df1a55c13a2ee3560174f661744e5e0 Mon Sep 17 00:00:00 2001 From: dhaval24 Date: Mon, 29 Jan 2018 14:46:09 -0800 Subject: [PATCH 1/3] Fix null ref check in TelemetryCorrelationUtils --- .../TelemetryCorrelationUtils.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/web/src/main/java/com/microsoft/applicationinsights/web/internal/correlation/TelemetryCorrelationUtils.java b/web/src/main/java/com/microsoft/applicationinsights/web/internal/correlation/TelemetryCorrelationUtils.java index f38b09d67f4..16642999b1c 100644 --- a/web/src/main/java/com/microsoft/applicationinsights/web/internal/correlation/TelemetryCorrelationUtils.java +++ b/web/src/main/java/com/microsoft/applicationinsights/web/internal/correlation/TelemetryCorrelationUtils.java @@ -111,7 +111,15 @@ public static void resolveCorrelation(HttpServletRequest request, HttpServletRes public static String generateChildDependencyId() { try { + RequestTelemetryContext context = ThreadContext.getRequestTelemetryContext(); + + //check if context is null - no correlation will happen + if (context == null) { + InternalLogger.INSTANCE.warn("No Correlation will happen, Thread context is null while generating child dependency"); + return ""; + } + RequestTelemetry requestTelemetry = context.getHttpRequestTelemetry(); String parentId = requestTelemetry.getContext().getOperation().getParentId(); @@ -137,6 +145,13 @@ public static String generateChildDependencyId() { * @return The correlation context as a string. */ public static String retrieveCorrelationContext() { + + //check if context is null - no correlation will happen + if (ThreadContext.getRequestTelemetryContext() == null) { + InternalLogger.INSTANCE.error("No correlation wil happen, Thread context is null"); + return ""; + } + CorrelationContext context = ThreadContext.getRequestTelemetryContext().getCorrelationContext(); return context.toString(); } @@ -256,6 +271,13 @@ private static void resolveCorrelationContext(HttpServletRequest request, Reques return; } + //check if context is null - no correlation will happen + if (ThreadContext.getRequestTelemetryContext() == null) { + InternalLogger.INSTANCE.error("No correlation will happen " + + "Thread context is null while resolving Correlation Context"); + return; + } + CorrelationContext currentCorrelationContext = ThreadContext.getRequestTelemetryContext().getCorrelationContext(); From cea2ec53632fe842db11df253045040138040d8e Mon Sep 17 00:00:00 2001 From: dhaval24 Date: Mon, 29 Jan 2018 14:49:12 -0800 Subject: [PATCH 2/3] Modifying log level to warning --- .../web/internal/correlation/TelemetryCorrelationUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/main/java/com/microsoft/applicationinsights/web/internal/correlation/TelemetryCorrelationUtils.java b/web/src/main/java/com/microsoft/applicationinsights/web/internal/correlation/TelemetryCorrelationUtils.java index 16642999b1c..1aa08853d08 100644 --- a/web/src/main/java/com/microsoft/applicationinsights/web/internal/correlation/TelemetryCorrelationUtils.java +++ b/web/src/main/java/com/microsoft/applicationinsights/web/internal/correlation/TelemetryCorrelationUtils.java @@ -148,7 +148,7 @@ public static String retrieveCorrelationContext() { //check if context is null - no correlation will happen if (ThreadContext.getRequestTelemetryContext() == null) { - InternalLogger.INSTANCE.error("No correlation wil happen, Thread context is null"); + InternalLogger.INSTANCE.warn("No correlation wil happen, Thread context is null"); return ""; } @@ -273,7 +273,7 @@ private static void resolveCorrelationContext(HttpServletRequest request, Reques //check if context is null - no correlation will happen if (ThreadContext.getRequestTelemetryContext() == null) { - InternalLogger.INSTANCE.error("No correlation will happen " + + InternalLogger.INSTANCE.warn("No correlation will happen " + "Thread context is null while resolving Correlation Context"); return; } From 3486d4b7c53acde00c4bc184b71b87c0fe5afcd1 Mon Sep 17 00:00:00 2001 From: dhaval24 Date: Mon, 29 Jan 2018 14:55:18 -0800 Subject: [PATCH 3/3] Updating Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aba3848175d..d8793bc3744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## Version 2.0.0 + +- Fix #506 Null Reference Check causing Null Pointer Exception in `TelemetryCorrelationUtils.java` + ## Version 2.0.0-BETA - Updating various dependencies to latest version - Introducing public class CustomClassWriter in Agent to enable finding common super classes used for Agent instrumentation without loading it