sling-org-apache-sling-models-impl icon indicating copy to clipboard operation
sling-org-apache-sling-models-impl copied to clipboard

SLING-11917 Evaluate constructor parameter names via reflection

Open kwin opened this issue 2 years ago • 7 comments

This is available if compiled accordingly (with javac option -parameters, https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#option-parameters), supported since javac 8+

kwin avatar Jun 27 '23 17:06 kwin

can you add a test case evaluating the new behavior?

i've never used the -parameters option, if i understand correctly it's still optional and not activated by default. so we need probably multiple maven verify executions or separate integration tests that test our code with variants of this flag enabled and not enabled, to ensure it works as expected in all conditions?

stefanseifert avatar Jun 30 '23 13:06 stefanseifert

The API https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Parameter.html is available since Java 8 (no matter if -parameters is used or not). The only difference is that https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Parameter.html#isNamePresent-- returns false by default and https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Parameter.html#getName-- returns an artificial name by default. But I will look into adding ITs (the current ones proof though that everything works by default, i.e. without using --parameters, so only ones with --parameters are currently not existing).

kwin avatar Jun 30 '23 13:06 kwin

Wouldn't that be as simple as adding another compile step in the project, for a separate source folder, that will have a sling model available to test?

henrykuijpers avatar Nov 18 '23 07:11 henrykuijpers

@henrykuijpers Yes, but I tried to do https://github.com/apache/sling-org-apache-sling-models-impl/pull/46 first, which turned out to be more complex.

kwin avatar Nov 18 '23 09:11 kwin