Skip to content

Commit

Permalink
Avoid potentially creating CLs in LogCapturingOutputFilter
Browse files Browse the repository at this point in the history
And also avoid passing the CuratedApplication here.
The problem was noticed when trying to log something in the
QuarkusClassLoader constructor.

Related to quarkusio#41233
  • Loading branch information
gsmet committed Jun 25, 2024
1 parent d68e5f7 commit 664164f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public Runnable prepare() {
long start = System.currentTimeMillis();
ClassLoader old = Thread.currentThread().getContextClassLoader();
QuarkusClassLoader tcl = testApplication.createDeploymentClassLoader();
LogCapturingOutputFilter logHandler = new LogCapturingOutputFilter(testApplication, true, true,
LogCapturingOutputFilter logHandler = new LogCapturingOutputFilter(true, true,
TestSupport.instance().get()::isDisplayTestOutput);
Thread.currentThread().setContextClassLoader(tcl);
Consumer currentTestAppConsumer = (Consumer) tcl.loadClass(CurrentTestApplication.class.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@

import org.jboss.logging.Logger;

import io.quarkus.bootstrap.app.CuratedApplication;
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;

public class LogCapturingOutputFilter implements BiPredicate<String, Boolean> {
private static final Logger log = Logger.getLogger(LogCapturingOutputFilter.class);

private final CuratedApplication application;
private final List<String> logOutput = new ArrayList<>();
private final List<String> errorOutput = new ArrayList<>();
private final boolean mergeErrorStream;
private final boolean convertToHtml;
private final Supplier<Boolean> finalPredicate;

public LogCapturingOutputFilter(CuratedApplication application, boolean mergeErrorStream, boolean convertToHtml,
public LogCapturingOutputFilter(boolean mergeErrorStream, boolean convertToHtml,
Supplier<Boolean> finalPredicate) {
this.application = application;
this.mergeErrorStream = mergeErrorStream;
this.convertToHtml = convertToHtml;
this.finalPredicate = finalPredicate;
Expand All @@ -50,8 +48,8 @@ public boolean test(String logRecord, Boolean errorStream) {
return true;
}
while (cl.getParent() != null) {
if (cl == application.getAugmentClassLoader()
|| cl == application.getBaseRuntimeClassLoader()) {
if (cl instanceof QuarkusClassLoader
&& (((QuarkusClassLoader) cl).isAugmentation() || ((QuarkusClassLoader) cl).isBaseRuntime())) {
//TODO: for convenience we save the log records as HTML rather than ANSI here
synchronized (logOutput) {
if (convertToHtml) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void ensurePrepared(ExtensionContext extensionContext, Class<? extends Q
private LaunchResult doLaunch(ExtensionContext context, Class<? extends QuarkusTestProfile> selectedProfile,
String[] arguments) throws Exception {
ensurePrepared(context, selectedProfile);
LogCapturingOutputFilter filter = new LogCapturingOutputFilter(prepareResult.curatedApplication, false, false,
LogCapturingOutputFilter filter = new LogCapturingOutputFilter(false, false,
() -> true);
QuarkusConsole.addOutputFilter(filter);
try {
Expand Down

0 comments on commit 664164f

Please sign in to comment.