You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/04/09 17:49:26 UTC
[commons-bcel] 01/02: Checkstyle.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
commit a8ba4e82405dc4f636df94af35fb8ed46dc5f260
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Apr 9 13:38:43 2022 -0400
Checkstyle.
---
.../org/apache/bcel/classfile/StackMapEntry.java | 4 +-
.../org/apache/bcel/generic/InstructionList.java | 8 ++--
.../bcel/generic/LocalVariableInstruction.java | 10 ++---
.../bcel/verifier/statics/Pass2Verifier.java | 20 ++++-----
.../verifier/structurals/ControlFlowGraph.java | 6 +--
.../structurals/InstConstraintVisitor.java | 47 +++++++---------------
.../bcel/verifier/structurals/Subroutines.java | 2 +-
7 files changed, 38 insertions(+), 59 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
index d36f8e8c..f953cedb 100644
--- a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
+++ b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
@@ -36,7 +36,7 @@ public final class StackMapEntry implements Node, Cloneable
/**
* Empty array.
*/
- private static final StackMapType[] EMPTY_STACK_MAP_TYPE_ARRAY = new StackMapType[0];
+ private static final StackMapType[] EMPTY_STACK_MAP_TYPE_ARRAY = {};
private int frameType;
private int byteCodeOffset;
@@ -244,7 +244,7 @@ public final class StackMapEntry implements Node, Cloneable
if (frameType == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
return 3 + (typesOfStackItems[0].hasIndex() ? 3 : 1);
}
- if ((frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX) || (frameType == Const.SAME_FRAME_EXTENDED)) {
+ if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX || frameType == Const.SAME_FRAME_EXTENDED) {
return 3;
}
if (frameType >= Const.APPEND_FRAME && frameType <= Const.APPEND_FRAME_MAX) {
diff --git a/src/main/java/org/apache/bcel/generic/InstructionList.java b/src/main/java/org/apache/bcel/generic/InstructionList.java
index 480b436a..d81a3e43 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionList.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionList.java
@@ -113,7 +113,7 @@ public class InstructionList implements Iterable<InstructionHandle> {
* Do a binary search since the pos array is orderd.
*/
do {
- final int i = (l + r) >>> 1;
+ final int i = l + r >>> 1;
final int j = pos[i];
if (j == target) {
return ihs[i];
@@ -619,10 +619,10 @@ public class InstructionList implements Iterable<InstructionHandle> {
*/
public void move(final InstructionHandle start, final InstructionHandle end, final InstructionHandle target) {
// Step 1: Check constraints
- if ((start == null) || (end == null)) {
+ if (start == null || end == null) {
throw new ClassGenException("Invalid null handle: From " + start + " to " + end);
}
- if ((target == start) || (target == end)) {
+ if (target == start || target == end) {
throw new ClassGenException("Invalid range: From " + start + " to " + end + " contains target " + target);
}
for (InstructionHandle ih = start; ih != end.getNext(); ih = ih.getNext()) {
@@ -691,7 +691,7 @@ public class InstructionList implements Iterable<InstructionHandle> {
private void remove(final InstructionHandle prev, InstructionHandle next) throws TargetLostException {
InstructionHandle first;
InstructionHandle last; // First and last deleted instruction
- if ((prev == null) && (next == null)) {
+ if (prev == null && next == null) {
first = start;
last = end;
start = end = null;
diff --git a/src/main/java/org/apache/bcel/generic/LocalVariableInstruction.java b/src/main/java/org/apache/bcel/generic/LocalVariableInstruction.java
index dc52f72d..0acf0ab8 100644
--- a/src/main/java/org/apache/bcel/generic/LocalVariableInstruction.java
+++ b/src/main/java/org/apache/bcel/generic/LocalVariableInstruction.java
@@ -109,8 +109,8 @@ public abstract class LocalVariableInstruction extends Instruction implements Ty
@Override
public String toString( final boolean verbose ) {
final short _opcode = super.getOpcode();
- if (((_opcode >= Const.ILOAD_0) && (_opcode <= Const.ALOAD_3))
- || ((_opcode >= Const.ISTORE_0) && (_opcode <= Const.ASTORE_3))) {
+ if (_opcode >= Const.ILOAD_0 && _opcode <= Const.ALOAD_3
+ || _opcode >= Const.ISTORE_0 && _opcode <= Const.ASTORE_3) {
return super.toString(verbose);
}
return super.toString(verbose) + " " + n;
@@ -130,8 +130,8 @@ public abstract class LocalVariableInstruction extends Instruction implements Ty
super.setLength(4);
} else {
final short _opcode = super.getOpcode();
- if (((_opcode >= Const.ILOAD) && (_opcode <= Const.ALOAD))
- || ((_opcode >= Const.ISTORE) && (_opcode <= Const.ASTORE))) {
+ if (_opcode >= Const.ILOAD && _opcode <= Const.ALOAD
+ || _opcode >= Const.ISTORE && _opcode <= Const.ASTORE) {
n = bytes.readUnsignedByte();
super.setLength(2);
} else if (_opcode <= Const.ALOAD_3) { // compact load instruction such as ILOAD_2
@@ -162,7 +162,7 @@ public abstract class LocalVariableInstruction extends Instruction implements Ty
*/
@Override
public void setIndex( final int n ) { // TODO could be package-protected?
- if ((n < 0) || (n > Const.MAX_SHORT)) {
+ if (n < 0 || n > Const.MAX_SHORT) {
throw new ClassGenException("Illegal value: " + n);
}
this.n = n;
diff --git a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
index 25982a62..06da8970 100644
--- a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
+++ b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
@@ -268,10 +268,8 @@ public final class Pass2Verifier extends PassVerifier implements Constants {
hashmap.put(nameAndSig, jc.getClassName());
}
}
- } else {
- if (!method.isStatic()) { // static methods don't inherit
- hashmap.put(nameAndSig, jc.getClassName());
- }
+ } else if (!method.isStatic()) { // static methods don't inherit
+ hashmap.put(nameAndSig, jc.getClassName());
}
}
@@ -404,13 +402,11 @@ public final class Pass2Verifier extends PassVerifier implements Constants {
if (att instanceof InnerClasses) {
if (!foundInnerClasses) {
foundInnerClasses = true;
- } else {
- if (hasInnerClass) {
- throw new ClassConstraintException("A Classfile structure (like '" + tostring(obj) +
- "') must have exactly one InnerClasses attribute"+
- " if at least one Inner Class is referenced (which is the case)."+
- " More than one InnerClasses attribute was found.");
- }
+ } else if (hasInnerClass) {
+ throw new ClassConstraintException("A Classfile structure (like '" + tostring(obj) +
+ "') must have exactly one InnerClasses attribute"+
+ " if at least one Inner Class is referenced (which is the case)."+
+ " More than one InnerClasses attribute was found.");
}
if (!hasInnerClass) {
addMessage("No referenced Inner Class found, but InnerClasses attribute '" + tostring(att) +
@@ -928,7 +924,7 @@ public final class Pass2Verifier extends PassVerifier implements Constants {
}
final Constant c = cp.getConstant(index);
- if ((CONST_Long.isInstance(c) && field_type.equals(Type.LONG)) || (CONST_Float.isInstance(c) && field_type.equals(Type.FLOAT))) {
+ if (CONST_Long.isInstance(c) && field_type.equals(Type.LONG) || CONST_Float.isInstance(c) && field_type.equals(Type.FLOAT)) {
return;
}
if (CONST_Double.isInstance(c) && field_type.equals(Type.DOUBLE)) {
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java b/src/main/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java
index 749f5372..e2e045b8 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java
@@ -169,8 +169,8 @@ public class ControlFlowGraph{
executionPredecessors = clone;
// sanity check
- if ((lastExecutionJSR() == null && subroutines.subroutineOf(getInstruction()) != subroutines.getTopLevel()) ||
- (lastExecutionJSR() != null && subroutines.subroutineOf(getInstruction()) == subroutines.getTopLevel())) {
+ if (lastExecutionJSR() == null && subroutines.subroutineOf(getInstruction()) != subroutines.getTopLevel() ||
+ lastExecutionJSR() != null && subroutines.subroutineOf(getInstruction()) == subroutines.getTopLevel()) {
throw new AssertionViolatedException("Huh?! Am I '" + this + "' part of a subroutine or not?");
}
@@ -344,7 +344,7 @@ public class ControlFlowGraph{
// Terminates method normally.
// Terminates method abnormally, because JustIce mandates
// subroutines not to be protected by exception handlers.
- if ((inst instanceof ReturnInstruction) || (inst instanceof ATHROW)) {
+ if (inst instanceof ReturnInstruction || inst instanceof ATHROW) {
return InstructionHandle.EMPTY_INSTRUCTION_HANDLE_ARRAY;
}
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
index 246d4892..a64e8437 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
@@ -355,14 +355,12 @@ public class InstConstraintVisitor extends EmptyVisitor{
constraintViolated(o, "Local Variable type and LOADing Instruction type mismatch: Local Variable: '"
+ locals().get(o.getIndex()) + "'; Instruction type: '" + o.getType(cpg) + "'.");
}
- } else { // we deal with an ALOAD
- if (!(locals().get(o.getIndex()) instanceof ReferenceType)) {
- constraintViolated(o, "Local Variable type and LOADing Instruction type mismatch: Local Variable: '"
- + locals().get(o.getIndex()) + "'; Instruction expects a ReferenceType.");
- }
- // ALOAD __IS ALLOWED__ to put uninitialized objects onto the stack!
- // referenceTypeIsInitialized(o, (ReferenceType) (locals().get(o.getIndex())));
+ } else if (!(locals().get(o.getIndex()) instanceof ReferenceType)) {
+ constraintViolated(o, "Local Variable type and LOADing Instruction type mismatch: Local Variable: '"
+ + locals().get(o.getIndex()) + "'; Instruction expects a ReferenceType.");
}
+ // ALOAD __IS ALLOWED__ to put uninitialized objects onto the stack!
+ // referenceTypeIsInitialized(o, (ReferenceType) (locals().get(o.getIndex())));
// LOAD instructions must have enough free stack slots.
if (stack().maxStack() - stack().slotsUsed() < o.getType(cpg).getSize()) {
@@ -437,12 +435,9 @@ public class InstConstraintVisitor extends EmptyVisitor{
// constraintViolated(o, "Type on stack top which should be returned is a '"+stack().peek()+
// "' which is not assignment compatible with the return type of this method, '"+mg.getType()+"'.");
//}
- }
- else{
- if (! method_type.equals( stack().peek() )) {
- constraintViolated(o, "Current method has return type of '"+mg.getType()+"' expecting a '"+method_type+
- "' on top of the stack. But stack top is a '"+stack().peek()+"'.");
- }
+ } else if (! method_type.equals( stack().peek() )) {
+ constraintViolated(o, "Current method has return type of '"+mg.getType()+"' expecting a '"+method_type+
+ "' on top of the stack. But stack top is a '"+stack().peek()+"'.");
}
}
@@ -998,19 +993,14 @@ public class InstConstraintVisitor extends EmptyVisitor{
if (stack().peek(0).getSize() == 2) {
// stack top size is 2, next-to-top's size is 1
- if ( (stack().peek(1).getSize() == 2) || (stack().peek(2).getSize() == 1) ) {
+ if ( stack().peek(1).getSize() == 2 || stack().peek(2).getSize() == 1 ) {
return; // Form 2
}
constraintViolated(o, "If stack top's size is 2 and stack-next-to-top's size is 1,"+
" then stack next-to-next-to-top's size must also be 1. But it is '"+stack().peek(2)+
"' of size '"+stack().peek(2).getSize()+"'.");
- }
- else{// stack top is of size 1
- if (stack().peek(1).getSize() == 1) {
- if ( (stack().peek(2).getSize() == 2) || (stack().peek(3).getSize() == 1)) {
- return; // Form 1
- }
- }
+ } else if ( stack().peek(1).getSize() == 1 && (stack().peek(2).getSize() == 2 || stack().peek(3).getSize() == 1)) {
+ return; // Form 1
}
constraintViolated(o, "The operand sizes on the stack do not match any of the four forms of usage of this instruction.");
}
@@ -2727,11 +2717,8 @@ public class InstConstraintVisitor extends EmptyVisitor{
if (!rvalue.isAssignmentCompatibleWith(shouldbe)) {
constraintViolated(o, "The stack top type '"+value+"' is not assignment compatible with '"+shouldbe+"'.");
}
- }
- else{
- if (shouldbe != value) {
- constraintViolated(o, "The stack top type '"+value+"' is not of type '"+shouldbe+"' as expected.");
- }
+ } else if (shouldbe != value) {
+ constraintViolated(o, "The stack top type '"+value+"' is not of type '"+shouldbe+"' as expected.");
}
if (f.isProtected()) {
@@ -2820,13 +2807,9 @@ public class InstConstraintVisitor extends EmptyVisitor{
constraintViolated(o, "The stack top type '"+value+"' is not assignment compatible with '"+shouldbe+"'.");
}
}
- else{
- if (shouldbe != value) {
- constraintViolated(o, "The stack top type '"+value+"' is not of type '"+shouldbe+"' as expected.");
- }
+ else if (shouldbe != value) {
+ constraintViolated(o, "The stack top type '"+value+"' is not of type '"+shouldbe+"' as expected.");
}
- // TODO: Interface fields may be assigned to only once. (Hard to implement in
- // JustIce's execution model). This may only happen in <clinit>, see Pass 3a.
} catch (final ClassNotFoundException e) {
// FIXME: maybe not the best way to handle this
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java b/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
index e423c624..ce8c5e87 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
@@ -627,7 +627,7 @@ public class Subroutines{
// Terminates method normally.
// Terminates method abnormally, because JustIce mandates
// subroutines not to be protected by exception handlers.
- if ((inst instanceof RET) || (inst instanceof ReturnInstruction) || (inst instanceof ATHROW)) {
+ if (inst instanceof RET || inst instanceof ReturnInstruction || inst instanceof ATHROW) {
return InstructionHandle.EMPTY_INSTRUCTION_HANDLE_ARRAY;
}