No need to nest so much.
diff --git a/src/examples/Mini/ASCII_CharStream.java b/src/examples/Mini/ASCII_CharStream.java
index 002032c..c55cb72 100644
--- a/src/examples/Mini/ASCII_CharStream.java
+++ b/src/examples/Mini/ASCII_CharStream.java
@@ -128,9 +128,8 @@
{
inputStream.close();
throw new java.io.IOException();
- } else {
- maxNextCharInd += i;
}
+ maxNextCharInd += i;
return;
}
catch(final java.io.IOException e) {
@@ -307,10 +306,9 @@
{
if (bufpos >= tokenBegin) {
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
- } else {
- return new String(buffer, tokenBegin, bufsize - tokenBegin) +
- new String(buffer, 0, bufpos + 1);
}
+ return new String(buffer, tokenBegin, bufsize - tokenBegin) +
+ new String(buffer, 0, bufpos + 1);
}
static public char[] GetSuffix(final int len)
diff --git a/src/examples/Mini/ASTExpr.java b/src/examples/Mini/ASTExpr.java
index 3c91d31..4e0c1de 100644
--- a/src/examples/Mini/ASTExpr.java
+++ b/src/examples/Mini/ASTExpr.java
@@ -136,13 +136,12 @@
if((kind == -1) && (unop == -1)) {
return exprs[0].traverse(env); // --> Replaced by successor
- } else {
- for(int i=0; i < exprs.length; i++) {
+ }
+ for(int i=0; i < exprs.length; i++) {
exprs[i] = exprs[i].traverse(env); // References may change
}
return this;
- }
}
/**
diff --git a/src/examples/Mini/ASTFactor.java b/src/examples/Mini/ASTFactor.java
index 56f82cd..305e78b 100644
--- a/src/examples/Mini/ASTFactor.java
+++ b/src/examples/Mini/ASTFactor.java
@@ -47,8 +47,7 @@
public ASTExpr traverse(final Environment env) {
if(kind == -1) {
return exprs[0].traverse(env);
- } else {
- return new ASTExpr(exprs, kind, line, column).traverse(env);
}
+ return new ASTExpr(exprs, kind, line, column).traverse(env);
}
}
diff --git a/src/examples/Mini/ASTTerm.java b/src/examples/Mini/ASTTerm.java
index 41936ad..60065a3 100644
--- a/src/examples/Mini/ASTTerm.java
+++ b/src/examples/Mini/ASTTerm.java
@@ -47,8 +47,7 @@
public ASTExpr traverse(final Environment env) {
if(kind == -1) {
return exprs[0].traverse(env);
- } else {
- return new ASTExpr(exprs, kind, line, column).traverse(env);
}
+ return new ASTExpr(exprs, kind, line, column).traverse(env);
}
}
diff --git a/src/examples/Mini/Function.java b/src/examples/Mini/Function.java
index b584a69..6235646 100644
--- a/src/examples/Mini/Function.java
+++ b/src/examples/Mini/Function.java
@@ -62,9 +62,8 @@
if(!reserved) {
return prefix + " declared at line " + line + ", column " + column;
- } else {
- return prefix + " <predefined function>";
}
+ return prefix + " <predefined function>";
}
public int getNoArgs() { return no_args; }
diff --git a/src/examples/Mini/MiniC.java b/src/examples/Mini/MiniC.java
index 4b333d9..5d2e133 100644
--- a/src/examples/Mini/MiniC.java
+++ b/src/examples/Mini/MiniC.java
@@ -168,17 +168,16 @@
final String str = Integer.toString(n);
final int diff = len - str.length();
- if(diff > 0) {
- final char[] chs = new char[diff];
+ if(diff <= 0) {
+ return str;
+ }
+ final char[] chs = new char[diff];
for(int i=0; i < diff; i++) {
chs[i] = ' ';
}
return new String(chs) + str;
- } else {
- return str;
- }
}
final static void addWarning(final String err) { warnings.addElement(err); }
diff --git a/src/examples/Mini/MiniParser.java b/src/examples/Mini/MiniParser.java
index 86c2228..f1921ec 100644
--- a/src/examples/Mini/MiniParser.java
+++ b/src/examples/Mini/MiniParser.java
@@ -1020,9 +1020,8 @@
static private int jj_ntk() {
if ((jj_nt=token.next) == null) {
return (jj_ntk = (token.next=MiniParserTokenManager.getNextToken()).kind);
- } else {
- return (jj_ntk = jj_nt.kind);
}
+ return (jj_ntk = jj_nt.kind);
}
static private java.util.Vector<int[]> jj_expentries = new java.util.Vector<>();
diff --git a/src/examples/Mini/MiniParserTokenManager.java b/src/examples/Mini/MiniParserTokenManager.java
index 93be21f..f5ef6b6 100644
--- a/src/examples/Mini/MiniParserTokenManager.java
+++ b/src/examples/Mini/MiniParserTokenManager.java
@@ -267,13 +267,16 @@
case 61:
if ((active0 & 0x40000L) != 0L) {
return jjStopAtPos(1, 18);
- } else if ((active0 & 0x80000L) != 0L) {
- return jjStopAtPos(1, 19);
- } else if ((active0 & 0x100000L) != 0L) {
- return jjStopAtPos(1, 20);
- } else if ((active0 & 0x200000L) != 0L) {
- return jjStopAtPos(1, 21);
- }
+ }
+ if ((active0 & 0x80000L) != 0L) {
+ return jjStopAtPos(1, 19);
+ }
+ if ((active0 & 0x100000L) != 0L) {
+ return jjStopAtPos(1, 20);
+ }
+ if ((active0 & 0x200000L) != 0L) {
+ return jjStopAtPos(1, 21);
+ }
break;
case 65:
return jjMoveStringLiteralDfa2_0(active0, 0x800000L);
@@ -374,9 +377,10 @@
case 69:
if ((active0 & 0x1000L) != 0L) {
return jjStartNfaWithStates_0(3, 12, 1);
- } else if ((active0 & 0x1000000L) != 0L) {
- return jjStartNfaWithStates_0(3, 24, 1);
}
+ if ((active0 & 0x1000000L) != 0L) {
+ return jjStartNfaWithStates_0(3, 24, 1);
+ }
break;
case 78:
if ((active0 & 0x800L) != 0L) {
@@ -407,9 +411,10 @@
case 69:
if ((active0 & 0x800000L) != 0L) {
return jjStartNfaWithStates_0(4, 23, 1);
- } else if ((active0 & 0x2000000000L) != 0L) {
- return jjStartNfaWithStates_0(4, 37, 1);
}
+ if ((active0 & 0x2000000000L) != 0L) {
+ return jjStartNfaWithStates_0(4, 37, 1);
+ }
break;
default :
break;
@@ -626,9 +631,8 @@
if (lexState >= 2 || lexState < 0) {
throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.",
TokenMgrError.INVALID_LEXICAL_STATE);
-} else {
- curLexState = lexState;
}
+curLexState = lexState;
}
static private Token jjFillToken()
@@ -713,7 +717,7 @@
}
return matchedToken;
}
- else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+ if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
{
if ((jjtoSpecial[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
{
diff --git a/src/examples/Mini/Variable.java b/src/examples/Mini/Variable.java
index 4008645..ff36619 100644
--- a/src/examples/Mini/Variable.java
+++ b/src/examples/Mini/Variable.java
@@ -47,9 +47,8 @@
public String toString() {
if(!reserved) {
return var_name + " declared at line " + line + ", column " + column;
- } else {
- return var_name + " <reserved key word>";
}
+ return var_name + " <reserved key word>";
}
public ASTIdent getName() { return name; }
diff --git a/src/main/java/org/apache/bcel/classfile/LineNumberTable.java b/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
index 961430b..042ebf0 100644
--- a/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
+++ b/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
@@ -168,7 +168,8 @@
final int j = lineNumberTable[i].getStartPC();
if (j == pos) {
return lineNumberTable[i].getLineNumber();
- } else if (pos < j) {
+ }
+ if (pos < j) {
r = i - 1;
} else {
l = i + 1;
diff --git a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
index 9a11104..7118eae 100644
--- a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
+++ b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
@@ -236,33 +236,38 @@
int getMapEntrySize() {
if (frameType >= Const.SAME_FRAME && frameType <= Const.SAME_FRAME_MAX) {
return 1;
- } else if (frameType >= Const.SAME_LOCALS_1_STACK_ITEM_FRAME &&
+ }
+ if (frameType >= Const.SAME_LOCALS_1_STACK_ITEM_FRAME &&
frameType <= Const.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
return 1 + (typesOfStackItems[0].hasIndex() ? 3 : 1);
- } else if (frameType == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
+ }
+ if (frameType == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
return 3 + (typesOfStackItems[0].hasIndex() ? 3 : 1);
- } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX) {
+ }
+ if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX) {
return 3;
- } else if (frameType == Const.SAME_FRAME_EXTENDED) {
+ }
+ if (frameType == Const.SAME_FRAME_EXTENDED) {
return 3;
- } else if (frameType >= Const.APPEND_FRAME && frameType <= Const.APPEND_FRAME_MAX) {
+ }
+ if (frameType >= Const.APPEND_FRAME && frameType <= Const.APPEND_FRAME_MAX) {
int len = 3;
for (final StackMapType types_of_local : typesOfLocals) {
len += types_of_local.hasIndex() ? 3 : 1;
}
return len;
- } else if (frameType == Const.FULL_FRAME) {
- int len = 7;
- for (final StackMapType types_of_local : typesOfLocals) {
- len += types_of_local.hasIndex() ? 3 : 1;
- }
- for (final StackMapType types_of_stack_item : typesOfStackItems) {
- len += types_of_stack_item.hasIndex() ? 3 : 1;
- }
- return len;
- } else {
+ }
+ if (frameType != Const.FULL_FRAME) {
throw new IllegalStateException("Invalid StackMap frameType: " + frameType);
}
+ int len = 7;
+ for (final StackMapType types_of_local : typesOfLocals) {
+ len += types_of_local.hasIndex() ? 3 : 1;
+ }
+ for (final StackMapType types_of_stack_item : typesOfStackItems) {
+ len += types_of_stack_item.hasIndex() ? 3 : 1;
+ }
+ return len;
}
diff --git a/src/main/java/org/apache/bcel/classfile/StackMapType.java b/src/main/java/org/apache/bcel/classfile/StackMapType.java
index 4010642..be47f82 100644
--- a/src/main/java/org/apache/bcel/classfile/StackMapType.java
+++ b/src/main/java/org/apache/bcel/classfile/StackMapType.java
@@ -119,11 +119,11 @@
return ", class=<unknown>";
}
return ", class=" + constantPool.constantToString(index, Const.CONSTANT_Class);
- } else if (type == Const.ITEM_NewObject) {
- return ", offset=" + index;
- } else {
- return "";
}
+ if (type == Const.ITEM_NewObject) {
+ return ", offset=" + index;
+ }
+ return "";
}
diff --git a/src/main/java/org/apache/bcel/generic/BranchInstruction.java b/src/main/java/org/apache/bcel/generic/BranchInstruction.java
index 1413fff..58a7876 100644
--- a/src/main/java/org/apache/bcel/generic/BranchInstruction.java
+++ b/src/main/java/org/apache/bcel/generic/BranchInstruction.java
@@ -226,11 +226,10 @@
*/
@Override
public void updateTarget( final InstructionHandle old_ih, final InstructionHandle new_ih ) {
- if (target == old_ih) {
- setTarget(new_ih);
- } else {
+ if (target != old_ih) {
throw new ClassGenException("Not targeting " + old_ih + ", but " + target);
}
+ setTarget(new_ih);
}
diff --git a/src/main/java/org/apache/bcel/generic/ICONST.java b/src/main/java/org/apache/bcel/generic/ICONST.java
index 7404a3e..33c7d18 100644
--- a/src/main/java/org/apache/bcel/generic/ICONST.java
+++ b/src/main/java/org/apache/bcel/generic/ICONST.java
@@ -38,11 +38,10 @@
public ICONST(final int i) {
super(org.apache.bcel.Const.ICONST_0, (short) 1);
- if ((i >= -1) && (i <= 5)) {
- super.setOpcode((short) (org.apache.bcel.Const.ICONST_0 + i)); // Even works for i == -1
- } else {
+ if ((i < -1) || (i > 5)) {
throw new ClassGenException("ICONST can be used only for value between -1 and 5: " + i);
}
+ super.setOpcode((short) (org.apache.bcel.Const.ICONST_0 + i)); // Even works for i == -1
value = i;
}
diff --git a/src/main/java/org/apache/bcel/generic/InstructionComparator.java b/src/main/java/org/apache/bcel/generic/InstructionComparator.java
index a31e55a..e3f5f53 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionComparator.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionComparator.java
@@ -40,17 +40,19 @@
return false;
// } else if (i1 == i2) { TODO consider adding this shortcut
// return true; // this must be AFTER the BI test
- } else if (i1 instanceof ConstantPushInstruction) {
+ }
+ if (i1 instanceof ConstantPushInstruction) {
return ((ConstantPushInstruction) i1).getValue().equals(
((ConstantPushInstruction) i2).getValue());
- } else if (i1 instanceof IndexedInstruction) {
+ }
+ if (i1 instanceof IndexedInstruction) {
return ((IndexedInstruction) i1).getIndex() == ((IndexedInstruction) i2)
.getIndex();
- } else if (i1 instanceof NEWARRAY) {
- return ((NEWARRAY) i1).getTypecode() == ((NEWARRAY) i2).getTypecode();
- } else {
- return true;
}
+ if (i1 instanceof NEWARRAY) {
+ return ((NEWARRAY) i1).getTypecode() == ((NEWARRAY) i2).getTypecode();
+ }
+ return true;
}
return false;
};
diff --git a/src/main/java/org/apache/bcel/generic/InstructionFactory.java b/src/main/java/org/apache/bcel/generic/InstructionFactory.java
index 74d731b..967f622 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionFactory.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionFactory.java
@@ -621,14 +621,14 @@
throw new IllegalArgumentException("Could not find instruction: " + name, e);
}
return i;
- } else if ((src_type instanceof ReferenceType) && (dest_type instanceof ReferenceType)) {
- if (dest_type instanceof ArrayType) {
- return new CHECKCAST(cp.addArrayClass((ArrayType) dest_type));
- }
- return new CHECKCAST(cp.addClass(((ObjectType) dest_type).getClassName()));
- } else {
+ }
+ if (!(src_type instanceof ReferenceType) || !(dest_type instanceof ReferenceType)) {
throw new IllegalArgumentException("Cannot cast " + src_type + " to " + dest_type);
}
+ if (dest_type instanceof ArrayType) {
+ return new CHECKCAST(cp.addArrayClass((ArrayType) dest_type));
+ }
+ return new CHECKCAST(cp.addClass(((ObjectType) dest_type).getClassName()));
}
@@ -685,11 +685,11 @@
if (dim == 1) {
if (t instanceof ObjectType) {
return new ANEWARRAY(cp.addClass((ObjectType) t));
- } else if (t instanceof ArrayType) {
- return new ANEWARRAY(cp.addArrayClass((ArrayType) t));
- } else {
- return new NEWARRAY(t.getType());
}
+ if (t instanceof ArrayType) {
+ return new ANEWARRAY(cp.addArrayClass((ArrayType) t));
+ }
+ return new NEWARRAY(t.getType());
}
ArrayType at;
if (t instanceof ArrayType) {
diff --git a/src/main/java/org/apache/bcel/generic/InstructionList.java b/src/main/java/org/apache/bcel/generic/InstructionList.java
index 53ce717..15bb377 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionList.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionList.java
@@ -117,7 +117,8 @@
final int j = pos[i];
if (j == target) {
return ihs[i];
- } else if (target < j) {
+ }
+ if (target < j) {
r = i - 1;
} else {
l = i + 1;
@@ -627,7 +628,8 @@
for (InstructionHandle ih = start; ih != end.getNext(); ih = ih.getNext()) {
if (ih == null) {
throw new ClassGenException("Invalid range: From " + start + " to " + end);
- } else if (ih == target) {
+ }
+ if (ih == target) {
throw new ClassGenException("Invalid range: From " + start + " to " + end + " contains target " + target);
}
}
diff --git a/src/main/java/org/apache/bcel/generic/Type.java b/src/main/java/org/apache/bcel/generic/Type.java
index 4c3a6ba..f0d4c05 100644
--- a/src/main/java/org/apache/bcel/generic/Type.java
+++ b/src/main/java/org/apache/bcel/generic/Type.java
@@ -194,24 +194,24 @@
//corrected concurrent private static field acess
wrap(CONSUMED_CHARS, 1);
return BasicType.getType(type);
- } else if (type == Const.T_ARRAY) {
- int dim = 0;
- do { // Count dimensions
- dim++;
- } while (signature.charAt(dim) == '[');
- // Recurse, but just once, if the signature is ok
- final Type t = getType(signature.substring(dim));
- //corrected concurrent private static field acess
- // consumed_chars += dim; // update counter - is replaced by
- final int _temp = unwrap(CONSUMED_CHARS) + dim;
- wrap(CONSUMED_CHARS, _temp);
- return new ArrayType(t, dim);
- } else { // type == T_REFERENCE
+ }
+ if (type != Const.T_ARRAY) { // type == T_REFERENCE
// Utility.typeSignatureToString understands how to parse generic types.
final String parsedSignature = Utility.typeSignatureToString(signature, false);
wrap(CONSUMED_CHARS, parsedSignature.length() + 2); // "Lblabla;" `L' and `;' are removed
return ObjectType.getInstance(parsedSignature.replace('/', '.'));
}
+ int dim = 0;
+ do { // Count dimensions
+ dim++;
+ } while (signature.charAt(dim) == '[');
+ // Recurse, but just once, if the signature is ok
+ final Type t = getType(signature.substring(dim));
+ //corrected concurrent private static field acess
+ // consumed_chars += dim; // update counter - is replaced by
+ final int _temp = unwrap(CONSUMED_CHARS) + dim;
+ wrap(CONSUMED_CHARS, _temp);
+ return new ArrayType(t, dim);
}
@@ -274,33 +274,41 @@
*/
if (cl.isArray()) {
return getType(cl.getName());
- } else if (cl.isPrimitive()) {
- if (cl == Integer.TYPE) {
- return INT;
- } else if (cl == Void.TYPE) {
- return VOID;
- } else if (cl == Double.TYPE) {
- return DOUBLE;
- } else if (cl == Float.TYPE) {
- return FLOAT;
- } else if (cl == Boolean.TYPE) {
- return BOOLEAN;
- } else if (cl == Byte.TYPE) {
- return BYTE;
- } else if (cl == Short.TYPE) {
- return SHORT;
- } else if (cl == Byte.TYPE) {
- return BYTE;
- } else if (cl == Long.TYPE) {
- return LONG;
- } else if (cl == Character.TYPE) {
- return CHAR;
- } else {
- throw new IllegalStateException("Unknown primitive type " + cl);
- }
- } else { // "Real" class
+ }
+ if (!cl.isPrimitive()) { // "Real" class
return ObjectType.getInstance(cl.getName());
}
+ if (cl == Integer.TYPE) {
+ return INT;
+ }
+ if (cl == Void.TYPE) {
+ return VOID;
+ }
+ if (cl == Double.TYPE) {
+ return DOUBLE;
+ }
+ if (cl == Float.TYPE) {
+ return FLOAT;
+ }
+ if (cl == Boolean.TYPE) {
+ return BOOLEAN;
+ }
+ if (cl == Byte.TYPE) {
+ return BYTE;
+ }
+ if (cl == Short.TYPE) {
+ return SHORT;
+ }
+ if (cl == Byte.TYPE) {
+ return BYTE;
+ }
+ if (cl == Long.TYPE) {
+ return LONG;
+ }
+ if (cl == Character.TYPE) {
+ return CHAR;
+ }
+ throw new IllegalStateException("Unknown primitive type " + cl);
}
@@ -365,7 +373,8 @@
final byte type = Utility.typeOfSignature(signature);
if (type <= Const.T_VOID) {
return encode(BasicType.getType(type).getSize(), 1);
- } else if (type == Const.T_ARRAY) {
+ }
+ if (type == Const.T_ARRAY) {
int dim = 0;
do { // Count dimensions
dim++;
@@ -373,13 +382,12 @@
// Recurse, but just once, if the signature is ok
final int consumed = consumed(getTypeSize(signature.substring(dim)));
return encode(1, dim + consumed);
- } else { // type == T_REFERENCE
- final int index = signature.indexOf(';'); // Look for closing `;'
- if (index < 0) {
- throw new ClassFormatException("Invalid signature: " + signature);
- }
- return encode(1, index + 1);
}
+ final int index = signature.indexOf(';'); // Look for closing `;'
+ if (index < 0) {
+ throw new ClassFormatException("Invalid signature: " + signature);
+ }
+ return encode(1, index + 1);
}
diff --git a/src/main/java/org/apache/bcel/util/BCELifier.java b/src/main/java/org/apache/bcel/util/BCELifier.java
index cb34928..9789e7a 100644
--- a/src/main/java/org/apache/bcel/util/BCELifier.java
+++ b/src/main/java/org/apache/bcel/util/BCELifier.java
@@ -261,19 +261,22 @@
final byte t = type.getType();
if (t <= Const.T_VOID) {
return "Type." + Const.getTypeName(t).toUpperCase(Locale.ENGLISH);
- } else if (type.toString().equals("java.lang.String")) {
+ }
+ if (type.toString().equals("java.lang.String")) {
return "Type.STRING";
- } else if (type.toString().equals("java.lang.Object")) {
+ }
+ if (type.toString().equals("java.lang.Object")) {
return "Type.OBJECT";
- } else if (type.toString().equals("java.lang.StringBuffer")) {
+ }
+ if (type.toString().equals("java.lang.StringBuffer")) {
return "Type.STRINGBUFFER";
- } else if (type instanceof ArrayType) {
+ }
+ if (type instanceof ArrayType) {
final ArrayType at = (ArrayType) type;
return "new ArrayType(" + printType(at.getBasicType()) + ", " + at.getDimensions()
+ ")";
- } else {
- return "new ObjectType(\"" + Utility.signatureToString(signature, false) + "\")";
}
+ return "new ObjectType(\"" + Utility.signatureToString(signature, false) + "\")";
}
diff --git a/src/main/java/org/apache/bcel/util/ClassLoader.java b/src/main/java/org/apache/bcel/util/ClassLoader.java
index f63b43a..461b419 100644
--- a/src/main/java/org/apache/bcel/util/ClassLoader.java
+++ b/src/main/java/org/apache/bcel/util/ClassLoader.java
@@ -123,11 +123,10 @@
if (class_name.contains(BCEL_TOKEN)) {
clazz = createClass(class_name);
} else { // Fourth try: Load classes via repository
- if ((clazz = repository.loadClass(class_name)) != null) {
- clazz = modifyClass(clazz);
- } else {
+ if ((clazz = repository.loadClass(class_name)) == null) {
throw new ClassNotFoundException(class_name);
}
+ clazz = modifyClass(clazz);
}
if (clazz != null) {
final byte[] bytes = clazz.getBytes();
diff --git a/src/main/java/org/apache/bcel/util/InstructionFinder.java b/src/main/java/org/apache/bcel/util/InstructionFinder.java
index f93cbe3..ebf10c8 100644
--- a/src/main/java/org/apache/bcel/util/InstructionFinder.java
+++ b/src/main/java/org/apache/bcel/util/InstructionFinder.java
@@ -141,11 +141,10 @@
final StringBuilder name = new StringBuilder();
while ((Character.isLetterOrDigit(ch) || ch == '_') && i < size) {
name.append(ch);
- if (++i < size) {
- ch = lower.charAt(i);
- } else {
+ if (++i >= size) {
break;
}
+ ch = lower.charAt(i);
}
i--;
buf.append(mapName(name.toString()));
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 00ab595..dae1eed 100644
--- a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
+++ b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
@@ -394,12 +394,11 @@
}
if (att instanceof SourceFile) {
- if (!foundSourceFile) {
- foundSourceFile = true;
- } else {
+ if (foundSourceFile) {
throw new ClassConstraintException("A ClassFile structure (like '" +
tostring(obj) + "') may have no more than one SourceFile attribute."); //vmspec2 4.7.7
}
+ foundSourceFile = true;
}
if (att instanceof InnerClasses) {
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 0cb5d6e..92ec820 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
@@ -414,12 +414,10 @@
}
if (o instanceof RETURN) {
- if (method_type != Type.VOID) {
- constraintViolated(o, "RETURN instruction in non-void method.");
- }
- else{
+ if (method_type == Type.VOID) {
return;
}
+ constraintViolated(o, "RETURN instruction in non-void method.");
}
if (o instanceof ARETURN) {
if (method_type == Type.VOID) {
@@ -1003,14 +1001,12 @@
return; // Form 4
}
// stack top size is 2, next-to-top's size is 1
- if ( stack().peek(2).getSize() != 1 ) {
- 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{
+ if ( 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) {
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java b/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java
index eaeecb7..25fa020 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java
@@ -171,14 +171,12 @@
if (! locals[i].equals(lv.locals[i])) { // needed in case of two UninitializedObjectType instances
final Type sup = ((ReferenceType) locals[i]).getFirstCommonSuperclass((ReferenceType) (lv.locals[i]));
- if (sup != null) {
- locals[i] = sup;
- }
- else{
+ if (sup == null) {
// We should have checked this in Pass2!
throw new AssertionViolatedException(
"Could not load all the super classes of '"+locals[i]+"' and '"+lv.locals[i]+"'.");
}
+ locals[i] = sup;
}
}
else{
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/OperandStack.java b/src/main/java/org/apache/bcel/verifier/structurals/OperandStack.java
index 7219165..b6ed81d 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/OperandStack.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/OperandStack.java
@@ -240,14 +240,11 @@
stack.set(i, ((UninitializedObjectType) (stack.get(i))).getInitialized() ); //note that.
}
if (! stack.get(i).equals(s.stack.get(i))) {
- if ( (stack.get(i) instanceof ReferenceType) &&
- (s.stack.get(i) instanceof ReferenceType) ) {
- stack.set(i, ((ReferenceType) stack.get(i)).getFirstCommonSuperclass((ReferenceType) (s.stack.get(i))));
- }
- else{
+ if (!(stack.get(i) instanceof ReferenceType) || !(s.stack.get(i) instanceof ReferenceType) ) {
throw new StructuralCodeConstraintException(
"Cannot merge stacks of different types:\nStack A:\n"+this+"\nStack B:\n"+s);
}
+ stack.set(i, ((ReferenceType) stack.get(i)).getFirstCommonSuperclass((ReferenceType) (s.stack.get(i))));
}
}
} catch (final ClassNotFoundException e) {