From c1d179e6a8c310f030a48c4f0ec7a0fda30cb558 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Sat, 1 Jun 2024 14:06:26 +0200 Subject: [PATCH] Add Java 21 build (#50) * 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 --- .github/workflows/maven-build.yml | 2 +- .github/workflows/maven-deploy.yml | 2 +- .../jaxrs/impl/JaxRsControllerProxyLinkBuilder.java | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index ca0dac79..84f537cb 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -20,7 +20,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - java: [11, 17] + java: [11, 17, 21] os: [ubuntu-latest] distribution: [temurin] diff --git a/.github/workflows/maven-deploy.yml b/.github/workflows/maven-deploy.yml index eae3bc5d..7d9621f6 100644 --- a/.github/workflows/maven-deploy.yml +++ b/.github/workflows/maven-deploy.yml @@ -17,7 +17,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Configure GIT run: | diff --git a/integration/osgi-jaxrs/src/main/java/io/wcm/caravan/rhyme/jaxrs/impl/JaxRsControllerProxyLinkBuilder.java b/integration/osgi-jaxrs/src/main/java/io/wcm/caravan/rhyme/jaxrs/impl/JaxRsControllerProxyLinkBuilder.java index 1d7e59ac..a2555df3 100644 --- a/integration/osgi-jaxrs/src/main/java/io/wcm/caravan/rhyme/jaxrs/impl/JaxRsControllerProxyLinkBuilder.java +++ b/integration/osgi-jaxrs/src/main/java/io/wcm/caravan/rhyme/jaxrs/impl/JaxRsControllerProxyLinkBuilder.java @@ -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; @@ -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; @@ -269,6 +271,17 @@ private String createQueryParamsTemplate(Map 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("{?"); }