Skip to content

Commit 36b0844

Browse files
committed
Fix PMD violations
1 parent 34d871e commit 36b0844

13 files changed

Lines changed: 1365 additions & 1360 deletions

File tree

src/main/java/org/apache/commons/codec/binary/BaseNCodec.java

Lines changed: 116 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -51,74 +51,6 @@
5151
*/
5252
public abstract class BaseNCodec implements BinaryEncoder, BinaryDecoder {
5353

54-
/**
55-
* Holds thread context so classes can be thread-safe.
56-
*
57-
* This class is not itself thread-safe; each thread must allocate its own copy.
58-
*
59-
* @since 1.7
60-
*/
61-
static class Context {
62-
63-
/**
64-
* Placeholder for the bytes we're dealing with for our based logic.
65-
* Bitwise operations store and extract the encoding or decoding from this variable.
66-
*/
67-
int ibitWorkArea;
68-
69-
/**
70-
* Placeholder for the bytes we're dealing with for our based logic.
71-
* Bitwise operations store and extract the encoding or decoding from this variable.
72-
*/
73-
long lbitWorkArea;
74-
75-
/**
76-
* Buffer for streaming.
77-
*/
78-
byte[] buffer;
79-
80-
/**
81-
* Position where next character should be written in the buffer.
82-
*/
83-
int pos;
84-
85-
/**
86-
* Position where next character should be read from the buffer.
87-
*/
88-
int readPos;
89-
90-
/**
91-
* Boolean flag to indicate the EOF has been reached. Once EOF has been reached, this object becomes useless,
92-
* and must be thrown away.
93-
*/
94-
boolean eof;
95-
96-
/**
97-
* Variable tracks how many characters have been written to the current line. Only used when encoding. We use
98-
* it to make sure each encoded line never goes beyond lineLength (if lineLength > 0).
99-
*/
100-
int currentLinePos;
101-
102-
/**
103-
* Writes to the buffer only occur after every 3/5 reads when encoding, and every 4/8 reads when decoding. This
104-
* variable helps track that.
105-
*/
106-
int modulus;
107-
108-
/**
109-
* Returns a String useful for debugging (especially within a debugger.)
110-
*
111-
* @return a String useful for debugging.
112-
*/
113-
@SuppressWarnings("boxing") // OK to ignore boxing here
114-
@Override
115-
public String toString() {
116-
return String.format("%s[buffer=%s, currentLinePos=%s, eof=%s, ibitWorkArea=%s, lbitWorkArea=%s, " +
117-
"modulus=%s, pos=%s, readPos=%s]", this.getClass().getSimpleName(), Arrays.toString(buffer),
118-
currentLinePos, eof, ibitWorkArea, lbitWorkArea, modulus, pos, readPos);
119-
}
120-
}
121-
12254
/**
12355
* EOF
12456
*
@@ -191,6 +123,122 @@ public String toString() {
191123
*/
192124
static final byte[] CHUNK_SEPARATOR = {'\r', '\n'};
193125

126+
/**
127+
* @deprecated Use {@link #pad}. Will be removed in 2.0.
128+
*/
129+
@Deprecated
130+
protected final byte PAD = PAD_DEFAULT; // instance variable just in case it needs to vary later
131+
132+
/** Pad byte. Instance variable just in case it needs to vary later. */
133+
protected final byte pad;
134+
135+
/** Number of bytes in each full block of unencoded data, e.g. 4 for Base64 and 5 for Base32 */
136+
private final int unencodedBlockSize;
137+
138+
/** Number of bytes in each full block of encoded data, e.g. 3 for Base64 and 8 for Base32 */
139+
private final int encodedBlockSize;
140+
141+
/**
142+
* Chunksize for encoding. Not used when decoding.
143+
* A value of zero or less implies no chunking of the encoded data.
144+
* Rounded down to the nearest multiple of encodedBlockSize.
145+
*/
146+
protected final int lineLength;
147+
148+
/**
149+
* Size of chunk separator. Not used unless {@link #lineLength} > 0.
150+
*/
151+
private final int chunkSeparatorLength;
152+
153+
/**
154+
* Defines the decoding behavior when the input bytes contain leftover trailing bits that
155+
* cannot be created by a valid encoding. These can be bits that are unused from the final
156+
* character or entire characters. The default mode is lenient decoding. Set this to
157+
* {@code true} to enable strict decoding.
158+
* <ul>
159+
* <li>Lenient: Any trailing bits are composed into 8-bit bytes where possible.
160+
* The remainder are discarded.
161+
* <li>Strict: The decoding will raise an {@link IllegalArgumentException} if trailing bits
162+
* are not part of a valid encoding. Any unused bits from the final character must
163+
* be zero. Impossible counts of entire final characters are not allowed.
164+
* </ul>
165+
* <p>
166+
* When strict decoding is enabled it is expected that the decoded bytes will be re-encoded
167+
* to a byte array that matches the original, i.e. no changes occur on the final
168+
* character. This requires that the input bytes use the same padding and alphabet
169+
* as the encoder.
170+
* </p>
171+
*/
172+
private final CodecPolicy decodingPolicy;
173+
174+
/**
175+
* Holds thread context so classes can be thread-safe.
176+
*
177+
* This class is not itself thread-safe; each thread must allocate its own copy.
178+
*
179+
* @since 1.7
180+
*/
181+
static class Context {
182+
183+
/**
184+
* Placeholder for the bytes we're dealing with for our based logic.
185+
* Bitwise operations store and extract the encoding or decoding from this variable.
186+
*/
187+
int ibitWorkArea;
188+
189+
/**
190+
* Placeholder for the bytes we're dealing with for our based logic.
191+
* Bitwise operations store and extract the encoding or decoding from this variable.
192+
*/
193+
long lbitWorkArea;
194+
195+
/**
196+
* Buffer for streaming.
197+
*/
198+
byte[] buffer;
199+
200+
/**
201+
* Position where next character should be written in the buffer.
202+
*/
203+
int pos;
204+
205+
/**
206+
* Position where next character should be read from the buffer.
207+
*/
208+
int readPos;
209+
210+
/**
211+
* Boolean flag to indicate the EOF has been reached. Once EOF has been reached, this object becomes useless,
212+
* and must be thrown away.
213+
*/
214+
boolean eof;
215+
216+
/**
217+
* Variable tracks how many characters have been written to the current line. Only used when encoding. We use
218+
* it to make sure each encoded line never goes beyond lineLength (if lineLength &gt; 0).
219+
*/
220+
int currentLinePos;
221+
222+
/**
223+
* Writes to the buffer only occur after every 3/5 reads when encoding, and every 4/8 reads when decoding. This
224+
* variable helps track that.
225+
*/
226+
int modulus;
227+
228+
/**
229+
* Returns a String useful for debugging (especially within a debugger.)
230+
*
231+
* @return a String useful for debugging.
232+
*/
233+
@SuppressWarnings("boxing") // OK to ignore boxing here
234+
@Override
235+
public String toString() {
236+
return String.format("%s[buffer=%s, currentLinePos=%s, eof=%s, ibitWorkArea=%s, lbitWorkArea=%s, " +
237+
"modulus=%s, pos=%s, readPos=%s]", this.getClass().getSimpleName(), Arrays.toString(buffer),
238+
currentLinePos, eof, ibitWorkArea, lbitWorkArea, modulus, pos, readPos);
239+
}
240+
}
241+
194242
/**
195243
* Create a positive capacity at least as large the minimum required capacity.
196244
* If the minimum capacity is negative then this throws an OutOfMemoryError as no array
@@ -269,54 +317,6 @@ private static byte[] resizeBuffer(final Context context, final int minCapacity)
269317
return b;
270318
}
271319

272-
/**
273-
* @deprecated Use {@link #pad}. Will be removed in 2.0.
274-
*/
275-
@Deprecated
276-
protected final byte PAD = PAD_DEFAULT; // instance variable just in case it needs to vary later
277-
278-
/** Pad byte. Instance variable just in case it needs to vary later. */
279-
protected final byte pad;
280-
281-
/** Number of bytes in each full block of unencoded data, e.g. 4 for Base64 and 5 for Base32 */
282-
private final int unencodedBlockSize;
283-
284-
/** Number of bytes in each full block of encoded data, e.g. 3 for Base64 and 8 for Base32 */
285-
private final int encodedBlockSize;
286-
287-
/**
288-
* Chunksize for encoding. Not used when decoding.
289-
* A value of zero or less implies no chunking of the encoded data.
290-
* Rounded down to the nearest multiple of encodedBlockSize.
291-
*/
292-
protected final int lineLength;
293-
294-
/**
295-
* Size of chunk separator. Not used unless {@link #lineLength} &gt; 0.
296-
*/
297-
private final int chunkSeparatorLength;
298-
299-
/**
300-
* Defines the decoding behavior when the input bytes contain leftover trailing bits that
301-
* cannot be created by a valid encoding. These can be bits that are unused from the final
302-
* character or entire characters. The default mode is lenient decoding. Set this to
303-
* {@code true} to enable strict decoding.
304-
* <ul>
305-
* <li>Lenient: Any trailing bits are composed into 8-bit bytes where possible.
306-
* The remainder are discarded.
307-
* <li>Strict: The decoding will raise an {@link IllegalArgumentException} if trailing bits
308-
* are not part of a valid encoding. Any unused bits from the final character must
309-
* be zero. Impossible counts of entire final characters are not allowed.
310-
* </ul>
311-
* <p>
312-
* When strict decoding is enabled it is expected that the decoded bytes will be re-encoded
313-
* to a byte array that matches the original, i.e. no changes occur on the final
314-
* character. This requires that the input bytes use the same padding and alphabet
315-
* as the encoder.
316-
* </p>
317-
*/
318-
private final CodecPolicy decodingPolicy;
319-
320320
/**
321321
* Note {@code lineLength} is rounded down to the nearest multiple of the encoded block size.
322322
* If {@code chunkSeparatorLength} is zero, then chunking is disabled.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public class Hex implements BinaryEncoder, BinaryDecoder {
6363
private static final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
6464
'E', 'F' };
6565

66+
private final Charset charset;
67+
6668
/**
6769
* Converts an array of characters representing hexadecimal values into an array of bytes of those same values. The
6870
* returned array will be half the length of the passed array, as it takes two characters to represent any given
@@ -371,8 +373,6 @@ protected static int toDigit(final char ch, final int index) throws DecoderExcep
371373
return digit;
372374
}
373375

374-
private final Charset charset;
375-
376376
/**
377377
* Creates a new codec with the default charset name {@link #DEFAULT_CHARSET}
378378
*/

src/main/java/org/apache/commons/codec/cli/Digest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
*/
3636
public class Digest {
3737

38+
private final String algorithm;
39+
private final String[] args;
40+
private final String[] inputs;
41+
3842
/**
3943
* Runs the digest algorithm in {@code args[0]} on the file in {@code args[1]}. If there is no {@code args[1]}, use
4044
* standard input.
@@ -53,10 +57,6 @@ public static void main(final String[] args) throws IOException {
5357
new Digest(args).run();
5458
}
5559

56-
private final String algorithm;
57-
private final String[] args;
58-
private final String[] inputs;
59-
6060
private Digest(final String[] args) {
6161
if (args == null) {
6262
throw new IllegalArgumentException("args");

src/main/java/org/apache/commons/codec/digest/DigestUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public class DigestUtils {
6060

6161
private static final int STREAM_BUFFER_LENGTH = 1024;
6262

63+
private final MessageDigest messageDigest;
64+
6365
/**
6466
* Reads through a byte array and returns the digest for the data. Provided for symmetry with other methods.
6567
*
@@ -1525,8 +1527,6 @@ public static MessageDigest updateDigest(final MessageDigest messageDigest, fina
15251527
return messageDigest;
15261528
}
15271529

1528-
private final MessageDigest messageDigest;
1529-
15301530
/**
15311531
* Preserves binary compatibility only.
15321532
* As for previous versions does not provide useful behavior

src/main/java/org/apache/commons/codec/digest/HmacUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public final class HmacUtils {
5959

6060
private static final int STREAM_BUFFER_LENGTH = 1024;
6161

62+
private final Mac mac;
63+
6264
/**
6365
* Returns whether this algorithm is available
6466
*
@@ -882,8 +884,6 @@ public HmacUtils() {
882884
this(null);
883885
}
884886

885-
private final Mac mac;
886-
887887
private HmacUtils(final Mac mac) {
888888
this.mac = mac;
889889
}

0 commit comments

Comments
 (0)