diff --git a/spring-web/src/main/java/org/springframework/web/client/RestOperations.java b/spring-web/src/main/java/org/springframework/web/client/RestOperations.java
index b5a60302d9..59ee4c78cc 100644
--- a/spring-web/src/main/java/org/springframework/web/client/RestOperations.java
+++ b/spring-web/src/main/java/org/springframework/web/client/RestOperations.java
@@ -611,7 +611,7 @@ public interface RestOperations {
*
* MyRequest body = ...
* RequestEntity request = RequestEntity
- * .post(new URI("https://example.com/foo"))
+ * .post(URI.create("https://example.com/foo"))
* .accept(MediaType.APPLICATION_JSON)
* .body(body);
* ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
@@ -631,7 +631,7 @@ public interface RestOperations {
*
* MyRequest body = ...
* RequestEntity request = RequestEntity
- * .post(new URI("https://example.com/foo"))
+ * .post(URI.create("https://example.com/foo"))
* .accept(MediaType.APPLICATION_JSON)
* .body(body);
* ParameterizedTypeReference<List<MyResponse>> myBean =
diff --git a/spring-web/src/test/java/org/springframework/http/HttpEntityTests.java b/spring-web/src/test/java/org/springframework/http/HttpEntityTests.java
index 6ebf469d08..40b3a7d799 100644
--- a/spring-web/src/test/java/org/springframework/http/HttpEntityTests.java
+++ b/spring-web/src/test/java/org/springframework/http/HttpEntityTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -109,8 +109,8 @@ public class HttpEntityTests {
headers.setContentType(MediaType.TEXT_PLAIN);
String body = "foo";
HttpEntity httpEntity = new HttpEntity<>(body, headers);
- RequestEntity requestEntity = new RequestEntity<>(body, headers, HttpMethod.GET, new URI("/"));
- RequestEntity requestEntity2 = new RequestEntity<>(body, headers, HttpMethod.GET, new URI("/"));
+ RequestEntity requestEntity = new RequestEntity<>(body, headers, HttpMethod.GET, URI.create("/"));
+ RequestEntity requestEntity2 = new RequestEntity<>(body, headers, HttpMethod.GET, URI.create("/"));
assertThat(requestEntity.getBody()).isEqualTo(body);
assertThat(requestEntity.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
diff --git a/spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java b/spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java
index 12a0512a15..68f77065c1 100644
--- a/spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java
+++ b/spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java
@@ -153,7 +153,7 @@ public class HttpHeadersTests {
@Test
void location() throws URISyntaxException {
- URI location = new URI("https://www.example.com/hotels");
+ URI location = URI.create("https://www.example.com/hotels");
headers.setLocation(location);
assertThat(headers.getLocation()).as("Invalid Location header").isEqualTo(location);
assertThat(headers.getFirst("Location")).as("Invalid Location header").isEqualTo("https://www.example.com/hotels");
diff --git a/spring-web/src/test/java/org/springframework/http/RequestEntityTests.java b/spring-web/src/test/java/org/springframework/http/RequestEntityTests.java
index 1c979728f9..45799b74c0 100644
--- a/spring-web/src/test/java/org/springframework/http/RequestEntityTests.java
+++ b/spring-web/src/test/java/org/springframework/http/RequestEntityTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package org.springframework.http;
import java.net.URI;
-import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
@@ -41,10 +40,10 @@ import static org.assertj.core.api.Assertions.assertThat;
class RequestEntityTests {
@Test
- void normal() throws URISyntaxException {
+ void normal() {
String headerName = "My-Custom-Header";
String headerValue = "HeaderValue";
- URI url = new URI("https://example.com");
+ URI url = URI.create("https://example.com");
Integer entity = 42;
RequestEntity