PropertyResolver fails on public getters declared on non-public JDK classes
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- Ngôn ngữ chính
- Java
- Star
- 800
- Fork
- 437
- Merge trung bình
- 21 giờ 36 phút
- Pull request đã merge (30 ngày)
- 167
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/wicket
-
PropertyResolver fails on JDK classes with a non-public field named like the propertyCó thể đã có người làm @vaibhavgupta443 đã nhận hôm nay. Đang mởgood first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
apache/wicket#1991 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Stop the autocomplete from accumulating request parameters while typingCó thể đã có người làm @aryankalantri đã nhận hôm nay. Đang mởgood first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
apache/wicket#1947 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Validate the report-uri value given to CSPHeaderConfiguration#reportBackCó thể đã có người làm @AzizOuertani đã nhận 3 ngày trước. Đang mởgood first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
apache/wicket#1946 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của apache/wicket
Issue tương tự
-
Quick Installation step 2 installs from the plugin manager, but the plugin isn't published yetĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
jenkinsci/user-guide-ai-chatbot-plugin#132 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
account assessment course feature lecture
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] 连接达梦时报错,agent 进程启动即退Đang mởbug db/dameng user-priority/P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
t8y2/dbx#15534 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
app:learninggoalhub enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100