Skip to content

Commit 95a7bfd

Browse files
committed
Consistent use of IllegalStateException instead of InternalError for UnsupportedEncodingException cause
(cherry picked from commit d9b39ad)
1 parent ccebbf7 commit 95a7bfd

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

spring-test/src/main/java/org/springframework/mock/http/MockHttpOutputMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public String getBodyAsString(Charset charset) {
8181
}
8282
catch (UnsupportedEncodingException ex) {
8383
// should not occur
84-
throw new InternalError(ex.getMessage());
84+
throw new IllegalStateException(ex);
8585
}
8686
}
8787

spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@ public abstract class HttpStatusCodeException extends RestClientException {
3535

3636
private static final String DEFAULT_CHARSET = "ISO-8859-1";
3737

38+
3839
private final HttpStatus statusCode;
3940

4041
private final String statusText;
@@ -74,10 +75,9 @@ protected HttpStatusCodeException(HttpStatus statusCode, String statusText) {
7475
* @param responseCharset the response body charset, may be {@code null}
7576
* @since 3.0.5
7677
*/
77-
protected HttpStatusCodeException(HttpStatus statusCode,
78-
String statusText,
79-
byte[] responseBody,
80-
Charset responseCharset) {
78+
protected HttpStatusCodeException(
79+
HttpStatus statusCode, String statusText, byte[] responseBody, Charset responseCharset) {
80+
8181
this(statusCode, statusText, null, responseBody, responseCharset);
8282
}
8383

@@ -93,6 +93,7 @@ protected HttpStatusCodeException(HttpStatus statusCode,
9393
*/
9494
protected HttpStatusCodeException(HttpStatus statusCode, String statusText,
9595
HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) {
96+
9697
super(statusCode.value() + " " + statusText);
9798
this.statusCode = statusCode;
9899
this.statusText = statusText;
@@ -126,11 +127,10 @@ public HttpHeaders getResponseHeaders() {
126127

127128
/**
128129
* Return the response body as a byte array.
129-
*
130130
* @since 3.0.5
131131
*/
132132
public byte[] getResponseBodyAsByteArray() {
133-
return responseBody;
133+
return this.responseBody;
134134
}
135135

136136
/**
@@ -139,11 +139,11 @@ public byte[] getResponseBodyAsByteArray() {
139139
*/
140140
public String getResponseBodyAsString() {
141141
try {
142-
return new String(responseBody, responseCharset);
142+
return new String(this.responseBody, this.responseCharset);
143143
}
144144
catch (UnsupportedEncodingException ex) {
145145
// should not occur
146-
throw new InternalError(ex.getMessage());
146+
throw new IllegalStateException(ex);
147147
}
148148
}
149149

spring-web/src/main/java/org/springframework/web/client/UnknownHttpStatusCodeException.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.web.client;
1718

1819
import java.io.UnsupportedEncodingException;
@@ -64,6 +65,7 @@ public UnknownHttpStatusCodeException(int rawStatusCode, String statusText,
6465
this.responseCharset = responseCharset != null ? responseCharset.name() : DEFAULT_CHARSET;
6566
}
6667

68+
6769
/**
6870
* Return the raw HTTP status code value.
6971
*/
@@ -89,19 +91,19 @@ public HttpHeaders getResponseHeaders() {
8991
* Return the response body as a byte array.
9092
*/
9193
public byte[] getResponseBodyAsByteArray() {
92-
return responseBody;
94+
return this.responseBody;
9395
}
9496

9597
/**
9698
* Return the response body as a string.
9799
*/
98100
public String getResponseBodyAsString() {
99101
try {
100-
return new String(responseBody, responseCharset);
102+
return new String(this.responseBody, this.responseCharset);
101103
}
102104
catch (UnsupportedEncodingException ex) {
103105
// should not occur
104-
throw new InternalError(ex.getMessage());
106+
throw new IllegalStateException(ex);
105107
}
106108
}
107109

spring-web/src/main/java/org/springframework/web/util/UriComponents.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.springframework.util.MultiValueMap;
3131

3232
/**
33-
* Represents an immutable collection of URI components, mapping component type to string
33+
* Represents an immutable collection of URI components, mapping component type to String
3434
* values. Contains convenience getters for all components. Effectively similar to {@link
3535
* java.net.URI}, but with more powerful encoding options and support for URI template
3636
* variables.
@@ -119,14 +119,15 @@ public final String getFragment() {
119119
/**
120120
* Encode all URI components using their specific encoding rules, and returns the
121121
* result as a new {@code UriComponents} instance. This method uses UTF-8 to encode.
122-
* @return the encoded uri components
122+
* @return the encoded URI components
123123
*/
124124
public final UriComponents encode() {
125125
try {
126126
return encode(DEFAULT_ENCODING);
127127
}
128-
catch (UnsupportedEncodingException e) {
129-
throw new InternalError("\"" + DEFAULT_ENCODING + "\" not supported");
128+
catch (UnsupportedEncodingException ex) {
129+
// should not occur
130+
throw new IllegalStateException(ex);
130131
}
131132
}
132133

@@ -140,7 +141,7 @@ public final UriComponents encode() {
140141
public abstract UriComponents encode(String encoding) throws UnsupportedEncodingException;
141142

142143
/**
143-
* Replaces all URI template variables with the values from a given map. The map keys
144+
* Replace all URI template variables with the values from a given map. The map keys
144145
* represent variable names; the values variable values. The order of variables is not
145146
* significant.
146147
* @param uriVariables the map of URI variables
@@ -152,7 +153,7 @@ public final UriComponents expand(Map<String, ?> uriVariables) {
152153
}
153154

154155
/**
155-
* Replaces all URI template variables with the values from a given array. The array
156+
* Replace all URI template variables with the values from a given array. The array
156157
* represent variable values. The order of variables is significant.
157158
* @param uriVariableValues URI variable values
158159
* @return the expanded uri components
@@ -163,7 +164,7 @@ public final UriComponents expand(Object... uriVariableValues) {
163164
}
164165

165166
/**
166-
* Replaces all URI template variables with the values obtained through the
167+
* Replace all URI template variables with the values obtained through the
167168
* given {@link UriTemplateVariables} instance.
168169
* @param uriTemplateVars resolves URI template variable values
169170
* @return the expanded uri components
@@ -174,7 +175,7 @@ public final UriComponents expand(UriTemplateVariables uriTemplateVars) {
174175
}
175176

176177
/**
177-
* Replaces all URI template variables with the values from the given {@link
178+
* Replace all URI template variables with the values from the given {@link
178179
* UriTemplateVariables}
179180
* @param uriVariables URI template values
180181
* @return the expanded uri components
@@ -188,12 +189,12 @@ public final UriComponents expand(UriTemplateVariables uriTemplateVars) {
188189
public abstract UriComponents normalize();
189190

190191
/**
191-
* Returns a URI string from this {@code UriComponents} instance.
192+
* Return a URI string from this {@code UriComponents} instance.
192193
*/
193194
public abstract String toUriString();
194195

195196
/**
196-
* Returns a {@code URI} from this {@code UriComponents} instance.
197+
* Return a {@code URI} from this {@code UriComponents} instance.
197198
*/
198199
public abstract URI toUri();
199200

0 commit comments

Comments
 (0)