PropertyResolver fails on public getters declared on non-public JDK classes
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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.
- Lingua principale
- Java
- Stelle
- 800
- Fork
- 437
- Merge medio
- 21h 36m
- PR unite (30g)
- 167
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/wicket
-
PropertyResolver fails on JDK classes with a non-public field named like the propertyForse già presa @vaibhavgupta443 l’ha presa oggi. Apertagood first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
apache/wicket#1991 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Stop the autocomplete from accumulating request parameters while typingForse già presa @aryankalantri l’ha presa oggi. Apertagood first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
apache/wicket#1947 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Validate the report-uri value given to CSPHeaderConfiguration#reportBackForse già presa @AzizOuertani l’ha presa 3 giorni fa. Apertagood first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
apache/wicket#1946 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di apache/wicket
Issue simili
-
account assessment course feature lecture
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
app:learninggoalhub enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100