-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARJAVA-4784 Add HttpClient to S2093 for Java21 (#4686)
- Loading branch information
1 parent
a39e170
commit 6a7d5c5
Showing
3 changed files
with
69 additions
and
11 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
java-checks-test-sources/default/src/main/java/checks/TryWithResourcesCheck_java_21.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package checks; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
|
||
class TryWithResourcesCheck_java_21 { | ||
|
||
void httpClientIsAutoCloseableAsOfJava21(HttpRequest request) throws IOException, InterruptedException { | ||
HttpClient client = null; | ||
var o = new Object(); | ||
try { // Noncompliant {{Change this "try" to a try-with-resources.}} | ||
client = HttpClient.newBuilder().build(); | ||
client.send(request, HttpResponse.BodyHandlers.ofString()); | ||
} finally { | ||
if (client != null) { | ||
client.close(); | ||
} | ||
} | ||
|
||
try { // Noncompliant | ||
client = HttpClient.newHttpClient(); | ||
client.send(request, HttpResponse.BodyHandlers.ofString()); | ||
} finally { | ||
client.close(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters