Skip to content

Commit 4dae15f

Browse files
author
Niall Kegan Pemberton
committed
Make new charsetName instance variable thread-safe
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@801639 13f79535-47bb-0310-9956-ffa450edef68
1 parent 41cb6aa commit 4dae15f

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

  • src/java/org/apache/commons/codec/binary

src/java/org/apache/commons/codec/binary/Hex.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,25 @@ protected static int toDigit(char ch, int index) throws DecoderException {
167167
return digit;
168168
}
169169

170-
private String charsetName = DEFAULT_CHARSET_NAME;
170+
private final String charsetName;
171171

172172
/**
173173
* Creates a new codec with the default charset name {@link #DEFAULT_CHARSET_NAME}
174174
*/
175175
public Hex() {
176176
// use default encoding
177+
this.charsetName = DEFAULT_CHARSET_NAME;
177178
}
178179

179180
/**
180181
* Creates a new codec with the given charset name.
181182
*
182183
* @param csName
183184
* the charset name.
185+
* @since 1.4
184186
*/
185187
public Hex(String csName) {
186-
setCharsetName(csName);
188+
this.charsetName = csName;
187189
}
188190

189191
/**
@@ -280,21 +282,12 @@ public Object encode(Object object) throws EncoderException {
280282
* Gets the charset name.
281283
*
282284
* @return the charset name.
285+
* @since 1.4
283286
*/
284287
public String getCharsetName() {
285288
return this.charsetName;
286289
}
287290

288-
/**
289-
* Sets the charset name.
290-
*
291-
* @param charsetName
292-
* the charset name.
293-
*/
294-
private void setCharsetName(String charsetName) {
295-
this.charsetName = charsetName;
296-
}
297-
298291
/**
299292
* Returns a string representation of the object, which includes the charset name.
300293
*

0 commit comments

Comments
 (0)