Skip to content

Commit 8a8542b

Browse files
committed
use try with resources
1 parent e679dc7 commit 8a8542b

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexerUtil.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.index;
2424

25+
import jakarta.ws.rs.client.Client;
2526
import org.opengrok.indexer.configuration.RuntimeEnvironment;
2627

2728
import jakarta.ws.rs.ProcessingException;
@@ -68,19 +69,23 @@ public static void enableProjects(final String host) throws
6869
ResponseProcessingException,
6970
ProcessingException,
7071
WebApplicationException {
71-
final Invocation.Builder request = ClientBuilder.newClient()
72-
.target(host)
73-
.path("api")
74-
.path("v1")
75-
.path("configuration")
76-
.path("projectsEnabled")
77-
.request()
78-
.headers(getWebAppHeaders());
79-
final String enabled = request.get(String.class);
80-
if (!Boolean.parseBoolean(enabled)) {
81-
final Response r = request.put(Entity.text(Boolean.TRUE.toString()));
82-
if (r.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
83-
throw new WebApplicationException(String.format("Unable to enable projects: %s", r.getStatusInfo().getReasonPhrase()), r.getStatus());
72+
73+
try (Client client = ClientBuilder.newClient()) {
74+
final Invocation.Builder request = client.target(host)
75+
.path("api")
76+
.path("v1")
77+
.path("configuration")
78+
.path("projectsEnabled")
79+
.request()
80+
.headers(getWebAppHeaders());
81+
final String enabled = request.get(String.class);
82+
if (!Boolean.parseBoolean(enabled)) {
83+
try (final Response r = request.put(Entity.text(Boolean.TRUE.toString()))) {
84+
if (r.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
85+
throw new WebApplicationException(String.format("Unable to enable projects: %s",
86+
r.getStatusInfo().getReasonPhrase()), r.getStatus());
87+
}
88+
}
8489
}
8590
}
8691
}

0 commit comments

Comments
 (0)