From 173833243d37427a1d73ae53b1b57921b0fab236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Gond=C5=BEa?= Date: Thu, 29 Mar 2018 10:26:36 +0200 Subject: [PATCH] Fix #118: Avoid the unsafe cast in Build#Stop() - Recover when 405 is returned - Propagate other exceptions correctly --- .../main/java/com/offbytwo/jenkins/model/Build.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java index 048c2bce..35d8ecc5 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java @@ -140,13 +140,13 @@ public String Stop() throws HttpResponseException, IOException { try { return client.get(url + "stop"); - } catch (IOException ex) { - if (((HttpResponseException) ex).getStatusCode() == 405) { + } catch (HttpResponseException ex) { + if (ex.getStatusCode() == 405) { stopPost(); return ""; } + throw ex; } - return ""; } /** Stops the build which is currently in progress. This version takes in @@ -163,13 +163,13 @@ public String Stop(boolean crumbFlag) throws HttpResponseException, IOException try { return client.get(url + "stop"); - } catch (IOException ex) { - if (((HttpResponseException) ex).getStatusCode() == 405) { + } catch (HttpResponseException ex) { + if (ex.getStatusCode() == 405) { stopPost(crumbFlag); return ""; } + throw ex; } - return ""; } private void stopPost(boolean crumbFlag) throws HttpResponseException, IOException {