Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix infinite recursion in server dump with Path #10685

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@

import java.io.IOException;
import java.lang.reflect.Array;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;

import org.eclipse.jetty.util.StringUtil;
Expand Down Expand Up @@ -155,7 +157,8 @@ static void dumpObjects(Appendable out, String indent, Object object, Object...
{
dumpContainer(out, indent, (Container)object, extras == 0);
}
if (object instanceof Iterable)
// Dump an Iterable Path because it may contain itself.
if (object instanceof Iterable && !(object instanceof Path))
{
dumpIterable(out, indent, (Iterable<?>)object, extras == 0);
}
Expand Down Expand Up @@ -231,12 +234,15 @@ else if (containerLifeCycle != null && containerLifeCycle.isUnmanaged(bean))
}
}
}

static void dumpIterable(Appendable out, String indent, Iterable<?> iterable, boolean last) throws IOException
{
for (Iterator i = iterable.iterator(); i.hasNext(); )
{
Object item = i.next();
// Safety net to stop iteration when an Iterable contains itself e.g. Path.
if (Objects.equals(item, iterable))
return;
String nextIndent = indent + ((i.hasNext() || !last) ? "| " : " ");
out.append(indent).append("+: ");
if (item instanceof Dumpable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,48 @@ public void testStaticContent(String env) throws Exception
}
}
}

@ParameterizedTest
@MethodSource("provideEnvironmentsToTest")
public void testJettyDemo(String env) throws Exception
{
Path jettyBase = newTestJettyBaseDirectory();
String jettyVersion = System.getProperty("jettyVersion");
JettyHomeTester distribution = JettyHomeTester.Builder.newInstance()
.jettyVersion(jettyVersion)
.jettyBase(jettyBase)
.build();

int httpPort = distribution.freePort();
int sslPort = distribution.freePort();

String[] argsConfig = {
"--add-modules=http," + toEnvironment("demos", env)
};

try (JettyHomeTester.Run runConfig = distribution.start(argsConfig))
{
assertTrue(runConfig.awaitFor(START_TIMEOUT, TimeUnit.SECONDS));
assertEquals(0, runConfig.getExitValue());

String[] argsStart = {
"jetty.http.port=" + httpPort,
"jetty.ssl.port=" + sslPort,
"jetty.server.dumpAfterStart=true"
};

try (JettyHomeTester.Run runStart = distribution.start(argsStart))
{
assertTrue(runStart.awaitConsoleLogsFor("Started oejs.Server@", START_TIMEOUT, TimeUnit.SECONDS));
startHttpClient();
String baseURI = "http://localhost:%d/%s-test".formatted(httpPort, env);

ContentResponse response = client.POST(baseURI + "/dump/info").send();
assertEquals(HttpStatus.OK_200, response.getStatus(), new ResponseDetails(response));
assertThat(response.getContentAsString(), containsString("Dump Servlet"));
assertThat(response.getContentAsString(), containsString("context-override-example:&nbsp;</th><td>a context value"));
}
}
}

}