Skip to content

Commit c1b91ea

Browse files
authored
Merge pull request #283 from ErykKul/http_500_fix_concurrency_problem
HTTP 500 fix when having many requests in parallel
2 parents 8569f9f + 25e742c commit c1b91ea

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ mvn spotless:check
7777
- (none)
7878

7979
#### 🏹 BUG FIXES
80+
- Fix a thread safety issue in CopyElement (Shoutout to @ErykKul for #283!)
8081
- Make Service Provider XML parsing more secure and avoid XXEs (activate STaX2 security features)
8182
- Make Service Provider XML parsing thread-safe (use thread-local variants of XmlInputFactory)
8283
- Switch to Sonatype Central Portal to [replace sunset OSSRH](https://central.sonatype.org/pages/ossrh-eol/)

xoai-common/src/main/java/io/gdcc/xoai/xml/CopyElement.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.io.InputStream;
1515
import java.nio.charset.StandardCharsets;
1616
import java.util.Objects;
17-
import java.util.regex.Matcher;
1817
import java.util.regex.Pattern;
1918
import javax.xml.stream.XMLStreamException;
2019

@@ -66,10 +65,10 @@ public void write(XmlWriter writer) throws XmlWriteException {
6665
}
6766

6867
/**
69-
* A matcher, created only once, reusable to match the XML declaration with any attributes.
68+
* A pattern, created only once, reusable to match the XML declaration with any attributes.
7069
* Non-greedy, so we do not interfere with any XML processing instructions following.
7170
*/
72-
private static final Matcher xmlDeclaration = Pattern.compile("<\\?xml .*?\\?>").matcher("");
71+
private static final Pattern xmlDeclaration = Pattern.compile("<\\?xml .*?\\?>");
7372

7473
protected void writeXml(XmlWriter writer) throws IOException {
7574

@@ -109,7 +108,7 @@ protected void writeXml(XmlWriter writer) throws IOException {
109108

110109
String firstChars = new String(bytes, StandardCharsets.UTF_8);
111110
// match the start with the compiled regex and replace with nothing when matching.
112-
firstChars = xmlDeclaration.reset(firstChars).replaceFirst("");
111+
firstChars = xmlDeclaration.matcher(firstChars).replaceFirst("");
113112

114113
// write the chars to the output stream
115114
writer.getOutputStream().write(firstChars.getBytes(StandardCharsets.UTF_8));

0 commit comments

Comments
 (0)