PropertyResolver fails on JDK classes with a non-public field named like the property
メンテナーはふだん 1 日以内に返信
@vaibhavgupta443 がすでに取り組んでいます。
2026年11月23日 から。
評価
調査の方向性
wicket-core/src/main/java/org/apache/wicket/core/util/lang/PropertyResolver.java の DefaultPropertyLocator.findField と、1384-1414 行あたりの get(...) の経路から始めてください。宣言フィールドの検索を trySetAccessible() を使うように変更し、失敗した場合は null を返して階層をさらに上へたどらないようにしてから、LocalDate と DefaultMutableTreeNode で試してください。wicket-core-tests/src/test/java/org/apache/wicket/core/util/lang/PropertyResolverTest.java に、4 つの 'Done when' の振る舞いをカバーするケースを追加し、修正前にそれらが失敗することを確認してください。Done とは、JDK クラスが InaccessibleObjectException なしで public getter を通じて解決される一方、本当に解決できないプロパティは引き続き Wicket の通常のエラーを報告することを意味します。
索引モデルが issue の本文から書いたものです。
説明
On Java 17 and newer, a property expression on a JDK object fails when the class has a non-public field with the same name as the property, even when a public getter exists:
PropertyResolver.getValue("year", LocalDate.of(2020, 1, 2));
PropertyResolver.getValue("userObject", new DefaultMutableTreeNode("x"));
Both throw:
java.lang.reflect.InaccessibleObjectException: Unable to make field private final int java.time.LocalDate.year accessible: module java.base does not "opens java.time" to unnamed module
at java.base/java.lang.reflect.Field.setAccessible(Field.java:177)
at org.apache.wicket.core.util.lang.PropertyResolver$DefaultPropertyLocator.findField(PropertyResolver.java:1414)
at org.apache.wicket.core.util.lang.PropertyResolver$DefaultPropertyLocator.get(PropertyResolver.java:1384)
at org.apache.wicket.core.util.lang.PropertyResolver$CachingPropertyLocator.get(PropertyResolver.java:1236)
at org.apache.wicket.core.util.lang.PropertyResolver.getGetAndSet(PropertyResolver.java:389)
So a PropertyModel or CompoundPropertyModel on such an object breaks unless the application runs with --add-opens for that package. A public field, such as x on java.awt.Point, works.
Where
wicket-core/src/main/java/org/apache/wicket/core/util/lang/PropertyResolver.java, DefaultPropertyLocator. The file is the same on master, wicket-11.x and wicket-10.x.
When get(…) finds a getter, it still calls findField(clz, exp) (line 1384), because MethodGetAndSet keeps the field. It uses that field only to set the value when there is no setter, and to answer getPropertyField(). findField first tries clz.getField(…), which only finds public fields. When that fails, it walks getDeclaredFields() up the class hierarchy and calls setAccessible(true) on the field with the matching name (line 1414). For a class in a package that its module doesn't open, that throws InaccessibleObjectException. Nothing catches it, so the getter is never used. The failure isn't cached, so it repeats on every render.
Suggested fix
In findField, use trySetAccessible() instead of setAccessible(true). When it returns false, log at debug level and return null. Don't continue up the class hierarchy: a field with the same name in a superclass is not the property. MethodGetAndSet already handles a null field, and when there is no getter either, get(…) falls through to findMethod.
Done when
getValueandsetValueofuserObjecton aDefaultMutableTreeNodework.getValueofyearon aLocalDatereturns the year.setValueofyearfails with Wicket's "no set method defined" error, becauseLocalDatehas no setter.getValueofdayon aLocalDate(a private field without a getter) fails with "Property could not be resolved", not withInaccessibleObjectException.- Tests in
wicket-core-tests/src/test/java/org/apache/wicket/core/util/lang/PropertyResolverTest.java. The rootpom.xmlruns surefire with--add-opensforjava.base/java.lang,java.lang.reflect,java.ioandjdk.internal.loader. A test on a class from those packages passes without the fix too, so use classes fromjava.timeorjavax.swing.tree, as above, and check that the tests fail without the fix.
Out of scope
Getters declared on a non-public JDK class fail in a different place, in MethodGetAndSet. Examples are key on a HashMap entry (HashMap$Node.getKey()) and size() on Collections.unmodifiableList(…). Fixing those needs Wicket to look the method up on a public interface or superclass, which is a larger change. WICKET-6874 reported the size() case on 8.11 as an illegal reflective access warning; on Java 17 it is an error.
Background
Found through the TreeGrid examples of wicketstuff's inmethod-grid, which use expressions such as userObject.property1 on DefaultMutableTreeNode nodes and fail to render on Java 17 and 21 (see wicketstuff/core#1778). The fix also applies to wicket-10.x and wicket-11.x; a committer can backport it after it is merged on master.
This issue is meant for a first contribution to Wicket. To work on it, leave a comment so others know; a claim without a pull request lapses after two weeks. Questions are welcome, here on the issue or on [email protected]. Start your branch from master, and see Send a pull request to Wicket for building and testing.
- 主要言語
- Java
- スター
- 800
- フォーク
- 437
- 平均マージ
- 21時間 36分
- マージ済み PR(30日)
- 167
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/wicket のほかの issue
-
Stop the autocomplete from accumulating request parameters while typing対応中かも @aryankalantri が今日担当しました。 オープンgood first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
apache/wicket#1947 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Validate the report-uri value given to CSPHeaderConfiguration#reportBack対応中かも @AzizOuertani が 3 日前に担当しました。 オープンgood first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
apache/wicket#1946 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
account assessment course feature lecture
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
app:learninggoalhub enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 1/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100