Skip to content

Commit 3a3179f

Browse files
olivergondzakhmarbaise
authored andcommitted
Fix #118: Avoid the unsafe cast in Build#Stop() (#326)
- Recover when 405 is returned - Propagate other exceptions correctly
1 parent 72767c4 commit 3a3179f

File tree

1 file changed

+6
-6
lines changed
  • jenkins-client/src/main/java/com/offbytwo/jenkins/model

1 file changed

+6
-6
lines changed

jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ public String Stop() throws HttpResponseException, IOException {
140140
try {
141141

142142
return client.get(url + "stop");
143-
} catch (IOException ex) {
144-
if (((HttpResponseException) ex).getStatusCode() == 405) {
143+
} catch (HttpResponseException ex) {
144+
if (ex.getStatusCode() == 405) {
145145
stopPost();
146146
return "";
147147
}
148+
throw ex;
148149
}
149-
return "";
150150
}
151151

152152
/** Stops the build which is currently in progress. This version takes in
@@ -163,13 +163,13 @@ public String Stop(boolean crumbFlag) throws HttpResponseException, IOException
163163
try {
164164

165165
return client.get(url + "stop");
166-
} catch (IOException ex) {
167-
if (((HttpResponseException) ex).getStatusCode() == 405) {
166+
} catch (HttpResponseException ex) {
167+
if (ex.getStatusCode() == 405) {
168168
stopPost(crumbFlag);
169169
return "";
170170
}
171+
throw ex;
171172
}
172-
return "";
173173
}
174174

175175
private void stopPost(boolean crumbFlag) throws HttpResponseException, IOException {

0 commit comments

Comments
 (0)