dashorst opened a new issue, #1993:
URL: https://github.com/apache/wicket/issues/1993

   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:
   
   ```java
   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 `MethodGetAndSet` constructor calls `getMethod.setAccessible(true)`, 
which throws because `java.util` isn't open;
   - `IndexedPropertyGetAndSet` does the same for indexed getters and setters;
   - `MethodGetAndSet.findSetter` calls `setAccessible(true)` inside a `catch 
(Exception e)`, so for a setter on such a class the setter silently becomes 
`null`.
   
   `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](https://issues.apache.org/jira/browse/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.xml` runs surefire with 
`--add-opens` for `java.base/java.lang`, `java.lang.reflect`, `java.io` and 
`jdk.internal.loader`, but not for `java.util`, so the examples above reproduce 
the problem in `wicket-core-tests`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to