Skip to content
Open
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 @@ -95,37 +95,14 @@ public static BrowsingContextInfo fromJson(JsonInput input) {
input.beginObject();
while (input.hasNext()) {
switch (input.nextName()) {
case "context":
id = input.read(String.class);
break;

case "url":
url = input.read(String.class);
break;

case "children":
children = input.read(LIST_OF_BROWSING_CONTEXT_INFO);
break;

case "parent":
parentBrowsingContext = input.read(String.class);
break;

case "clientWindow":
clientWindow = input.read(String.class);
break;

case "originalOpener":
originalOpener = input.read(String.class);
break;

case "userContext":
userContext = input.read(String.class);
break;

default:
input.skipValue();
break;
case "context" -> id = input.read(String.class);
case "url" -> url = input.read(String.class);
case "children" -> children = input.read(LIST_OF_BROWSING_CONTEXT_INFO);
case "parent" -> parentBrowsingContext = input.read(String.class);
case "clientWindow" -> clientWindow = input.read(String.class);
case "originalOpener" -> originalOpener = input.read(String.class);
case "userContext" -> userContext = input.read(String.class);
default -> input.skipValue();
}
}

Expand Down
26 changes: 14 additions & 12 deletions java/src/org/openqa/selenium/support/ThreadGuard.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
// under the License.
package org.openqa.selenium.support;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;

/**
* Multithreaded client code should use this to assert that it accesses webdriver in a thread-safe
Expand All @@ -44,10 +45,10 @@ public class ThreadGuard {
public static WebDriver protect(WebDriver actualWebDriver) {
WebDriverInvocationHandler invocationHandler = new WebDriverInvocationHandler(actualWebDriver);
return (WebDriver)
java.lang.reflect.Proxy.newProxyInstance(
actualWebDriver.getClass().getClassLoader(),
getInterfaces(actualWebDriver),
invocationHandler);
java.lang.reflect.Proxy.newProxyInstance(
actualWebDriver.getClass().getClassLoader(),
getInterfaces(actualWebDriver),
invocationHandler);
}

private static Class<?>[] getInterfaces(Object target) {
Expand Down Expand Up @@ -82,11 +83,12 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
if (Thread.currentThread().getId() != threadId) {
Thread currentThread = Thread.currentThread();
throw new WebDriverException(
String.format(
"Thread safety error; this instance of WebDriver was constructed on "
+ "thread %s (id %d) and is being accessed by thread %s (id %d)"
+ "This is not permitted and *will* cause undefined behaviour",
threadName, threadId, currentThread.getName(), currentThread.getId()));
String.format(
"""
Thread safety error; this instance of WebDriver was constructed on
thread %s (id %d) and is being accessed by thread %s (id %d)
This is not permitted and *will* cause undefined behaviour
""", threadName, threadId, currentThread.getName(), currentThread.getId()));
}
return invokeUnderlying(method, args);
} catch (InvocationTargetException e) {
Expand All @@ -95,7 +97,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
}

protected Object invokeUnderlying(Method method, Object[] args)
throws IllegalAccessException, InvocationTargetException {
throws IllegalAccessException, InvocationTargetException {
return method.invoke(underlying, args);
}
}
Expand Down
Loading