Skip to content

Commit 2b047ff

Browse files
committed
- fixes a bug where regex replacement on multithreading could cross wires
1 parent 9eb7fcb commit 2b047ff

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/main/java/com/microsoft/graph/content/MSBatchRequestContent.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class MSBatchRequestContent {
2929

3030
/*
3131
* Creates Batch request content using list provided
32-
*
32+
*
3333
* @param batchRequestStepsArray List of batch steps for batching
3434
*/
3535
public MSBatchRequestContent(final List<MSBatchRequestStep> batchRequestStepsArray) {
@@ -50,7 +50,7 @@ public MSBatchRequestContent() {
5050

5151
/*
5252
* @param batchRequestStep Batch request step adding to batch content
53-
*
53+
*
5454
* @return true or false based on addition or no addition of batch request step
5555
* given
5656
*/
@@ -81,7 +81,7 @@ public String addBatchRequestStep(final Request request, final String... arrayOf
8181

8282
/*
8383
* @param requestId Id of Batch request step to be removed
84-
*
84+
*
8585
* @return true or false based on removal or no removal of batch request step
8686
* with given id
8787
*/
@@ -116,18 +116,13 @@ public String getBatchRequestContent() {
116116
}
117117

118118
private static final Pattern protocolAndHostReplacementPattern = Pattern.compile("(?i)^http[s]?:\\/\\/graph\\.microsoft\\.com\\/(?>v1\\.0|beta)\\/?"); // (?i) case insensitive
119-
private Matcher protocolAndHostReplacementMatcher; // not static to avoid multithreading issues as the object is mutable
120119
private JsonObject getBatchRequestObjectFromRequestStep(final MSBatchRequestStep batchRequestStep) {
121120
final JsonObject contentmap = new JsonObject();
122121
contentmap.add("id", new JsonPrimitive(batchRequestStep.getRequestId()));
123122

124-
if(protocolAndHostReplacementMatcher == null) {
125-
protocolAndHostReplacementMatcher = protocolAndHostReplacementPattern.matcher(batchRequestStep.getRequest().url().toString());
126-
} else {
127-
protocolAndHostReplacementMatcher = protocolAndHostReplacementMatcher.reset(batchRequestStep.getRequest().url().toString());
128-
}
123+
final Matcher protocolAndHostReplacementMatcher = protocolAndHostReplacementPattern.matcher(batchRequestStep.getRequest().url().toString());
129124

130-
final String url = protocolAndHostReplacementMatcher.replaceAll("");
125+
final String url = protocolAndHostReplacementMatcher.replaceAll("");
131126
contentmap.add("url", new JsonPrimitive(url));
132127

133128
contentmap.add("method", new JsonPrimitive(batchRequestStep.getRequest().method().toString()));
@@ -186,5 +181,5 @@ private JsonObject requestBodyToJSONObject(final Request request) throws IOExcep
186181
else
187182
return requestBodyElement.getAsJsonObject();
188183
}
189-
184+
190185
}

0 commit comments

Comments
 (0)