Skip to content

Commit 727e74d

Browse files
holly-cumminsgsmet
authored andcommitted
Only reinstate classloaders for the sources we replaced it on
1 parent fd4ac9a commit 727e74d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

integration-tests/main/src/test/java/io/quarkus/it/main/MethodSourceTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import jakarta.inject.Inject;
1010

11+
import org.eclipse.microprofile.config.ConfigProvider;
1112
import org.hamcrest.CoreMatchers;
1213
import org.hamcrest.Matcher;
1314
import org.junit.jupiter.params.ParameterizedTest;
@@ -28,6 +29,9 @@ public class MethodSourceTest {
2829
public void testParameterResolver(UnusedBean.DummyInput dummyInput, Matcher<String> matcher) {
2930
UnusedBean.DummyResult dummyResult = unusedBean.dummy(dummyInput);
3031
assertThat(dummyResult.getResult(), matcher);
32+
33+
// Can we get config?
34+
ConfigProvider.getConfig();
3135
}
3236

3337
private static Collection<Arguments> provideDummyInput() {

test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/ExecutionListener.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ public void executionStarted(TestIdentifier testIdentifier) {
2525
Optional<TestSource> oSource = testIdentifier.getSource();
2626
if (oSource.isPresent()) {
2727
TestSource source = oSource.get();
28-
if (source instanceof ClassSource) {
29-
ClassSource cs = (ClassSource) source;
28+
if (source instanceof ClassSource cs) {
3029
ClassLoader classLoader = cs.getJavaClass().getClassLoader();
3130
// Only adjust the TCCL in cases where we know the QuarkusTestExtension would be about to do it anyway
3231
// We could check annotations, but that would be slow, and the assumption that only Quarkus Tests are loaded with the quarkus classloader should be a fair one
3332
if (classLoader instanceof QuarkusClassLoader) {
34-
origCl = Thread.currentThread()
35-
.getContextClassLoader();
33+
origCl = Thread.currentThread().getContextClassLoader();
3634
Thread.currentThread().setContextClassLoader(classLoader);
3735
} else {
3836
origCl = null;
@@ -43,9 +41,15 @@ public void executionStarted(TestIdentifier testIdentifier) {
4341

4442
@Override
4543
public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult result) {
46-
if (origCl != null) {
47-
// If execution is parallel this could be odd, but if execution is parallel any kind of TCCL manipulation will be ill-fated
48-
Thread.currentThread().setContextClassLoader(origCl);
44+
Optional<TestSource> oSource = testIdentifier.getSource();
45+
if (oSource.isPresent()) {
46+
TestSource source = oSource.get();
47+
if (source instanceof ClassSource) {
48+
if (origCl != null) {
49+
// If execution is parallel this could produce odd results, but if execution is parallel any kind of TCCL manipulation will be ill-fated
50+
Thread.currentThread().setContextClassLoader(origCl);
51+
}
52+
}
4953
}
5054
}
5155
}

0 commit comments

Comments
 (0)