Skip to content

Commit 0313222

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

File tree

4 files changed

+41
-37
lines changed

4 files changed

+41
-37
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
@@ -79,7 +79,7 @@ public String getBodyAsString(Charset charset) {
7979
}
8080
catch (UnsupportedEncodingException ex) {
8181
// should not occur
82-
throw new InternalError(ex.getMessage());
82+
throw new IllegalStateException(ex);
8383
}
8484
}
8585

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: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 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.
@@ -30,15 +30,16 @@
3030
import org.springframework.util.MultiValueMap;
3131

3232
/**
33-
* Represents an immutable collection of URI components, mapping component type to string
34-
* values. Contains convenience getters for all components. Effectively similar to {@link
35-
* java.net.URI}, but with more powerful encoding options and support for URI template
36-
* variables.
33+
* Represents an immutable collection of URI components, mapping component type to
34+
* String values. Contains convenience getters for all components. Effectively similar
35+
* to {@link java.net.URI}, but with more powerful encoding options and support for
36+
* URI template variables.
3737
*
3838
* @author Arjen Poutsma
3939
* @since 3.1
4040
* @see UriComponentsBuilder
4141
*/
42+
@SuppressWarnings("serial")
4243
public abstract class UriComponents implements Serializable {
4344

4445
private static final String DEFAULT_ENCODING = "UTF-8";
@@ -118,54 +119,55 @@ public final String getFragment() {
118119
/**
119120
* Encode all URI components using their specific encoding rules, and returns the
120121
* result as a new {@code UriComponents} instance. This method uses UTF-8 to encode.
121-
* @return the encoded uri components
122+
* @return the encoded URI components
122123
*/
123124
public final UriComponents encode() {
124125
try {
125126
return encode(DEFAULT_ENCODING);
126127
}
127-
catch (UnsupportedEncodingException e) {
128-
throw new InternalError("\"" + DEFAULT_ENCODING + "\" not supported");
128+
catch (UnsupportedEncodingException ex) {
129+
// should not occur
130+
throw new IllegalStateException(ex);
129131
}
130132
}
131133

132134
/**
133135
* Encode all URI components using their specific encoding rules, and
134136
* returns the result as a new {@code UriComponents} instance.
135137
* @param encoding the encoding of the values contained in this map
136-
* @return the encoded uri components
138+
* @return the encoded URI components
137139
* @throws UnsupportedEncodingException if the given encoding is not supported
138140
*/
139141
public abstract UriComponents encode(String encoding) throws UnsupportedEncodingException;
140142

141143
/**
142-
* Replaces all URI template variables with the values from a given map. The map keys
143-
* represent variable names; the values variable values. The order of variables is not
144-
* significant.
144+
* Replace all URI template variables with the values from a given map.
145+
* <p>The given map keys represent variable names; the corresponding values
146+
* represent variable values. The order of variables is not significant.
145147
* @param uriVariables the map of URI variables
146-
* @return the expanded uri components
148+
* @return the expanded URI components
147149
*/
148150
public final UriComponents expand(Map<String, ?> uriVariables) {
149151
Assert.notNull(uriVariables, "'uriVariables' must not be null");
150152
return expandInternal(new MapTemplateVariables(uriVariables));
151153
}
152154

153155
/**
154-
* Replaces all URI template variables with the values from a given array. The array
155-
* represent variable values. The order of variables is significant.
156-
* @param uriVariableValues URI variable values
157-
* @return the expanded uri components
156+
* Replace all URI template variables with the values from a given array.
157+
* <p>The given array represents variable values. The order of variables is significant.
158+
* @param uriVariableValues the URI variable values
159+
* @return the expanded URI components
158160
*/
159161
public final UriComponents expand(Object... uriVariableValues) {
160162
Assert.notNull(uriVariableValues, "'uriVariableValues' must not be null");
161163
return expandInternal(new VarArgsTemplateVariables(uriVariableValues));
162164
}
163165

164166
/**
165-
* Replaces all URI template variables with the values from the given {@link
166-
* UriTemplateVariables}
167-
* @param uriVariables URI template values
168-
* @return the expanded uri components
167+
* Replace all URI template variables with the values from the given
168+
* {@link UriTemplateVariables}.
169+
* @param uriVariables the URI template values
170+
* @return the expanded URI components
169171
*/
170172
abstract UriComponents expandInternal(UriTemplateVariables uriVariables);
171173

@@ -176,12 +178,12 @@ public final UriComponents expand(Object... uriVariableValues) {
176178
public abstract UriComponents normalize();
177179

178180
/**
179-
* Returns a URI string from this {@code UriComponents} instance.
181+
* Return a URI string from this {@code UriComponents} instance.
180182
*/
181183
public abstract String toUriString();
182184

183185
/**
184-
* Returns a {@code URI} from this {@code UriComponents} instance.
186+
* Return a {@code URI} from this {@code UriComponents} instance.
185187
*/
186188
public abstract URI toUri();
187189

0 commit comments

Comments
 (0)