Skip to content

Commit

Permalink
Add Java 21 build (#50)
Browse files Browse the repository at this point in the history
* Add Java 21 build
Update to checkout@v4

* avoid issue with UriTemplate unable to expand an empty query parameter list (which failed only on the new Java 21 build)

---------

Co-authored-by: Steffen Sauder <[email protected]>
  • Loading branch information
stefanseifert and feffef authored Jun 1, 2024
1 parent 81dff00 commit c1d179e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
java: [11, 17]
java: [11, 17, 21]
os: [ubuntu-latest]
distribution: [temurin]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maven-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Configure GIT
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Application;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.osgi.service.component.annotations.Component;
Expand All @@ -55,6 +56,7 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.UncheckedExecutionException;

import io.wcm.caravan.hal.resource.Link;
Expand Down Expand Up @@ -269,6 +271,17 @@ private String createQueryParamsTemplate(Map<String, Object> parameterMap) {
String[] sortedVarNames = getQueryParameterVarNames(tp -> parameterMap.containsKey(tp.name));

for (String varName : sortedVarNames) {

// Here comes a workaround for a weird issue that was introduced with Java 21:
// The UriTemplate class is suddenly no longer able to expand a query parameter template
// with an empty list/array value.
// This can be avoided by simply not adding this parameter to the template in the first place
String key = StringUtils.substringBefore(varName, "*");
Object value = parameterMap.get(key);
if (value instanceof Iterable && Iterables.isEmpty((Iterable)value)) {
continue;
}

if (queries.length() == 0) {
queries.append("{?");
}
Expand Down

0 comments on commit c1d179e

Please sign in to comment.