henrykuijpers opened a new pull request, #13: URL: https://github.com/apache/sling-org-apache-sling-scripting-jsp/pull/13
https://issues.apache.org/jira/browse/SLING-13381 ### Changes - New `RecordELResolver`: resolves record components through their accessor methods, so `${record.name}` calls `record.name()`. Records are read-only (`setValue` throws `PropertyNotWritableException`). - The record API (`Class.isRecord()`, `RecordComponent`) is accessed reflectively, so the bundle still targets Java 8 and only resolves records when running on Java 16+. Accessors are cached per class in a `ClassValue`, so classloaders aren't leaked. - The resolver is registered **before** the `BeanELResolver` in both resolver chains: - `JspApplicationContextImpl` (EL in JSP pages) - `ELResolverImpl.DefaultResolver` (`ExpressionEvaluator` API) If it came after, the `BeanELResolver` would throw a `PropertyNotFoundException` for record components. - Properties that aren't record components (e.g. a regular `getFoo()` on a record) are left unresolved, so the `BeanELResolver` still handles them as before. No changes to the pom or the bundle manifest. ### Tests - `RecordELResolverTest`: unit tests for every resolver method, covering records, non-public records, accessors that throw, non-records, a `null` base and a `null` context. - `ELResolverImplTest` and `JspApplicationContextImplTest`: EL expressions evaluated through both resolver chains, including the fallback to bean getters, and checks that beans and maps still resolve. - The test sources are compiled for Java 8, so the records are compiled at runtime by the `TestRecords` class rule. **Tests that need a record are skipped on JVMs older than Java 16.** The CI build only runs on JDK 11 (`.sling-module.json`), so it skips the record tests. To run them locally, keep building with JDK 11 (parent 35's bnd 4.2.0 fails on JDK 17+) and run the tests on a newer JVM: ``` mvn clean install -Djvm=/path/to/jdk-17/bin/java ``` Results: on JDK 11, 65 tests run and 24 are skipped. With the tests on JDK 17 or 21, all 65 run and none are skipped. I also temporarily broke the code three ways (resolver order in each chain, removing `setAccessible`), and each one fails the corresponding tests. The record tests will run in CI once the build moves to JDK 17+ (e.g. via SLING-12438 / #10). -- 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]
