From ddcf01adf1015f1addca43574ad9a47f270fb6f9 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 20 Jun 2018 19:33:27 +0200 Subject: [PATCH] #724 - Make sure EncodingUtils compiles on both Spring 4.3 and 5. We now catch Throwable instead of UnsupportedEncodingException as in Spring 5, the methods on UriUtils don't throw the latter anymore. --- .../springframework/hateoas/core/EncodingUtils.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/hateoas/core/EncodingUtils.java b/src/main/java/org/springframework/hateoas/core/EncodingUtils.java index 953f584d..e596e777 100644 --- a/src/main/java/org/springframework/hateoas/core/EncodingUtils.java +++ b/src/main/java/org/springframework/hateoas/core/EncodingUtils.java @@ -17,7 +17,7 @@ package org.springframework.hateoas.core; import lombok.experimental.UtilityClass; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import org.springframework.util.Assert; import org.springframework.web.util.UriUtils; @@ -32,7 +32,7 @@ import org.springframework.web.util.UriUtils; @UtilityClass public class EncodingUtils { - private static final String ENCODING = "UTF-8"; + private static final String ENCODING = StandardCharsets.UTF_8.name(); /** * Encodes the given path value. @@ -46,7 +46,7 @@ public class EncodingUtils { try { return UriUtils.encodePath(source.toString(), ENCODING); - } catch (UnsupportedEncodingException o_O) { + } catch (Throwable o_O) { throw new IllegalStateException(o_O); } } @@ -63,7 +63,7 @@ public class EncodingUtils { try { return UriUtils.encodeQueryParam(source.toString(), ENCODING); - } catch (UnsupportedEncodingException o_O) { + } catch (Throwable o_O) { throw new IllegalStateException(o_O); } } @@ -80,7 +80,7 @@ public class EncodingUtils { try { return UriUtils.encodeFragment(source.toString(), ENCODING); - } catch (UnsupportedEncodingException o_O) { + } catch (Throwable o_O) { throw new IllegalStateException(o_O); } }