From 2b047ffdc750fd3b0726317153f69656c9fbbac7 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 2 Dec 2020 09:07:54 -0500 Subject: [PATCH] - fixes a bug where regex replacement on multithreading could cross wires --- .../graph/content/MSBatchRequestContent.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java b/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java index 85ae6347a..4b9fc0a9e 100644 --- a/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java +++ b/src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java @@ -29,7 +29,7 @@ public class MSBatchRequestContent { /* * Creates Batch request content using list provided - * + * * @param batchRequestStepsArray List of batch steps for batching */ public MSBatchRequestContent(final List batchRequestStepsArray) { @@ -50,7 +50,7 @@ public MSBatchRequestContent() { /* * @param batchRequestStep Batch request step adding to batch content - * + * * @return true or false based on addition or no addition of batch request step * given */ @@ -81,7 +81,7 @@ public String addBatchRequestStep(final Request request, final String... arrayOf /* * @param requestId Id of Batch request step to be removed - * + * * @return true or false based on removal or no removal of batch request step * with given id */ @@ -116,18 +116,13 @@ public String getBatchRequestContent() { } private static final Pattern protocolAndHostReplacementPattern = Pattern.compile("(?i)^http[s]?:\\/\\/graph\\.microsoft\\.com\\/(?>v1\\.0|beta)\\/?"); // (?i) case insensitive - private Matcher protocolAndHostReplacementMatcher; // not static to avoid multithreading issues as the object is mutable private JsonObject getBatchRequestObjectFromRequestStep(final MSBatchRequestStep batchRequestStep) { final JsonObject contentmap = new JsonObject(); contentmap.add("id", new JsonPrimitive(batchRequestStep.getRequestId())); - if(protocolAndHostReplacementMatcher == null) { - protocolAndHostReplacementMatcher = protocolAndHostReplacementPattern.matcher(batchRequestStep.getRequest().url().toString()); - } else { - protocolAndHostReplacementMatcher = protocolAndHostReplacementMatcher.reset(batchRequestStep.getRequest().url().toString()); - } + final Matcher protocolAndHostReplacementMatcher = protocolAndHostReplacementPattern.matcher(batchRequestStep.getRequest().url().toString()); - final String url = protocolAndHostReplacementMatcher.replaceAll(""); + final String url = protocolAndHostReplacementMatcher.replaceAll(""); contentmap.add("url", new JsonPrimitive(url)); contentmap.add("method", new JsonPrimitive(batchRequestStep.getRequest().method().toString())); @@ -186,5 +181,5 @@ private JsonObject requestBodyToJSONObject(final Request request) throws IOExcep else return requestBodyElement.getAsJsonObject(); } - + }