This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/main by this push:
new 5d3ce9f7983 CXF-8184 - Use the thread default bus in
AbstractToolContainer.getBus() (#3590)
5d3ce9f7983 is described below
commit 5d3ce9f7983e3167fbaf300236b1fce9af51cd22
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Fri Oct 16 12:21:59 2026 +0100
CXF-8184 - Use the thread default bus in AbstractToolContainer.getBus()
(#3590)
---
.../common/toolspec/AbstractToolContainer.java | 7 +++---
.../common/toolspec/AbstractToolContainerTest.java | 26 ++++++++++++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git
a/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainer.java
b/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainer.java
index a91400a2475..9bbd131a227 100644
---
a/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainer.java
+++
b/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainer.java
@@ -186,12 +186,13 @@ public abstract class AbstractToolContainer implements
ToolContainer {
}
public Bus getBus() {
- Bus bus = BusFactory.getDefaultBus();
-
- OASISCatalogManager catalogManager =
bus.getExtension(OASISCatalogManager.class);
+ // Use the thread default bus rather than the global default bus, so
that concurrent
+ // invocations (e.g. a parallel Maven build) don't use a bus that
another thread may shut down
+ Bus bus = BusFactory.getThreadDefaultBus();
String catalogLocation = getCatalogURL();
if (!StringUtils.isEmpty(catalogLocation)) {
+ OASISCatalogManager catalogManager =
OASISCatalogManager.getCatalogManager(bus);
try {
catalogManager.loadCatalog(new URI(catalogLocation).toURL());
} catch (Exception e) {
diff --git
a/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainerTest.java
b/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainerTest.java
index 826f2409b89..f9d11e37bfa 100644
---
a/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainerTest.java
+++
b/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainerTest.java
@@ -19,6 +19,9 @@
package org.apache.cxf.tools.common.toolspec;
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.tools.common.ToolContext;
import org.apache.cxf.tools.common.ToolException;
import org.junit.Before;
@@ -26,6 +29,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
public class AbstractToolContainerTest {
private DummyToolContainer dummyTool;
@@ -66,4 +70,26 @@ public class AbstractToolContainerTest {
String[] args = {"-r", "wsdlurl=dfd"};
ToolRunner.runTool(DummyToolContainer.class,
getClass().getResourceAsStream(tsSource), false, args);
}
+
+ @Test
+ public void testGetBusUsesThreadDefaultBus() {
+ Bus originalDefault = BusFactory.getDefaultBus(false);
+ Bus originalThreadDefault = BusFactory.getThreadDefaultBus(false);
+ Bus globalBus = BusFactory.newInstance().createBus();
+ Bus threadBus = BusFactory.newInstance().createBus();
+ try {
+ BusFactory.setDefaultBus(globalBus);
+ BusFactory.setThreadDefaultBus(threadBus);
+ dummyTool.setContext(new ToolContext());
+
+ // Another thread (e.g. a parallel Maven module build) may shut
down the global default bus,
+ // so the tool must use the bus set up for the current thread
+ assertSame(threadBus, dummyTool.getBus());
+ } finally {
+ BusFactory.setThreadDefaultBus(originalThreadDefault);
+ BusFactory.setDefaultBus(originalDefault);
+ threadBus.shutdown(true);
+ globalBus.shutdown(true);
+ }
+ }
}