Skip to content

Commit 3fe2634

Browse files
committed
Fix the status handler
Turns out to be a nasty problem with instantiating some kinds of handlers (those that don't take a parameter) Interesting story: the lambda was created automatically by a refactoring IDE. Each individual step was correct, except the last one, which took a method call (`constructor.newInstance()`) and turned into a method referened (`constructor::newInstance`). When called, the original version of this didn't pass any arguments, and everything was fine. The mathod reference version, however, caused the sessionId to be passed to the `newInstance` method as argument, causing grief. Still. Fixed now.
1 parent 10d4ab6 commit 3fe2634

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

java/server/src/org/openqa/selenium/remote/server/rest/ResultConfig.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,29 +204,19 @@ public Throwable getRootExceptionCause(Throwable originalException) {
204204
private HandlerFactory getHandlerFactory(Class<? extends RestishHandler<?>> handlerClazz) {
205205
final Constructor<? extends RestishHandler<?>> sessionAware = getConstructor(handlerClazz, Session.class);
206206
if (sessionAware != null) {
207-
return new HandlerFactory() {
208-
@Override
209-
public RestishHandler<?> createHandler(SessionId sessionId) throws Exception {
210-
return sessionAware.newInstance(sessionId != null ? sessions.get(sessionId) : null);
211-
}
212-
};
207+
return (sessionId) ->
208+
sessionAware.newInstance(sessionId != null ? sessions.get(sessionId) : null);
213209
}
214210

215211
final Constructor<? extends RestishHandler> driverSessions =
216212
getConstructor(handlerClazz, DriverSessions.class);
217213
if (driverSessions != null) {
218-
return new HandlerFactory() {
219-
@Override
220-
public RestishHandler<?> createHandler(SessionId sessionId) throws Exception {
221-
return driverSessions.newInstance(sessions);
222-
}
223-
};
214+
return (sessionId) -> driverSessions.newInstance(sessions);
224215
}
225216

226-
227-
final Constructor<? extends RestishHandler> norags = getConstructor(handlerClazz);
228-
if (norags != null) {
229-
return norags::newInstance;
217+
final Constructor<? extends RestishHandler> noArgs = getConstructor(handlerClazz);
218+
if (noArgs != null) {
219+
return (sessionId) -> noArgs.newInstance();
230220
}
231221

232222
throw new IllegalArgumentException("Don't know how to construct " + handlerClazz);

0 commit comments

Comments
 (0)