Skip to content

Commit

Permalink
Convert UseTryWithResources NOPMDs to use try-with-resources
Browse files Browse the repository at this point in the history
Since JDK9 it is possible to use effectively final variables in try-with-resources and avoid having to define a new variable
  • Loading branch information
Adam- committed Jun 24, 2024
1 parent d77149e commit 227af35
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void onFailure(Call call, IOException e)
@Override
public void onResponse(Call call, Response response)
{
try // NOPMD: UseTryWithResources
try (response)
{
RuntimeConfig config = RuneLiteAPI.GSON.fromJson(response.body().charStream(), RuntimeConfig.class);
future.complete(config);
Expand All @@ -127,10 +127,6 @@ public void onResponse(Call call, Response response)
{
future.completeExceptionally(ex);
}
finally
{
response.close();
}
}
});
return future;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void onFailure(Call call, IOException e)
@Override
public void onResponse(Call call, Response response)
{
try // NOPMD: UseTryWithResources
try (response)
{
if (response.code() != 200)
{
Expand Down Expand Up @@ -188,10 +188,6 @@ public void onResponse(Call call, Response response)
{
future.completeExceptionally(ex);
}
finally
{
response.close();
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,10 @@ public void onFailure(Call call, IOException e)
@Override
public void onResponse(Call call, Response response) throws IOException
{
try // NOPMD: UseTryWithResources
try (response)
{
future.complete(processResponse(username, response));
}
finally
{
response.close();
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void onFailure(Call call, IOException e)
@Override
public void onResponse(Call call, Response response) throws IOException
{
try // NOPMD: UseTryWithResources
try (response)
{
if (!response.isSuccessful())
{
Expand All @@ -254,10 +254,6 @@ public void onResponse(Call call, Response response) throws IOException

partyService.setPartyMemberAvatar(event.getMemberId(), image);
}
finally
{
response.close();
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void onFailure(Call call, IOException e)
public void onResponse(Call call, Response response) throws IOException
{
String body = response.body().string();
try // NOPMD: UseTryWithResources
try (response)
{
JsonArray jar = new JsonParser().parse(body).getAsJsonArray();
List<String> apredictions = gson.fromJson(jar.get(1), new TypeToken<List<String>>()
Expand All @@ -159,10 +159,6 @@ public void onResponse(Call call, Response response) throws IOException
{
log.warn("error parsing wiki response {}", body, e);
}
finally
{
response.close();
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,13 @@ public void onFailure(Call call, IOException e)
@Override
public void onResponse(Call call, Response response)
{
try // NOPMD: UseTryWithResources
try (response)
{
if (!response.isSuccessful())
{
log.debug("unsuccessful xtea response");
}
}
finally
{
response.close();
}
}
});
}
Expand Down

0 comments on commit 227af35

Please sign in to comment.