Commit 982da481 authored by Eric Bruneton's avatar Eric Bruneton
Browse files

Fix some code smells found with SonarQube.

parent c90dd56f
Pipeline #10426 passed with stage
in 8 minutes and 35 seconds
......@@ -316,7 +316,7 @@ public class Analyzer<V extends Value> implements Opcodes {
throws AnalyzerException {
method.maxLocals = computeMaxLocals(method);
method.maxStack = -1;
Frame<V>[] frames = analyze(owner, method);
analyze(owner, method);
method.maxStack = computeMaxStack(frames);
return frames;
}
......
......@@ -45,6 +45,6 @@ public class InsnNodeTest extends AsmTest {
InsnNode insnNode = new InsnNode(Opcodes.ACONST_NULL);
assertEquals(AbstractInsnNode.INSN, insnNode.getType());
assertEquals(insnNode.getOpcode(), Opcodes.ACONST_NULL);
assertEquals(Opcodes.ACONST_NULL, insnNode.getOpcode());
}
}
......@@ -629,9 +629,7 @@ public class ASMifier extends Printer {
@Override
public void visitRecordComponentEnd() {
stringBuilder.setLength(0);
stringBuilder.append(name).append(VISIT_END);
text.add(stringBuilder.toString());
visitMemberEnd();
}
// -----------------------------------------------------------------------------------------------
......@@ -656,9 +654,7 @@ public class ASMifier extends Printer {
@Override
public void visitFieldEnd() {
stringBuilder.setLength(0);
stringBuilder.append(name).append(VISIT_END);
text.add(stringBuilder.toString());
visitMemberEnd();
}
// -----------------------------------------------------------------------------------------------
......@@ -1131,9 +1127,7 @@ public class ASMifier extends Printer {
@Override
public void visitMethodEnd() {
stringBuilder.setLength(0);
stringBuilder.append(name).append(VISIT_END);
text.add(stringBuilder.toString());
visitMemberEnd();
}
// -----------------------------------------------------------------------------------------------
......@@ -1243,6 +1237,13 @@ public class ASMifier extends Printer {
text.add(stringBuilder.toString());
}
/** Visits the end of a field, record component or method. */
private void visitMemberEnd() {
stringBuilder.setLength(0);
stringBuilder.append(name).append(VISIT_END);
text.add(stringBuilder.toString());
}
// -----------------------------------------------------------------------------------------------
// Utility methods
// -----------------------------------------------------------------------------------------------
......
......@@ -999,8 +999,6 @@ public class CheckClassAdapter extends ClassVisitor {
// Can't fix PMD warning for 1.5 compatibility.
try (InputStream inputStream = new FileInputStream(args[0])) { // NOPMD(AvoidFileStream)
classReader = new ClassReader(inputStream);
} catch (IOException ioe) {
throw ioe;
}
} else {
classReader = new ClassReader(args[0]);
......
......@@ -1310,8 +1310,6 @@ public abstract class Printer {
// Can't fix PMD warning for 1.5 compatibility.
try (InputStream inputStream = new FileInputStream(className)) { // NOPMD(AvoidFileStream)
new ClassReader(inputStream).accept(traceClassVisitor, parsingOptions);
} catch (IOException ioe) {
throw ioe;
}
} else {
new ClassReader(className).accept(traceClassVisitor, parsingOptions);
......
......@@ -3458,17 +3458,17 @@ public class ClassReader {
currentAttributeOffset += 6;
if (Constants.BOOTSTRAP_METHODS.equals(attributeName)) {
// Read the num_bootstrap_methods field and create an array of this size.
int[] bootstrapMethodOffsets = new int[readUnsignedShort(currentAttributeOffset)];
int[] result = new int[readUnsignedShort(currentAttributeOffset)];
// Compute and store the offset of each 'bootstrap_methods' array field entry.
int currentBootstrapMethodOffset = currentAttributeOffset + 2;
for (int j = 0; j < bootstrapMethodOffsets.length; ++j) {
bootstrapMethodOffsets[j] = currentBootstrapMethodOffset;
for (int j = 0; j < result.length; ++j) {
result[j] = currentBootstrapMethodOffset;
// Skip the bootstrap_method_ref and num_bootstrap_arguments fields (2 bytes each),
// as well as the bootstrap_arguments array field (of size num_bootstrap_arguments * 2).
currentBootstrapMethodOffset +=
4 + readUnsignedShort(currentBootstrapMethodOffset + 2) * 2;
}
return bootstrapMethodOffsets;
return result;
}
currentAttributeOffset += attributeLength;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment