PropertyResolver fails on public getters declared on non-public JDK classes
维护者通常 1 天内回复
评估
这个 Issue 还没有评估数据。
描述
On Java 17 and newer, a property expression fails when the getter is public but is declared on a class that isn't public, as many JDK implementation classes are:
Map.Entry<String, String> entry = new HashMap<>(Map.of("k", "v")).entrySet().iterator().next();
PropertyResolver.getValue("key", entry);
List<Integer> list = Collections.unmodifiableList(new ArrayList<>(List.of(1)));
PropertyResolver.getValue("size()", list);
PropertyResolver.getValue("empty", list);
All three throw InaccessibleObjectException, for example:
java.lang.reflect.InaccessibleObjectException: Unable to make public int java.util.Collections$UnmodifiableCollection.size() accessible: module java.base does not "opens java.util" to unnamed module
So a PropertyModel on a map entry (for example in a ListView over map.entrySet()) or on a JDK collection wrapper breaks unless the application runs with --add-opens java.base/java.util=ALL-UNNAMED.
Where
wicket-core/src/main/java/org/apache/wicket/core/util/lang/PropertyResolver.java, the same on master, wicket-11.x and wicket-10.x. DefaultPropertyLocator looks getters and setters up on the runtime class of the object, so the Method it finds is declared on HashMap$Node or Collections$UnmodifiableCollection. Then:
- the
MethodGetAndSetconstructor callsgetMethod.setAccessible(true), which throws becausejava.utilisn't open; IndexedPropertyGetAndSetdoes the same for indexed getters and setters;MethodGetAndSet.findSettercallssetAccessible(true)inside acatch (Exception e), so for a setter on such a class the setter silently becomesnull.
trySetAccessible() alone doesn't fix this: without access, Method.invoke throws IllegalAccessException, because the declaring class isn't public. The method has to be looked up on a public class or interface that declares it, here Map.Entry.getKey() and Collection.size(), and invoked through that Method.
WICKET-6874 reported the size() case on 8.11, when Java only printed an illegal reflective access warning; it was closed as "Cannot Reproduce". On Java 17 it is an error.
For the key example, #1991 has to be fixed first: today findField already fails on the private key field of HashMap$Node, before this code is reached.
Done when
- Getters and setters declared on a non-public class are resolved through a public superclass or interface that declares the same method, so the examples above work without
--add-opens. - Tests that fail without the fix. The root
pom.xmlruns surefire with--add-opensforjava.base/java.lang,java.lang.reflect,java.ioandjdk.internal.loader, but not forjava.util, so the examples above reproduce the problem inwicket-core-tests.
- 主要语言
- Java
- 星标
- 800
- 派生
- 437
- 平均合并
- 21 小时 36 分钟
- 30 天内合并 PR
- 167
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/wicket 的其他 Issue
-
PropertyResolver fails on JDK classes with a non-public field named like the property可能已有人在做 @vaibhavgupta443 今天认领。 未关闭good first issue
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
Stop the autocomplete from accumulating request parameters while typing可能已有人在做 @aryankalantri 今天认领。 未关闭good first issue
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
Validate the report-uri value given to CSPHeaderConfiguration#reportBack可能已有人在做 @AzizOuertani 于 3 天前认领。 未关闭good first issue
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 70/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
jenkinsci/user-guide-ai-chatbot-plugin#132 ·
维护者通常 6 天内回复
-
account assessment course feature lecture
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
bug db/dameng user-priority/P2
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
app:learninggoalhub enhancement good first issue
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100