Skip to content

Commit 7348bfe

Browse files
gnodetclaude
andauthored
Fix intermittent ArrayIndexOutOfBoundsException during stderr processing (#303)
* Fix intermittent ArrayIndexOutOfBoundsException during stderr processing The same StreamConsumer instance was shared between the stdout and stderr StreamPumper threads in CommandLineUtils.executeCommandLine(). Since StreamConsumer has non-thread-safe mutable state (StringBuilder, File, int fields), concurrent access from both threads caused ArrayIndexOutOfBoundsException inside StringBuilder's System.arraycopy. Use separate StreamConsumer instances for stdout and stderr to eliminate the race condition. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Use synchronized on shared StreamConsumer instead of separate instances Address review feedback: use a single shared StreamConsumer with synchronized consumeLine() to protect both the consumer's internal state and the buildContext writes from concurrent access by the stdout and stderr StreamPumper threads. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0e0410c commit 7348bfe

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractXSDToJavaMojo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,8 @@ private int runForked(XsdOption option, String outputDir) throws Exception {
553553
int linenum;
554554
int column;
555555
StringBuilder message = new StringBuilder();
556-
557-
public void consumeLine(String line) {
556+
557+
public synchronized void consumeLine(String line) {
558558
if (getLog().isDebugEnabled()) {
559559
getLog().debug(line);
560560
}
@@ -593,7 +593,7 @@ public void consumeLine(String line) {
593593
getLog().debug(e);
594594
throw new MojoExecutionException(e.getMessage(), e);
595595
}
596-
596+
597597

598598
String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
599599

@@ -609,5 +609,5 @@ public void consumeLine(String line) {
609609
file.delete();
610610
return 0;
611611
}
612-
612+
613613
}

0 commit comments

Comments
 (0)