We tried to use the UriTemplate in projects using Java 21.
E.g. in https://github.com/wcm-io-caravan/caravan-rhyme
The error can reproduced in this project itself by just building it with Java 21:
- Update the source code level to 1.8 for the maven-compiler-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
- Run maven package:
$ export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64/
$ ./mvnw clean package
- This makes the following tests to fail:
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] TestExtendedSpecTests>AbstractUriTemplateConformanceTest.test:156 Additional Examples 3: Empty Variables-> Template: {/empty_list*} returned java.lang.reflect.InvocationTargetException and did not match any combination
[ERROR] TestExtendedSpecTests>AbstractUriTemplateConformanceTest.test:156 Additional Examples 3: Empty Variables-> Template: {/empty_list} returned java.lang.reflect.InvocationTargetException and did not match any combination
[ERROR] TestExtendedSpecTests>AbstractUriTemplateConformanceTest.test:156 Additional Examples 3: Empty Variables-> Template: {?empty_list*} returned java.lang.reflect.InvocationTargetException and did not match any combination
[ERROR] TestExtendedSpecTests>AbstractUriTemplateConformanceTest.test:156 Additional Examples 3: Empty Variables-> Template: {?empty_list} returned java.lang.reflect.InvocationTargetException and did not match any combination
[ERROR] TestSpecExamplesBySection>AbstractUriTemplateConformanceTest.test:156 3.2.5 Label Expansion with Dot-Prefix-> Template: X{.empty_keys*} returned java.lang.reflect.InvocationTargetException and did not match any combination
[ERROR] TestSpecExamplesBySection>AbstractUriTemplateConformanceTest.test:156 3.2.5 Label Expansion with Dot-Prefix-> Template: X{.empty_keys} returned java.lang.reflect.InvocationTargetException and did not match any combination
[INFO]
[ERROR] Tests run: 461, Failures: 6, Errors: 0, Skipped: 7
The issue is caused by new methods added to Java collections in Java 21:
These methods look like bean properties (named first and last) but throwing a NoSuchElementException if the collection is empty.
We tried to use the UriTemplate in projects using Java 21.
E.g. in https://github.com/wcm-io-caravan/caravan-rhyme
The error can reproduced in this project itself by just building it with Java 21:
The issue is caused by new methods added to Java collections in Java 21:
These methods look like bean properties (named
firstandlast) but throwing aNoSuchElementExceptionif the collection is empty.