Skip to content

Commit 4350eb1

Browse files
committed
[java] Add a warning while passing a decorated driver to augmenter
Related to #13246
1 parent 097d301 commit 4350eb1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

java/src/org/openqa/selenium/remote/Augmenter.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Set;
3131
import java.util.function.BiFunction;
3232
import java.util.function.Predicate;
33+
import java.util.logging.Logger;
3334
import java.util.stream.Collectors;
3435
import java.util.stream.Stream;
3536
import java.util.stream.StreamSupport;
@@ -59,6 +60,8 @@
5960
*/
6061
@Beta
6162
public class Augmenter {
63+
64+
private static final Logger LOG = Logger.getLogger(Augmenter.class.getName());
6265
private final Set<Augmentation<?>> augmentations;
6366

6467
public Augmenter() {
@@ -147,6 +150,19 @@ public WebDriver augment(WebDriver driver) {
147150
Require.precondition(
148151
driver instanceof HasCapabilities, "Driver must have capabilities", driver);
149152

153+
if (driver instanceof Decorated<?>) {
154+
LOG.warning(
155+
"Warning: In future versions, passing a decorated driver will no longer be allowed.\n"
156+
+ " Instead, augment the driver first and then use it to created a decorated"
157+
+ " driver.\n"
158+
+ " Explanation: Decorated drivers are not aware of the augmentations applied to"
159+
+ " them. It can lead to expected behavior.\n"
160+
+ " For example, augmenting HasDevTools interface to a decorated driver. \n"
161+
+ " The decorated driver is not aware that after augmentation it is an instance of"
162+
+ " HasDevTools. So it does not invoke the close() method of the underlying"
163+
+ " websocket, potentially causing a memory leak. ");
164+
}
165+
150166
Capabilities caps = ImmutableCapabilities.copyOf(((HasCapabilities) driver).getCapabilities());
151167

152168
// Collect the interfaces to apply

0 commit comments

Comments
 (0)