Skip to content

Commit 69e8bcd

Browse files
committed
Checkstyle updates from ASM master
Issue: SPR-17267
1 parent c385a1d commit 69e8bcd

14 files changed

+513
-462
lines changed

spring-core/src/main/java/org/springframework/asm/ByteVector.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ public ByteVector putLong(final long longValue) {
239239
* @param stringValue a String whose UTF8 encoded length must be less than 65536.
240240
* @return this byte vector.
241241
*/
242+
// DontCheck(AbbreviationAsWordInName): can't be renamed (for backward binary compatibility).
242243
public ByteVector putUTF8(final String stringValue) {
243244
int charLength = stringValue.length();
244245
if (charLength > 65535) {
@@ -261,7 +262,7 @@ public ByteVector putUTF8(final String stringValue) {
261262
currentData[currentLength++] = (byte) charValue;
262263
} else {
263264
length = currentLength;
264-
return encodeUTF8(stringValue, i, 65535);
265+
return encodeUtf8(stringValue, i, 65535);
265266
}
266267
}
267268
length = currentLength;
@@ -280,14 +281,14 @@ public ByteVector putUTF8(final String stringValue) {
280281
* encoded characters.
281282
* @return this byte vector.
282283
*/
283-
final ByteVector encodeUTF8(final String stringValue, final int offset, final int maxByteLength) {
284+
final ByteVector encodeUtf8(final String stringValue, final int offset, final int maxByteLength) {
284285
int charLength = stringValue.length();
285286
int byteLength = offset;
286287
for (int i = offset; i < charLength; ++i) {
287288
char charValue = stringValue.charAt(i);
288-
if (charValue >= '\u0001' && charValue <= '\u007F') {
289+
if (charValue >= 0x0001 && charValue <= 0x007F) {
289290
byteLength++;
290-
} else if (charValue <= '\u07FF') {
291+
} else if (charValue <= 0x07FF) {
291292
byteLength += 2;
292293
} else {
293294
byteLength += 3;
@@ -308,9 +309,9 @@ final ByteVector encodeUTF8(final String stringValue, final int offset, final in
308309
int currentLength = length;
309310
for (int i = offset; i < charLength; ++i) {
310311
char charValue = stringValue.charAt(i);
311-
if (charValue >= '\u0001' && charValue <= '\u007F') {
312+
if (charValue >= 0x0001 && charValue <= 0x007F) {
312313
data[currentLength++] = (byte) charValue;
313-
} else if (charValue <= '\u07FF') {
314+
} else if (charValue <= 0x07FF) {
314315
data[currentLength++] = (byte) (0xC0 | charValue >> 6 & 0x1F);
315316
data[currentLength++] = (byte) (0x80 | charValue & 0x3F);
316317
} else {

spring-core/src/main/java/org/springframework/asm/ClassReader.java

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public class ClassReader {
9999
* necessarily start at offset 0. Use {@link #getItem} and {@link #header} to get correct
100100
* ClassFile element offsets within this byte array.
101101
*/
102+
// DontCheck(MemberName): can't be renamed (for backward binary compatibility).
102103
public final byte[] b;
103104

104105
/**
@@ -488,7 +489,7 @@ public void accept(
488489
accessFlags |= Opcodes.ACC_SYNTHETIC;
489490
} else if (Constants.SOURCE_DEBUG_EXTENSION.equals(attributeName)) {
490491
sourceDebugExtension =
491-
readUTF(currentAttributeOffset, attributeLength, new char[attributeLength]);
492+
readUtf(currentAttributeOffset, attributeLength, new char[attributeLength]);
492493
} else if (Constants.RUNTIME_INVISIBLE_ANNOTATIONS.equals(attributeName)) {
493494
runtimeInvisibleAnnotationsOffset = currentAttributeOffset;
494495
} else if (Constants.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS.equals(attributeName)) {
@@ -530,7 +531,8 @@ public void accept(
530531

531532
// Visit the Module, ModulePackages and ModuleMainClass attributes.
532533
if (moduleOffset != 0) {
533-
readModule(classVisitor, context, moduleOffset, modulePackagesOffset, moduleMainClass);
534+
readModuleAttributes(
535+
classVisitor, context, moduleOffset, modulePackagesOffset, moduleMainClass);
534536
}
535537

536538
// Visit the NestHost attribute.
@@ -685,7 +687,7 @@ public void accept(
685687
// ----------------------------------------------------------------------------------------------
686688

687689
/**
688-
* Reads the module attribute and visit it.
690+
* Reads the Module, ModulePackages and ModuleMainClass attributes and visit them.
689691
*
690692
* @param classVisitor the current class visitor
691693
* @param context information about the class being parsed.
@@ -695,7 +697,7 @@ public void accept(
695697
* attribute_info's attribute_name_index and attribute_length fields), or 0.
696698
* @param moduleMainClass the string corresponding to the ModuleMainClass attribute, or null.
697699
*/
698-
private void readModule(
700+
private void readModuleAttributes(
699701
final ClassVisitor classVisitor,
700702
final Context context,
701703
final int moduleOffset,
@@ -1111,7 +1113,7 @@ private int readMethod(
11111113
context.currentMethodAccessFlags,
11121114
context.currentMethodName,
11131115
context.currentMethodDescriptor,
1114-
signatureIndex == 0 ? null : readUTF(signatureIndex, charBuffer),
1116+
signatureIndex == 0 ? null : readUtf(signatureIndex, charBuffer),
11151117
exceptions);
11161118
if (methodVisitor == null) {
11171119
return currentOffset;
@@ -1601,18 +1603,15 @@ private void readCode(
16011603

16021604
// Read the 'exception_table_length' and 'exception_table' field to create a label for each
16031605
// referenced instruction, and to make methodVisitor visit the corresponding try catch blocks.
1604-
{
1605-
int exceptionTableLength = readUnsignedShort(currentOffset);
1606-
currentOffset += 2;
1607-
while (exceptionTableLength-- > 0) {
1608-
Label start = createLabel(readUnsignedShort(currentOffset), labels);
1609-
Label end = createLabel(readUnsignedShort(currentOffset + 2), labels);
1610-
Label handler = createLabel(readUnsignedShort(currentOffset + 4), labels);
1611-
String catchType =
1612-
readUTF8(cpInfoOffsets[readUnsignedShort(currentOffset + 6)], charBuffer);
1613-
currentOffset += 8;
1614-
methodVisitor.visitTryCatchBlock(start, end, handler, catchType);
1615-
}
1606+
int exceptionTableLength = readUnsignedShort(currentOffset);
1607+
currentOffset += 2;
1608+
while (exceptionTableLength-- > 0) {
1609+
Label start = createLabel(readUnsignedShort(currentOffset), labels);
1610+
Label end = createLabel(readUnsignedShort(currentOffset + 2), labels);
1611+
Label handler = createLabel(readUnsignedShort(currentOffset + 4), labels);
1612+
String catchType = readUTF8(cpInfoOffsets[readUnsignedShort(currentOffset + 6)], charBuffer);
1613+
currentOffset += 8;
1614+
methodVisitor.visitTryCatchBlock(start, end, handler, catchType);
16161615
}
16171616

16181617
// Read the Code attributes to create a label for each referenced instruction (the variables
@@ -2142,11 +2141,11 @@ private void readCode(
21422141
currentOffset += 4 - (currentBytecodeOffset & 3);
21432142
// Read the instruction.
21442143
Label defaultLabel = labels[currentBytecodeOffset + readInt(currentOffset)];
2145-
int nPairs = readInt(currentOffset + 4);
2144+
int numPairs = readInt(currentOffset + 4);
21462145
currentOffset += 8;
2147-
int[] keys = new int[nPairs];
2148-
Label[] values = new Label[nPairs];
2149-
for (int i = 0; i < nPairs; ++i) {
2146+
int[] keys = new int[numPairs];
2147+
Label[] values = new Label[numPairs];
2148+
for (int i = 0; i < numPairs; ++i) {
21502149
keys[i] = readInt(currentOffset);
21512150
values[i] = labels[currentBytecodeOffset + readInt(currentOffset + 4)];
21522151
currentOffset += 8;
@@ -2958,12 +2957,12 @@ private int readElementValue(
29582957
private void computeImplicitFrame(final Context context) {
29592958
String methodDescriptor = context.currentMethodDescriptor;
29602959
Object[] locals = context.currentFrameLocalTypes;
2961-
int nLocal = 0;
2960+
int numLocal = 0;
29622961
if ((context.currentMethodAccessFlags & Opcodes.ACC_STATIC) == 0) {
29632962
if ("<init>".equals(context.currentMethodName)) {
2964-
locals[nLocal++] = Opcodes.UNINITIALIZED_THIS;
2963+
locals[numLocal++] = Opcodes.UNINITIALIZED_THIS;
29652964
} else {
2966-
locals[nLocal++] = readClass(header + 2, context.charBuffer);
2965+
locals[numLocal++] = readClass(header + 2, context.charBuffer);
29672966
}
29682967
}
29692968
// Parse the method descriptor, one argument type descriptor at each iteration. Start by
@@ -2977,16 +2976,16 @@ private void computeImplicitFrame(final Context context) {
29772976
case 'B':
29782977
case 'S':
29792978
case 'I':
2980-
locals[nLocal++] = Opcodes.INTEGER;
2979+
locals[numLocal++] = Opcodes.INTEGER;
29812980
break;
29822981
case 'F':
2983-
locals[nLocal++] = Opcodes.FLOAT;
2982+
locals[numLocal++] = Opcodes.FLOAT;
29842983
break;
29852984
case 'J':
2986-
locals[nLocal++] = Opcodes.LONG;
2985+
locals[numLocal++] = Opcodes.LONG;
29872986
break;
29882987
case 'D':
2989-
locals[nLocal++] = Opcodes.DOUBLE;
2988+
locals[numLocal++] = Opcodes.DOUBLE;
29902989
break;
29912990
case '[':
29922991
while (methodDescriptor.charAt(currentMethodDescritorOffset) == '[') {
@@ -2998,20 +2997,20 @@ private void computeImplicitFrame(final Context context) {
29982997
++currentMethodDescritorOffset;
29992998
}
30002999
}
3001-
locals[nLocal++] =
3000+
locals[numLocal++] =
30023001
methodDescriptor.substring(
30033002
currentArgumentDescriptorStartOffset, ++currentMethodDescritorOffset);
30043003
break;
30053004
case 'L':
30063005
while (methodDescriptor.charAt(currentMethodDescritorOffset) != ';') {
30073006
++currentMethodDescritorOffset;
30083007
}
3009-
locals[nLocal++] =
3008+
locals[numLocal++] =
30103009
methodDescriptor.substring(
30113010
currentArgumentDescriptorStartOffset + 1, currentMethodDescritorOffset++);
30123011
break;
30133012
default:
3014-
context.currentFrameLocalCount = nLocal;
3013+
context.currentFrameLocalCount = numLocal;
30153014
return;
30163015
}
30173016
}
@@ -3178,7 +3177,11 @@ private int readVerificationTypeInfo(
31783177
// Methods to parse attributes
31793178
// ----------------------------------------------------------------------------------------------
31803179

3181-
/** @return the offset in {@link #b} of the first ClassFile's 'attributes' array field entry. */
3180+
/**
3181+
* Returns the offset in {@link #b} of the first ClassFile's 'attributes' array field entry.
3182+
*
3183+
* @return the offset in {@link #b} of the first ClassFile's 'attributes' array field entry.
3184+
*/
31823185
final int getFirstAttributeOffset() {
31833186
// Skip the access_flags, this_class, super_class, and interfaces_count fields (using 2 bytes
31843187
// each), as well as the interfaces array field (2 bytes per interface).
@@ -3399,12 +3402,13 @@ public long readLong(final int offset) {
33993402
* large. It is not automatically resized.
34003403
* @return the String corresponding to the specified CONSTANT_Utf8 entry.
34013404
*/
3405+
// DontCheck(AbbreviationAsWordInName): can't be renamed (for backward binary compatibility).
34023406
public String readUTF8(final int offset, final char[] charBuffer) {
34033407
int constantPoolEntryIndex = readUnsignedShort(offset);
34043408
if (offset == 0 || constantPoolEntryIndex == 0) {
34053409
return null;
34063410
}
3407-
return readUTF(constantPoolEntryIndex, charBuffer);
3411+
return readUtf(constantPoolEntryIndex, charBuffer);
34083412
}
34093413

34103414
/**
@@ -3416,14 +3420,14 @@ public String readUTF8(final int offset, final char[] charBuffer) {
34163420
* large. It is not automatically resized.
34173421
* @return the String corresponding to the specified CONSTANT_Utf8 entry.
34183422
*/
3419-
final String readUTF(final int constantPoolEntryIndex, final char[] charBuffer) {
3423+
final String readUtf(final int constantPoolEntryIndex, final char[] charBuffer) {
34203424
String value = constantUtf8Values[constantPoolEntryIndex];
34213425
if (value != null) {
34223426
return value;
34233427
}
34243428
int cpInfoOffset = cpInfoOffsets[constantPoolEntryIndex];
34253429
return constantUtf8Values[constantPoolEntryIndex] =
3426-
readUTF(cpInfoOffset + 2, readUnsignedShort(cpInfoOffset), charBuffer);
3430+
readUtf(cpInfoOffset + 2, readUnsignedShort(cpInfoOffset), charBuffer);
34273431
}
34283432

34293433
/**
@@ -3435,7 +3439,7 @@ final String readUTF(final int constantPoolEntryIndex, final char[] charBuffer)
34353439
* large. It is not automatically resized.
34363440
* @return the String corresponding to the specified UTF8 string.
34373441
*/
3438-
private String readUTF(final int utfOffset, final int utfLength, final char[] charBuffer) {
3442+
private String readUtf(final int utfOffset, final int utfLength, final char[] charBuffer) {
34393443
int currentOffset = utfOffset;
34403444
int endOffset = currentOffset + utfLength;
34413445
int strLength = 0;

spring-core/src/main/java/org/springframework/asm/ClassTooLargeException.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,20 @@ public ClassTooLargeException(final String className, final int constantPoolCoun
5151
this.constantPoolCount = constantPoolCount;
5252
}
5353

54-
/** @return the internal name of the class. */
54+
/**
55+
* Returns the internal name of the class.
56+
*
57+
* @return the internal name of the class.
58+
*/
5559
public String getClassName() {
5660
return className;
5761
}
5862

59-
/** @return the number of constant pool items of the class. */
63+
/**
64+
* Returns the number of constant pool items of the class.
65+
*
66+
* @return the number of constant pool items of the class.
67+
*/
6068
public int getConstantPoolCount() {
6169
return constantPoolCount;
6270
}

spring-core/src/main/java/org/springframework/asm/ClassWriter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public final void visitSource(final String file, final String debug) {
282282
sourceFileIndex = symbolTable.addConstantUtf8(file);
283283
}
284284
if (debug != null) {
285-
debugExtension = new ByteVector().encodeUTF8(debug, 0, Integer.MAX_VALUE);
285+
debugExtension = new ByteVector().encodeUtf8(debug, 0, Integer.MAX_VALUE);
286286
}
287287
}
288288

@@ -674,7 +674,7 @@ public byte[] toByteArray() throws ClassTooLargeException, MethodTooLargeExcepti
674674
* ones.
675675
*/
676676
private byte[] replaceAsmInstructions(final byte[] classFile, final boolean hasFrames) {
677-
Attribute[] attributes = getAttributePrototypes();
677+
final Attribute[] attributes = getAttributePrototypes();
678678
firstField = null;
679679
lastField = null;
680680
firstMethod = null;
@@ -743,6 +743,7 @@ public int newConst(final Object value) {
743743
* @param value the String value.
744744
* @return the index of a new or already existing UTF8 item.
745745
*/
746+
// DontCheck(AbbreviationAsWordInName): can't be renamed (for backward binary compatibility).
746747
public int newUTF8(final String value) {
747748
return symbolTable.addConstantUtf8(value);
748749
}
@@ -947,13 +948,13 @@ protected String getCommonSuperClass(final String type1, final String type2) {
947948
Class<?> class1;
948949
try {
949950
class1 = Class.forName(type1.replace('/', '.'), false, classLoader);
950-
} catch (Exception e) {
951+
} catch (ClassNotFoundException e) {
951952
throw new TypeNotPresentException(type1, e);
952953
}
953954
Class<?> class2;
954955
try {
955956
class2 = Class.forName(type2.replace('/', '.'), false, classLoader);
956-
} catch (Exception e) {
957+
} catch (ClassNotFoundException e) {
957958
throw new TypeNotPresentException(type2, e);
958959
}
959960
if (class1.isAssignableFrom(class2)) {

spring-core/src/main/java/org/springframework/asm/Constants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
*/
3737
final class Constants implements Opcodes {
3838

39-
private Constants() {}
40-
4139
// The ClassFile attribute names, in the order they are defined in
4240
// https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html#jvms-4.7-300.
4341

@@ -173,4 +171,6 @@ private Constants() {}
173171
static final int ASM_IFNULL = IFNULL + ASM_IFNULL_OPCODE_DELTA;
174172
static final int ASM_IFNONNULL = IFNONNULL + ASM_IFNULL_OPCODE_DELTA;
175173
static final int ASM_GOTO_W = 220;
174+
175+
private Constants() {}
176176
}

0 commit comments

Comments
 (0)