Skip to content

Commit 453f597

Browse files
committed
Correcting logic around classIsPresent
Signed-off-by: Joakim Erdfelt <[email protected]>
1 parent bf66c83 commit 453f597

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.eclipse.jetty.server.Request;
4242
import org.eclipse.jetty.server.RequestLog;
4343
import org.eclipse.jetty.server.Response;
44-
import org.eclipse.jetty.util.Jetty;
4544
import org.eclipse.jetty.util.component.LifeCycle;
4645

4746
/**
@@ -222,31 +221,30 @@ enum State {
222221
String fileName;
223222
String resource;
224223

225-
// Default to non-modern Jetty (ie: Jetty 9.3 or earlier)
226224
// Jetty 9.4.x and newer is considered modern.
227-
boolean modernJettyRequestLog = false;
225+
boolean modernJettyRequestLog;
228226
boolean quiet = false;
229227

230228
public RequestLogImpl() {
231229
putObject(CoreConstants.EVALUATOR_MAP, new HashMap<String, EventEvaluator<?>>());
232230

233231
// plumb the depths of Jetty and the environment ...
234-
try {
235-
Class.forName("jakarta.servlet.http.HttpServlet");
232+
if (classIsPresent("jakarta.servlet.http.HttpServlet")) {
236233
throw new RuntimeException("The new jakarta.servlet classes are not supported by this " +
237234
"version of logback-access (check for a newer version of logback-access that " +
238235
"does support it)");
239-
} catch(Throwable ignore) {
240-
// Class doesn't exist, assumption is that this is normal javax.servlet environment.
241236
}
242237

243238
// look for modern approach to RequestLog
239+
modernJettyRequestLog = classIsPresent("org.eclipse.jetty.server.CustomRequestLog");
240+
}
241+
242+
private boolean classIsPresent(String className) {
244243
try {
245-
Class.forName("org.eclipse.jetty.server.CustomRequestLog");
246-
// Class exists, treat as modern Jetty.
247-
modernJettyRequestLog = true;
248-
} catch(Throwable ignore) {
249-
// Class doesn't exist, this is an old school Jetty.
244+
Class.forName(className);
245+
return true;
246+
} catch (ClassNotFoundException e) {
247+
return false;
250248
}
251249
}
252250

0 commit comments

Comments
 (0)