File tree Expand file tree Collapse file tree
application/src/main/java/org/togetherjava/tjbot/features/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,7 +68,6 @@ public static boolean containsLink(String content) {
6868 return !(new UrlDetector (content , UrlDetectorOptions .BRACKET_MATCH ).detect ().isEmpty ());
6969 }
7070
71- @ SuppressWarnings ("java:S2095" )
7271 public static CompletableFuture <Boolean > isLinkBroken (String url ) {
7372 HttpRequest headRequest = HttpRequest .newBuilder (URI .create (url ))
7473 .method ("HEAD" , HttpRequest .BodyPublishers .noBody ())
@@ -77,21 +76,17 @@ public static CompletableFuture<Boolean> isLinkBroken(String url) {
7776 return HTTP_CLIENT .sendAsync (headRequest , HttpResponse .BodyHandlers .discarding ())
7877 .thenApply (response -> {
7978 int status = response .statusCode ();
80- if (status >= 200 && status < 400 ) {
81- return false ;
82- }
83- return status >= 400 ? true : null ;
79+ return status < 200 || status >= 400 ;
8480 })
85- .exceptionally (ignored -> null )
81+ .exceptionally (ignored -> true )
8682 .thenCompose (result -> {
87- if (result != null ) {
88- return CompletableFuture .completedFuture (result );
83+ if (! result ) {
84+ return CompletableFuture .completedFuture (false );
8985 }
9086 HttpRequest getRequest = HttpRequest .newBuilder (URI .create (url )).GET ().build ();
91-
9287 return HTTP_CLIENT .sendAsync (getRequest , HttpResponse .BodyHandlers .discarding ())
9388 .thenApply (resp -> resp .statusCode () >= 400 )
94- .exceptionally (ignored -> true );
89+ .exceptionally (ignored -> true ); // still never null
9590 });
9691 }
9792
You can’t perform that action at this time.
0 commit comments