[🐛 Bug]: JPMS: `isDisplayed.js` / `getAttribute.js` not found on the module path (`Read.resourceAsString` is caller-sensitive)

オープン
#18,324 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
53/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java
領域
api, backend

調査の方向性

Read java/src/org/openqa/selenium/remote/codec/w3c/W3CHttpCommandCodec.java, java/src/org/openqa/selenium/remote/RemoteScript.java, and java/src/org/openqa/selenium/io/Read.java, along with the relevant module descriptors. Reproduce the failure using the provided Maven project on the module path, then check both resource-loading call sites. Done when the affected resources load on the module path without requiring consumers to add the workaround directive.

索引モデルが issue の本文から書いたものです。

説明

A-needs-triaging C-java D-chrome D-firefox I-defect OS-linux
Description

When Selenium runs on the module path, W3CHttpCommandCodec cannot load JavaScript files it needs, so WebElement#isDisplayed() and #getAttribute() fail with any browser (no Grid).

Works on the class path.

java.lang.IllegalArgumentException: Resource not found: /org/openqa/selenium/remote/isDisplayed.js
	at org.seleniumhq.selenium.api/org.openqa.selenium.io.Read.resourceAsString(Read.java:71)
	at org.seleniumhq.selenium.remote_driver/org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec.lambda$executeAtom$0(W3CHttpCommandCodec.java:364)

Reproducer

Simple Maven project that showcases the issue: selenium-bug-remote-resource-jpms.zip

Only dependency is org.seleniumhq.selenium:selenium-remote-driver:4.52.0; no browser needed. Run with:

mvn package
java -p target/classes:target/lib -m repro/repro.Main       # fails: Resource not found
java -cp 'target/classes:target/lib/*' repro.Main           # works

# Workaround works too
java --add-opens org.seleniumhq.selenium.remote_driver/org.openqa.selenium.remote=org.seleniumhq.selenium.api -p target/classes:target/lib -m repro/repro.Main

Cause

W3CHttpCommandCodec now calls Read.resourceAsString(getClass(), "/org/openqa/selenium/remote/isDisplayed.js"); and Read calls clazz.getResourceAsStream(path).

This fails, because Class#getResourceAsStream is caller-sensitive: the package must be opened to the caller's module, i.e. org.seleniumhq.selenium.api. But remote_driver opens org.openqa.selenium.remote only to org.seleniumhq.selenium.json.

Same issue in RemoteScript (resource bidi-mutation-listener.js).

Suggested fix

Two options that come to mind:

  • Load the resource in the module that owns it, e.g. Read.toString(getClass().getResourceAsStream(path)) (plus null check) in W3CHttpCommandCodec and RemoteScript.
  • Alternative: Add opens org.openqa.selenium.remote to org.seleniumhq.selenium.api to the module descriptor of org.seleniumhq.selenium.remote_driver.

Read.resourceAsString(Class, String) can never work for non-open packages of other named modules, so it might be worth deprecating.

Workaround

Consumers must add the missing opens directive manually when running on the module path:

--add-opens org.seleniumhq.selenium.remote_driver/org.openqa.selenium.remote=org.seleniumhq.selenium.api
Reproducible Code
// module-info.java
module repro {
    requires org.seleniumhq.selenium.remote_driver;
}

// repro/Main.java
package repro;

import java.util.Map;
import org.openqa.selenium.remote.Command;
import org.openqa.selenium.remote.DriverCommand;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec;

public final class Main {
    public static void main(String[] args) {
        var command = new Command(new SessionId("s"), DriverCommand.IS_ELEMENT_DISPLAYED, Map.of("id", "e"));
        System.out.println(new W3CHttpCommandCodec().encode(command).getUri());
    }
}
Debugging Logs
_(none, stack trace above)_
主要言語
Java
スター
34.6k
フォーク
8.7k
平均マージ
1日 23時間
マージ済み PR(30日)
86

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

SeleniumHQ/selenium のほかの issue

SeleniumHQ/selenium の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。