Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java?rev=1749600&r1=1749599&r2=1749600&view=diff ============================================================================== --- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java (original) +++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java Tue Jun 21 20:43:38 2016 @@ -134,7 +134,7 @@ public final class Pass3aVerifier extend private Code code; /** Should only be instantiated by a Verifier. */ - public Pass3aVerifier(final Verifier owner, final int method_no){ + public Pass3aVerifier(final Verifier owner, final int method_no) { myOwner = owner; this.method_no = method_no; } @@ -157,21 +157,21 @@ public final class Pass3aVerifier extend * @throws InvalidMethodException if the method to verify does not exist. */ @Override - public VerificationResult do_verify(){ + public VerificationResult do_verify() { try { - if (myOwner.doPass2().equals(VerificationResult.VR_OK)){ + if (myOwner.doPass2().equals(VerificationResult.VR_OK)) { // Okay, class file was loaded correctly by Pass 1 // and satisfies static constraints of Pass 2. JavaClass jc = Repository.lookupClass(myOwner.getClassName()); Method[] methods = jc.getMethods(); - if (method_no >= methods.length){ + if (method_no >= methods.length) { throw new InvalidMethodException("METHOD DOES NOT EXIST!"); } Method method = methods[method_no]; code = method.getCode(); // No Code? Nothing to verify! - if ( method.isAbstract() || method.isNative() ){ // IF mg HAS NO CODE (static constraint of Pass 2) + if ( method.isAbstract() || method.isNative() ) { // IF mg HAS NO CODE (static constraint of Pass 2) return VerificationResult.VR_OK; } @@ -187,7 +187,7 @@ public final class Pass3aVerifier extend try{ instructionList = new InstructionList(method.getCode().getCode()); } - catch(RuntimeException re){ + catch(RuntimeException re) { return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Bad bytecode in the code array of the Code attribute of method '"+method+"'."); } @@ -199,7 +199,7 @@ public final class Pass3aVerifier extend try{ delayedPass2Checks(); } - catch(ClassConstraintException cce){ + catch(ClassConstraintException cce) { vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, cce.getMessage()); return vr; } @@ -207,10 +207,10 @@ public final class Pass3aVerifier extend pass3StaticInstructionChecks(); pass3StaticInstructionOperandsChecks(); } - catch(StaticCodeConstraintException scce){ + catch(StaticCodeConstraintException scce) { vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, scce.getMessage()); } - catch(ClassCastException cce){ + catch(ClassCastException cce) { vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Class Cast Exception: " + cce.getMessage()); } return vr; @@ -232,7 +232,7 @@ public final class Pass3aVerifier extend * @throws ClassConstraintException if the verification fails. * @see #do_verify() */ - private void delayedPass2Checks(){ + private void delayedPass2Checks() { int[] instructionPositions = instructionList.getInstructionPositions(); int codeLength = code.getCode().length; @@ -241,7 +241,7 @@ public final class Pass3aVerifier extend // LineNumberTable // ///////////////////// LineNumberTable lnt = code.getLineNumberTable(); - if (lnt != null){ + if (lnt != null) { LineNumber[] lineNumbers = lnt.getLineNumberTable(); IntList offsets = new IntList(); lineNumber_loop: @@ -306,20 +306,20 @@ public final class Pass3aVerifier extend int startpc = element.getStartPC(); int endpc = element.getEndPC(); int handlerpc = element.getHandlerPC(); - if (startpc >= endpc){ + if (startpc >= endpc) { throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+element+ "' that has its start_pc ('"+startpc+"') not smaller than its end_pc ('"+endpc+"')."); } - if (!contains(instructionPositions, startpc)){ + if (!contains(instructionPositions, startpc)) { throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+element+ "' that has a non-existant bytecode offset as its start_pc ('"+startpc+"')."); } - if ( (!contains(instructionPositions, endpc)) && (endpc != codeLength)){ + if ( (!contains(instructionPositions, endpc)) && (endpc != codeLength)) { throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+element+ "' that has a non-existant bytecode offset as its end_pc ('"+startpc+ "') [that is also not equal to code_length ('"+codeLength+"')]."); } - if (!contains(instructionPositions, handlerpc)){ + if (!contains(instructionPositions, handlerpc)) { throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+element+ "' that has a non-existant bytecode offset as its handler_pc ('"+handlerpc+"')."); } @@ -333,14 +333,14 @@ public final class Pass3aVerifier extend * * @throws StaticCodeConstraintException if the verification fails. */ - private void pass3StaticInstructionChecks(){ + private void pass3StaticInstructionChecks() { // Code array must not be empty: // Enforced in pass 2 (also stated in the static constraints of the Code // array in vmspec2), together with pass 1 (reading code_length bytes and // interpreting them as code[]). So this must not be checked again here. - if (code.getCode().length >= Const.MAX_CODE_SIZE){// length must be LESS than the max + if (code.getCode().length >= Const.MAX_CODE_SIZE) {// length must be LESS than the max throw new StaticCodeInstructionConstraintException( "Code array in code attribute '"+code+"' too big: must be smaller than "+Const.MAX_CODE_SIZE+"65536 bytes."); } @@ -361,17 +361,17 @@ public final class Pass3aVerifier extend // BREAKPOINT... that BCEL knows about but which are illegal anyway. // We currently go the safe way here. InstructionHandle ih = instructionList.getStart(); - while (ih != null){ + while (ih != null) { Instruction i = ih.getInstruction(); - if (i instanceof IMPDEP1){ + if (i instanceof IMPDEP1) { throw new StaticCodeInstructionConstraintException( "IMPDEP1 must not be in the code, it is an illegal instruction for _internal_ JVM use!"); } - if (i instanceof IMPDEP2){ + if (i instanceof IMPDEP2) { throw new StaticCodeInstructionConstraintException( "IMPDEP2 must not be in the code, it is an illegal instruction for _internal_ JVM use!"); } - if (i instanceof BREAKPOINT){ + if (i instanceof BREAKPOINT) { throw new StaticCodeInstructionConstraintException( "BREAKPOINT must not be in the code, it is an illegal instruction for _internal_ JVM use!"); } @@ -403,7 +403,7 @@ public final class Pass3aVerifier extend * * @throws StaticCodeConstraintException if the verification fails. */ - private void pass3StaticInstructionOperandsChecks(){ + private void pass3StaticInstructionOperandsChecks() { try { // When building up the InstructionList, BCEL has already done all those checks // mentioned in The Java Virtual Machine Specification, Second Edition, as @@ -421,18 +421,18 @@ public final class Pass3aVerifier extend // Checks for the things BCEL does _not_ handle itself. InstructionHandle ih = instructionList.getStart(); - while (ih != null){ + while (ih != null) { Instruction i = ih.getInstruction(); // An "own" constraint, due to JustIce's new definition of what "subroutine" means. - if (i instanceof JsrInstruction){ + if (i instanceof JsrInstruction) { InstructionHandle target = ((JsrInstruction) i).getTarget(); - if (target == instructionList.getStart()){ + if (target == instructionList.getStart()) { throw new StaticCodeInstructionOperandConstraintException( "Due to JustIce's clear definition of subroutines, no JSR or JSR_W may have a top-level instruction"+ " (such as the very first instruction, which is targeted by instruction '"+ih+"' as its target."); } - if (!(target.getInstruction() instanceof ASTORE)){ + if (!(target.getInstruction() instanceof ASTORE)) { throw new StaticCodeInstructionOperandConstraintException( "Due to JustIce's clear definition of subroutines, no JSR or JSR_W may target anything else"+ " than an ASTORE instruction. Instruction '"+ih+"' targets '"+target+"'."); @@ -452,7 +452,7 @@ public final class Pass3aVerifier extend } /** A small utility method returning if a given int i is in the given int[] ints. */ - private static boolean contains(final int[] ints, final int i){ + private static boolean contains(final int[] ints, final int i) { for (int k : ints) { if (k==i) { return true; @@ -462,7 +462,7 @@ public final class Pass3aVerifier extend } /** Returns the method number as supplied when instantiating. */ - public int getMethodNo(){ + public int getMethodNo() { return method_no; } @@ -475,7 +475,7 @@ public final class Pass3aVerifier extend private final ConstantPoolGen cpg; /** The only Constructor. */ - InstOperandConstraintVisitor(final ConstantPoolGen cpg){ + InstOperandConstraintVisitor(final ConstantPoolGen cpg) { this.cpg = cpg; } @@ -483,7 +483,7 @@ public final class Pass3aVerifier extend * Utility method to return the max_locals value of the method verified * by the surrounding Pass3aVerifier instance. */ - private int max_locals(){ + private int max_locals() { try { return Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getCode().getMaxLocals(); } catch (ClassNotFoundException e) { @@ -503,8 +503,8 @@ public final class Pass3aVerifier extend * A utility method to raise an exception if the index is not * a valid constant pool index. */ - private void indexValid(final Instruction i, final int idx){ - if (idx < 0 || idx >= cpg.getSize()){ + private void indexValid(final Instruction i, final int idx) { + if (idx < 0 || idx >= cpg.getSize()) { constraintViolated(i, "Illegal constant pool index '"+idx+"'."); } } @@ -517,12 +517,12 @@ public final class Pass3aVerifier extend * The referenced class is loaded and pass2-verified. */ @Override - public void visitLoadClass(final LoadClass o){ + public void visitLoadClass(final LoadClass o) { ObjectType t = o.getLoadClassType(cpg); - if (t != null){// null means "no class is loaded" + if (t != null) {// null means "no class is loaded" Verifier v = VerifierFactory.getVerifier(t.getClassName()); VerificationResult vr = v.doPass1(); - if (vr.getStatus() != VerificationResult.VERIFIED_OK){ + if (vr.getStatus() != VerificationResult.VERIFIED_OK) { constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded: '"+vr+"'."); } @@ -539,16 +539,16 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ // LDC and LDC_W (LDC_W is a subclass of LDC in BCEL's model) @Override - public void visitLDC(final LDC o){ + public void visitLDC(final LDC o) { indexValid(o, o.getIndex()); Constant c = cpg.getConstant(o.getIndex()); - if (c instanceof ConstantClass){ + if (c instanceof ConstantClass) { addMessage("Operand of LDC or LDC_W is CONSTANT_Class '"+c+"' - this is only supported in JDK 1.5 and higher."); } else{ if (! ( (c instanceof ConstantInteger) || (c instanceof ConstantFloat) || - (c instanceof ConstantString) ) ){ + (c instanceof ConstantString) ) ) { constraintViolated(o, "Operand of LDC or LDC_W must be one of CONSTANT_Integer, CONSTANT_Float or CONSTANT_String, but is '"+c+"'."); } @@ -558,17 +558,17 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ // LDC2_W @Override - public void visitLDC2_W(final LDC2_W o){ + public void visitLDC2_W(final LDC2_W o) { indexValid(o, o.getIndex()); Constant c = cpg.getConstant(o.getIndex()); if (! ( (c instanceof ConstantLong) || - (c instanceof ConstantDouble) ) ){ + (c instanceof ConstantDouble) ) ) { constraintViolated(o, "Operand of LDC2_W must be CONSTANT_Long or CONSTANT_Double, but is '"+c+"'."); } try{ indexValid(o, o.getIndex()+1); } - catch(StaticCodeInstructionOperandConstraintException e){ + catch(StaticCodeInstructionOperandConstraintException e) { throw new AssertionViolatedException("OOPS: Does not BCEL handle that? LDC2_W operand has a problem.", e); } } @@ -585,11 +585,11 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ //getfield, putfield, getstatic, putstatic @Override - public void visitFieldInstruction(final FieldInstruction o){ + public void visitFieldInstruction(final FieldInstruction o) { try { indexValid(o, o.getIndex()); Constant c = cpg.getConstant(o.getIndex()); - if (! (c instanceof ConstantFieldref)){ + if (! (c instanceof ConstantFieldref)) { constraintViolated(o, "Indexing a constant that's not a CONSTANT_Fieldref but a '"+c+"'."); } @@ -599,19 +599,19 @@ public final class Pass3aVerifier extend Field[] fields = jc.getFields(); Field f = null; for (Field field : fields) { - if (field.getName().equals(field_name)){ + if (field.getName().equals(field_name)) { Type f_type = Type.getType(field.getSignature()); Type o_type = o.getType(cpg); /* TODO: Check if assignment compatibility is sufficient. * What does Sun do? */ - if (f_type.equals(o_type)){ + if (f_type.equals(o_type)) { f = field; break; } } } - if (f == null){ + if (f == null) { JavaClass[] superclasses = jc.getSuperClasses(); outer: for (JavaClass superclass : superclasses) { @@ -644,7 +644,7 @@ public final class Pass3aVerifier extend // Argh. Sun's implementation allows us to have multiple fields of // the same name but with a different signature. - //if (! f_type.equals(o_type)){ + //if (! f_type.equals(o_type)) { // constraintViolated(o, // "Referenced field '"+field_name+"' has type '"+f_type+"' instead of '"+o_type+"' as expected."); //} @@ -659,32 +659,32 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitInvokeInstruction(final InvokeInstruction o){ + public void visitInvokeInstruction(final InvokeInstruction o) { indexValid(o, o.getIndex()); if ( (o instanceof INVOKEVIRTUAL) || (o instanceof INVOKESPECIAL) || - (o instanceof INVOKESTATIC) ){ + (o instanceof INVOKESTATIC) ) { Constant c = cpg.getConstant(o.getIndex()); - if (! (c instanceof ConstantMethodref)){ + if (! (c instanceof ConstantMethodref)) { constraintViolated(o, "Indexing a constant that's not a CONSTANT_Methodref but a '"+c+"'."); } else{ // Constants are okay due to pass2. ConstantNameAndType cnat = (ConstantNameAndType) (cpg.getConstant(((ConstantMethodref) c).getNameAndTypeIndex())); ConstantUtf8 cutf8 = (ConstantUtf8) (cpg.getConstant(cnat.getNameIndex())); - if (cutf8.getBytes().equals(Const.CONSTRUCTOR_NAME) && (!(o instanceof INVOKESPECIAL)) ){ + if (cutf8.getBytes().equals(Const.CONSTRUCTOR_NAME) && (!(o instanceof INVOKESPECIAL)) ) { constraintViolated(o, "Only INVOKESPECIAL is allowed to invoke instance initialization methods."); } - if ( (! (cutf8.getBytes().equals(Const.CONSTRUCTOR_NAME)) ) && (cutf8.getBytes().startsWith("<")) ){ + if ( (! (cutf8.getBytes().equals(Const.CONSTRUCTOR_NAME)) ) && (cutf8.getBytes().startsWith("<")) ) { constraintViolated(o, "No method with a name beginning with '<' other than the instance initialization methods"+ " may be called by the method invocation instructions."); } } } - else{ //if (o instanceof INVOKEINTERFACE){ + else{ //if (o instanceof INVOKEINTERFACE) { Constant c = cpg.getConstant(o.getIndex()); - if (! (c instanceof ConstantInterfaceMethodref)){ + if (! (c instanceof ConstantInterfaceMethodref)) { constraintViolated(o, "Indexing a constant that's not a CONSTANT_InterfaceMethodref but a '"+c+"'."); } // TODO: From time to time check if BCEL allows to detect if the @@ -696,10 +696,10 @@ public final class Pass3aVerifier extend ConstantNameAndType cnat = (ConstantNameAndType) (cpg.getConstant(((ConstantInterfaceMethodref)c).getNameAndTypeIndex())); String name = ((ConstantUtf8) (cpg.getConstant(cnat.getNameIndex()))).getBytes(); - if (name.equals(Const.CONSTRUCTOR_NAME)){ + if (name.equals(Const.CONSTRUCTOR_NAME)) { constraintViolated(o, "Method to invoke must not be '"+Const.CONSTRUCTOR_NAME+"'."); } - if (name.equals(Const.STATIC_INITIALIZER_NAME)){ + if (name.equals(Const.STATIC_INITIALIZER_NAME)) { constraintViolated(o, "Method to invoke must not be '"+Const.STATIC_INITIALIZER_NAME+"'."); } } @@ -707,13 +707,13 @@ public final class Pass3aVerifier extend // The LoadClassType is the method-declaring class, so we have to check the other types. Type t = o.getReturnType(cpg); - if (t instanceof ArrayType){ + if (t instanceof ArrayType) { t = ((ArrayType) t).getBasicType(); } - if (t instanceof ObjectType){ + if (t instanceof ObjectType) { Verifier v = VerifierFactory.getVerifier(((ObjectType) t).getClassName()); VerificationResult vr = v.doPass2(); - if (vr.getStatus() != VerificationResult.VERIFIED_OK){ + if (vr.getStatus() != VerificationResult.VERIFIED_OK) { constraintViolated(o, "Return type class/interface could not be verified successfully: '"+vr.getMessage()+"'."); } } @@ -721,13 +721,13 @@ public final class Pass3aVerifier extend Type[] ts = o.getArgumentTypes(cpg); for (Type element : ts) { t = element; - if (t instanceof ArrayType){ + if (t instanceof ArrayType) { t = ((ArrayType) t).getBasicType(); } - if (t instanceof ObjectType){ + if (t instanceof ObjectType) { Verifier v = VerifierFactory.getVerifier(((ObjectType) t).getClassName()); VerificationResult vr = v.doPass2(); - if (vr.getStatus() != VerificationResult.VERIFIED_OK){ + if (vr.getStatus() != VerificationResult.VERIFIED_OK) { constraintViolated(o, "Argument type class/interface could not be verified successfully: '"+vr.getMessage()+"'."); } @@ -738,36 +738,36 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitINSTANCEOF(final INSTANCEOF o){ + public void visitINSTANCEOF(final INSTANCEOF o) { indexValid(o, o.getIndex()); Constant c = cpg.getConstant(o.getIndex()); - if (! (c instanceof ConstantClass)){ + if (! (c instanceof ConstantClass)) { constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'."); } } /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitCHECKCAST(final CHECKCAST o){ + public void visitCHECKCAST(final CHECKCAST o) { indexValid(o, o.getIndex()); Constant c = cpg.getConstant(o.getIndex()); - if (! (c instanceof ConstantClass)){ + if (! (c instanceof ConstantClass)) { constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'."); } } /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitNEW(final NEW o){ + public void visitNEW(final NEW o) { indexValid(o, o.getIndex()); Constant c = cpg.getConstant(o.getIndex()); - if (! (c instanceof ConstantClass)){ + if (! (c instanceof ConstantClass)) { constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'."); } else{ ConstantUtf8 cutf8 = (ConstantUtf8) (cpg.getConstant( ((ConstantClass) c).getNameIndex() )); Type t = Type.getType("L"+cutf8.getBytes()+";"); - if (t instanceof ArrayType){ + if (t instanceof ArrayType) { constraintViolated(o, "NEW must not be used to create an array."); } } @@ -776,20 +776,20 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitMULTIANEWARRAY(final MULTIANEWARRAY o){ + public void visitMULTIANEWARRAY(final MULTIANEWARRAY o) { indexValid(o, o.getIndex()); Constant c = cpg.getConstant(o.getIndex()); - if (! (c instanceof ConstantClass)){ + if (! (c instanceof ConstantClass)) { constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'."); } int dimensions2create = o.getDimensions(); - if (dimensions2create < 1){ + if (dimensions2create < 1) { constraintViolated(o, "Number of dimensions to create must be greater than zero."); } Type t = o.getType(cpg); - if (t instanceof ArrayType){ + if (t instanceof ArrayType) { int dimensions = ((ArrayType) t).getDimensions(); - if (dimensions < dimensions2create){ + if (dimensions < dimensions2create) { constraintViolated(o, "Not allowed to create array with more dimensions ('"+dimensions2create+ "') than the one referenced by the CONSTANT_Class '"+t+"'."); @@ -803,16 +803,16 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitANEWARRAY(final ANEWARRAY o){ + public void visitANEWARRAY(final ANEWARRAY o) { indexValid(o, o.getIndex()); Constant c = cpg.getConstant(o.getIndex()); - if (! (c instanceof ConstantClass)){ + if (! (c instanceof ConstantClass)) { constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'."); } Type t = o.getType(cpg); - if (t instanceof ArrayType){ + if (t instanceof ArrayType) { int dimensions = ((ArrayType) t).getDimensions(); - if (dimensions > Const.MAX_ARRAY_DIMENSIONS){ + if (dimensions > Const.MAX_ARRAY_DIMENSIONS) { constraintViolated(o, "Not allowed to create an array with more than "+ Const.MAX_ARRAY_DIMENSIONS + " dimensions;"+ " actual: " + dimensions); @@ -822,7 +822,7 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitNEWARRAY(final NEWARRAY o){ + public void visitNEWARRAY(final NEWARRAY o) { byte t = o.getTypecode(); if (! ( (t == Const.T_BOOLEAN) || (t == Const.T_CHAR) || @@ -831,21 +831,21 @@ public final class Pass3aVerifier extend (t == Const.T_BYTE) || (t == Const.T_SHORT) || (t == Const.T_INT) || - (t == Const.T_LONG) ) ){ + (t == Const.T_LONG) ) ) { constraintViolated(o, "Illegal type code '+t+' for 'atype' operand."); } } /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitILOAD(final ILOAD o){ + public void visitILOAD(final ILOAD o) { int idx = o.getIndex(); - if (idx < 0){ + if (idx < 0) { constraintViolated(o, "Index '"+idx+"' must be non-negative."); } else{ int maxminus1 = max_locals()-1; - if (idx > maxminus1){ + if (idx > maxminus1) { constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); } } @@ -853,14 +853,14 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitFLOAD(final FLOAD o){ + public void visitFLOAD(final FLOAD o) { int idx = o.getIndex(); - if (idx < 0){ + if (idx < 0) { constraintViolated(o, "Index '"+idx+"' must be non-negative."); } else{ int maxminus1 = max_locals()-1; - if (idx > maxminus1){ + if (idx > maxminus1) { constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); } } @@ -868,14 +868,14 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitALOAD(final ALOAD o){ + public void visitALOAD(final ALOAD o) { int idx = o.getIndex(); - if (idx < 0){ + if (idx < 0) { constraintViolated(o, "Index '"+idx+"' must be non-negative."); } else{ int maxminus1 = max_locals()-1; - if (idx > maxminus1){ + if (idx > maxminus1) { constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); } } @@ -883,14 +883,14 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitISTORE(final ISTORE o){ + public void visitISTORE(final ISTORE o) { int idx = o.getIndex(); - if (idx < 0){ + if (idx < 0) { constraintViolated(o, "Index '"+idx+"' must be non-negative."); } else{ int maxminus1 = max_locals()-1; - if (idx > maxminus1){ + if (idx > maxminus1) { constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); } } @@ -898,14 +898,14 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitFSTORE(final FSTORE o){ + public void visitFSTORE(final FSTORE o) { int idx = o.getIndex(); - if (idx < 0){ + if (idx < 0) { constraintViolated(o, "Index '"+idx+"' must be non-negative."); } else{ int maxminus1 = max_locals()-1; - if (idx > maxminus1){ + if (idx > maxminus1) { constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); } } @@ -913,14 +913,14 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitASTORE(final ASTORE o){ + public void visitASTORE(final ASTORE o) { int idx = o.getIndex(); - if (idx < 0){ + if (idx < 0) { constraintViolated(o, "Index '"+idx+"' must be non-negative."); } else{ int maxminus1 = max_locals()-1; - if (idx > maxminus1){ + if (idx > maxminus1) { constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); } } @@ -928,14 +928,14 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitIINC(final IINC o){ + public void visitIINC(final IINC o) { int idx = o.getIndex(); - if (idx < 0){ + if (idx < 0) { constraintViolated(o, "Index '"+idx+"' must be non-negative."); } else{ int maxminus1 = max_locals()-1; - if (idx > maxminus1){ + if (idx > maxminus1) { constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); } } @@ -943,14 +943,14 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitRET(final RET o){ + public void visitRET(final RET o) { int idx = o.getIndex(); - if (idx < 0){ + if (idx < 0) { constraintViolated(o, "Index '"+idx+"' must be non-negative."); } else{ int maxminus1 = max_locals()-1; - if (idx > maxminus1){ + if (idx > maxminus1) { constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); } } @@ -958,15 +958,15 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitLLOAD(final LLOAD o){ + public void visitLLOAD(final LLOAD o) { int idx = o.getIndex(); - if (idx < 0){ + if (idx < 0) { constraintViolated(o, "Index '"+idx+"' must be non-negative."+ " [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]"); } else{ int maxminus2 = max_locals()-2; - if (idx > maxminus2){ + if (idx > maxminus2) { constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'."); } } @@ -974,15 +974,15 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitDLOAD(final DLOAD o){ + public void visitDLOAD(final DLOAD o) { int idx = o.getIndex(); - if (idx < 0){ + if (idx < 0) { constraintViolated(o, "Index '"+idx+"' must be non-negative."+ " [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]"); } else{ int maxminus2 = max_locals()-2; - if (idx > maxminus2){ + if (idx > maxminus2) { constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'."); } } @@ -990,15 +990,15 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitLSTORE(final LSTORE o){ + public void visitLSTORE(final LSTORE o) { int idx = o.getIndex(); - if (idx < 0){ + if (idx < 0) { constraintViolated(o, "Index '"+idx+"' must be non-negative."+ " [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]"); } else{ int maxminus2 = max_locals()-2; - if (idx > maxminus2){ + if (idx > maxminus2) { constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'."); } } @@ -1006,15 +1006,15 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitDSTORE(final DSTORE o){ + public void visitDSTORE(final DSTORE o) { int idx = o.getIndex(); - if (idx < 0){ + if (idx < 0) { constraintViolated(o, "Index '"+idx+"' must be non-negative."+ " [Constraint by JustIce as an analogon to the single-slot xLOAD/xSTORE instructions; may not happen anyway.]"); } else{ int maxminus2 = max_locals()-2; - if (idx > maxminus2){ + if (idx > maxminus2) { constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-2 '"+maxminus2+"'."); } } @@ -1022,14 +1022,14 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitLOOKUPSWITCH(final LOOKUPSWITCH o){ + public void visitLOOKUPSWITCH(final LOOKUPSWITCH o) { int[] matchs = o.getMatchs(); int max = Integer.MIN_VALUE; - for (int i=0; i<matchs.length; i++){ - if (matchs[i] == max && i != 0){ + for (int i=0; i<matchs.length; i++) { + if (matchs[i] == max && i != 0) { constraintViolated(o, "Match '"+matchs[i]+"' occurs more than once."); } - if (matchs[i] < max){ + if (matchs[i] < max) { constraintViolated(o, "Lookup table must be sorted but isn't."); } else{ @@ -1040,45 +1040,45 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitTABLESWITCH(final TABLESWITCH o){ + public void visitTABLESWITCH(final TABLESWITCH o) { // "high" must be >= "low". We cannot check this, as BCEL hides // it from us. } /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitPUTSTATIC(final PUTSTATIC o){ + public void visitPUTSTATIC(final PUTSTATIC o) { try { String field_name = o.getFieldName(cpg); JavaClass jc = Repository.lookupClass(getObjectType(o).getClassName()); Field[] fields = jc.getFields(); Field f = null; for (Field field : fields) { - if (field.getName().equals(field_name)){ + if (field.getName().equals(field_name)) { f = field; break; } } - if (f == null){ + if (f == null) { throw new AssertionViolatedException("Field '" + field_name + "' not found in " + jc.getClassName()); } - if (f.isFinal()){ - if (!(myOwner.getClassName().equals(getObjectType(o).getClassName()))){ + if (f.isFinal()) { + if (!(myOwner.getClassName().equals(getObjectType(o).getClassName()))) { constraintViolated(o, "Referenced field '"+f+"' is final and must therefore be declared in the current class '"+ myOwner.getClassName()+"' which is not the case: it is declared in '"+o.getReferenceType(cpg)+"'."); } } - if (! (f.isStatic())){ + if (! (f.isStatic())) { constraintViolated(o, "Referenced field '"+f+"' is not static which it should be."); } String meth_name = Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getName(); // If it's an interface, it can be set only in <clinit>. - if ((!(jc.isClass())) && (!(meth_name.equals(Const.STATIC_INITIALIZER_NAME)))){ + if ((!(jc.isClass())) && (!(meth_name.equals(Const.STATIC_INITIALIZER_NAME)))) { constraintViolated(o, "Interface field '"+f+"' must be set in a '"+Const.STATIC_INITIALIZER_NAME+"' method."); } } catch (ClassNotFoundException e) { @@ -1089,23 +1089,23 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitGETSTATIC(final GETSTATIC o){ + public void visitGETSTATIC(final GETSTATIC o) { try { String field_name = o.getFieldName(cpg); JavaClass jc = Repository.lookupClass(getObjectType(o).getClassName()); Field[] fields = jc.getFields(); Field f = null; for (Field field : fields) { - if (field.getName().equals(field_name)){ + if (field.getName().equals(field_name)) { f = field; break; } } - if (f == null){ + if (f == null) { throw new AssertionViolatedException("Field '" + field_name + "' not found in " + jc.getClassName()); } - if (! (f.isStatic())){ + if (! (f.isStatic())) { constraintViolated(o, "Referenced field '"+f+"' is not static which it should be."); } } catch (ClassNotFoundException e) { @@ -1115,24 +1115,24 @@ public final class Pass3aVerifier extend } /* Checks if the constraints of operands of the said instruction(s) are satisfied. */ - //public void visitPUTFIELD(PUTFIELD o){ + //public void visitPUTFIELD(PUTFIELD o) { // for performance reasons done in Pass 3b //} /* Checks if the constraints of operands of the said instruction(s) are satisfied. */ - //public void visitGETFIELD(GETFIELD o){ + //public void visitGETFIELD(GETFIELD o) { // for performance reasons done in Pass 3b //} /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitINVOKEDYNAMIC(final INVOKEDYNAMIC o){ + public void visitINVOKEDYNAMIC(final INVOKEDYNAMIC o) { throw new RuntimeException("INVOKEDYNAMIC instruction is not supported at this time"); } /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitINVOKEINTERFACE(final INVOKEINTERFACE o){ + public void visitINVOKEINTERFACE(final INVOKEINTERFACE o) { try { // INVOKEINTERFACE is a LoadClass; the Class where the referenced method is declared in, // is therefore resolved/verified. @@ -1141,11 +1141,11 @@ public final class Pass3aVerifier extend String classname = o.getClassName(cpg); JavaClass jc = Repository.lookupClass(classname); Method m = getMethodRecursive(jc, o); - if (m == null){ + if (m == null) { constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+o.getSignature(cpg)+ "' not found in class '"+jc.getClassName()+"'."); } - if (jc.isClass()){ + if (jc.isClass()) { constraintViolated(o, "Referenced class '"+jc.getClassName()+"' is a class, but not an interface as expected."); } } catch (ClassNotFoundException e) { @@ -1165,22 +1165,22 @@ public final class Pass3aVerifier extend Method m; //look in the given class m = getMethod(jc, invoke); - if(m != null){ + if(m != null) { //method found in given class return m; } //method not found, look in super classes - for(JavaClass superclass : jc.getSuperClasses()){ + for(JavaClass superclass : jc.getSuperClasses()) { m = getMethod(superclass, invoke); - if(m != null){ + if(m != null) { //method found in super class return m; } } //method not found, look in super interfaces - for(JavaClass superclass : jc.getInterfaces()){ + for(JavaClass superclass : jc.getInterfaces()) { m = getMethod(superclass, invoke); - if(m != null){ + if(m != null) { //method found in super interface return m; } @@ -1194,12 +1194,12 @@ public final class Pass3aVerifier extend * @param invoke the instruction that references the method * @return the referenced method or null if not found. */ - private Method getMethod(final JavaClass jc, final InvokeInstruction invoke){ + private Method getMethod(final JavaClass jc, final InvokeInstruction invoke) { Method[] ms = jc.getMethods(); for (Method element : ms) { if ( (element.getName().equals(invoke.getMethodName(cpg))) && (Type.getReturnType(element.getSignature()).equals(invoke.getReturnType(cpg))) && - (objarrayequals(Type.getArgumentTypes(element.getSignature()), invoke.getArgumentTypes(cpg))) ){ + (objarrayequals(Type.getArgumentTypes(element.getSignature()), invoke.getArgumentTypes(cpg))) ) { return element; } } @@ -1209,7 +1209,7 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitINVOKESPECIAL(final INVOKESPECIAL o){ + public void visitINVOKESPECIAL(final INVOKESPECIAL o) { try { // INVOKESPECIAL is a LoadClass; the Class where the referenced method is declared in, // is therefore resolved/verified. @@ -1218,23 +1218,23 @@ public final class Pass3aVerifier extend String classname = o.getClassName(cpg); JavaClass jc = Repository.lookupClass(classname); Method m = getMethodRecursive(jc, o); - if (m == null){ + if (m == null) { constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+o.getSignature(cpg) +"' not found in class '"+jc.getClassName()+"'."); } JavaClass current = Repository.lookupClass(myOwner.getClassName()); - if (current.isSuper()){ + if (current.isSuper()) { - if ((Repository.instanceOf( current, jc )) && (!current.equals(jc))){ + if ((Repository.instanceOf( current, jc )) && (!current.equals(jc))) { - if (! (o.getMethodName(cpg).equals(Const.CONSTRUCTOR_NAME) )){ + if (! (o.getMethodName(cpg).equals(Const.CONSTRUCTOR_NAME) )) { // Special lookup procedure for ACC_SUPER classes. int supidx = -1; Method meth = null; - while (supidx != 0){ + while (supidx != 0) { supidx = current.getSuperclassNameIndex(); current = Repository.lookupClass(current.getSuperclassName()); @@ -1242,7 +1242,7 @@ public final class Pass3aVerifier extend for (Method meth2 : meths) { if ( (meth2.getName().equals(o.getMethodName(cpg))) && (Type.getReturnType(meth2.getSignature()).equals(o.getReturnType(cpg))) && - (objarrayequals(Type.getArgumentTypes(meth2.getSignature()), o.getArgumentTypes(cpg))) ){ + (objarrayequals(Type.getArgumentTypes(meth2.getSignature()), o.getArgumentTypes(cpg))) ) { meth = meth2; break; } @@ -1251,7 +1251,7 @@ public final class Pass3aVerifier extend break; } } - if (meth == null){ + if (meth == null) { constraintViolated(o, "ACC_SUPER special lookup procedure not successful: method '"+ o.getMethodName(cpg)+"' with proper signature not declared in superclass hierarchy."); } @@ -1268,7 +1268,7 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitINVOKESTATIC(final INVOKESTATIC o){ + public void visitINVOKESTATIC(final INVOKESTATIC o) { try { // INVOKESTATIC is a LoadClass; the Class where the referenced method is declared in, // is therefore resolved/verified. @@ -1277,10 +1277,10 @@ public final class Pass3aVerifier extend String classname = o.getClassName(cpg); JavaClass jc = Repository.lookupClass(classname); Method m = getMethodRecursive(jc, o); - if (m == null){ + if (m == null) { constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+ o.getSignature(cpg) +"' not found in class '"+jc.getClassName()+"'."); - } else if (! (m.isStatic())){ // implies it's not abstract, verified in pass 2. + } else if (! (m.isStatic())) { // implies it's not abstract, verified in pass 2. constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' has ACC_STATIC unset."); } @@ -1293,7 +1293,7 @@ public final class Pass3aVerifier extend /** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override - public void visitINVOKEVIRTUAL(final INVOKEVIRTUAL o){ + public void visitINVOKEVIRTUAL(final INVOKEVIRTUAL o) { try { // INVOKEVIRTUAL is a LoadClass; the Class where the referenced method is declared in, // is therefore resolved/verified. @@ -1302,11 +1302,11 @@ public final class Pass3aVerifier extend String classname = o.getClassName(cpg); JavaClass jc = Repository.lookupClass(classname); Method m = getMethodRecursive(jc, o); - if (m == null){ + if (m == null) { constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+ o.getSignature(cpg)+"' not found in class '"+jc.getClassName()+"'."); } - if (! (jc.isClass())){ + if (! (jc.isClass())) { constraintViolated(o, "Referenced class '"+jc.getClassName()+"' is an interface, but not a class as expected."); } @@ -1324,13 +1324,13 @@ public final class Pass3aVerifier extend * The equality of the elements is based on their equals(Object) * method instead of their object identity. */ - private boolean objarrayequals(final Object[] o, final Object[] p){ - if (o.length != p.length){ + private boolean objarrayequals(final Object[] o, final Object[] p) { + if (o.length != p.length) { return false; } - for (int i=0; i<o.length; i++){ - if (! (o[i].equals(p[i])) ){ + for (int i=0; i<o.length; i++) { + if (! (o[i].equals(p[i])) ) { return false; } }
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java?rev=1749600&r1=1749599&r2=1749600&view=diff ============================================================================== --- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java (original) +++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java Tue Jun 21 20:43:38 2016 @@ -83,7 +83,7 @@ public class ControlFlowGraph{ * Creates an InstructionHandleImpl object from an InstructionHandle. * Creation of one per InstructionHandle suffices. Don't create more. */ - public InstructionContextImpl(final InstructionHandle inst){ + public InstructionContextImpl(final InstructionHandle inst) { if (inst == null) { throw new AssertionViolatedException("Cannot instantiate InstructionContextImpl from NULL."); } @@ -95,13 +95,13 @@ public class ControlFlowGraph{ /* Satisfies InstructionContext.getTag(). */ @Override - public int getTag(){ + public int getTag() { return TAG; } /* Satisfies InstructionContext.setTag(int). */ @Override - public void setTag(final int tag){ // part of InstructionContext interface + public void setTag(final int tag) { // part of InstructionContext interface TAG = tag; } @@ -109,7 +109,7 @@ public class ControlFlowGraph{ * Returns the exception handlers of this instruction. */ @Override - public ExceptionHandler[] getExceptionHandlers(){ + public ExceptionHandler[] getExceptionHandlers() { return exceptionhandlers.getExceptionHandlers(getInstruction()); } @@ -117,7 +117,7 @@ public class ControlFlowGraph{ * Returns a clone of the "outgoing" frame situation with respect to the given ExecutionChain. */ @Override - public Frame getOutFrame(final ArrayList<InstructionContext> execChain){ + public Frame getOutFrame(final ArrayList<InstructionContext> execChain) { executionPredecessors = execChain; Frame org; @@ -126,7 +126,7 @@ public class ControlFlowGraph{ org = outFrames.get(jsr); - if (org == null){ + if (org == null) { throw new AssertionViolatedException( "outFrame not set! This:\n"+this+"\nExecutionChain: "+getExecutionChain()+"\nOutFrames: '"+outFrames+"'."); } @@ -141,7 +141,7 @@ public class ControlFlowGraph{ org = inFrames.get(jsr); - if (org == null){ + if (org == null) { throw new AssertionViolatedException("inFrame not set! This:\n"+this+"\nInFrames: '"+inFrames+"'."); } return org.getClone(); @@ -163,30 +163,30 @@ public class ControlFlowGraph{ * changed from the one before execute()ing. */ @Override - public boolean execute(final Frame inFrame, final ArrayList<InstructionContext> execPreds, final InstConstraintVisitor icv, final ExecutionVisitor ev){ + public boolean execute(final Frame inFrame, final ArrayList<InstructionContext> execPreds, final InstConstraintVisitor icv, final ExecutionVisitor ev) { @SuppressWarnings("unchecked") // OK because execPreds is compatible type final List<InstructionContext> clone = (List<InstructionContext>) execPreds.clone(); executionPredecessors = clone; //sanity check - if ( (lastExecutionJSR() == null) && (subroutines.subroutineOf(getInstruction()) != subroutines.getTopLevel() ) ){ + if ( (lastExecutionJSR() == null) && (subroutines.subroutineOf(getInstruction()) != subroutines.getTopLevel() ) ) { throw new AssertionViolatedException("Huh?! Am I '"+this+"' part of a subroutine or not?"); } - if ( (lastExecutionJSR() != null) && (subroutines.subroutineOf(getInstruction()) == subroutines.getTopLevel() ) ){ + if ( (lastExecutionJSR() != null) && (subroutines.subroutineOf(getInstruction()) == subroutines.getTopLevel() ) ) { throw new AssertionViolatedException("Huh?! Am I '"+this+"' part of a subroutine or not?"); } Frame inF = inFrames.get(lastExecutionJSR()); - if (inF == null){// no incoming frame was set, so set it. + if (inF == null) {// no incoming frame was set, so set it. inFrames.put(lastExecutionJSR(), inFrame); inF = inFrame; } else{// if there was an "old" inFrame - if (inF.equals(inFrame)){ //shortcut: no need to merge equal frames. + if (inF.equals(inFrame)) { //shortcut: no need to merge equal frames. return false; } - if (! mergeInFrames(inFrame)){ + if (! mergeInFrames(inFrame)) { return false; } } @@ -203,7 +203,7 @@ public class ControlFlowGraph{ icv.setFrame(workingFrame); getInstruction().accept(icv); } - catch(StructuralCodeConstraintException ce){ + catch(StructuralCodeConstraintException ce) { ce.extendMessage("","\nInstructionHandle: "+getInstruction()+"\n"); ce.extendMessage("","\nExecution Frame:\n"+workingFrame); extendMessageWithFlow(ce); @@ -226,7 +226,7 @@ public class ControlFlowGraph{ * Returns a simple String representation of this InstructionContext. */ @Override - public String toString(){ + public String toString() { //TODO: Put information in the brackets, e.g. // Is this an ExceptionHandler? Is this a RET? Is this the start of // a subroutine? @@ -258,9 +258,9 @@ public class ControlFlowGraph{ * while execute(Frame, ArrayList)-ing the code represented * by the surrounding ControlFlowGraph. */ - private String getExecutionChain(){ + private String getExecutionChain() { String s = this.toString(); - for (int i=executionPredecessors.size()-1; i>=0; i--){ + for (int i=executionPredecessors.size()-1; i>=0; i--) { s = executionPredecessors.get(i)+"\n" + s; } return s; @@ -272,7 +272,7 @@ public class ControlFlowGraph{ * This extended message will then reflect the execution flow needed to get to the constraint * violation that triggered the throwing of the "e" object. */ - private void extendMessageWithFlow(final StructuralCodeConstraintException e){ + private void extendMessageWithFlow(final StructuralCodeConstraintException e) { String s = "Execution flow:\n"; e.extendMessage("", s+getExecutionChain()); } @@ -281,7 +281,7 @@ public class ControlFlowGraph{ * Fulfils the contract of InstructionContext.getInstruction(). */ @Override - public InstructionHandle getInstruction(){ + public InstructionHandle getInstruction() { return instruction; } @@ -292,18 +292,18 @@ public class ControlFlowGraph{ * we were called by this one. * Returns null if we were called from the top level. */ - private InstructionContextImpl lastExecutionJSR(){ + private InstructionContextImpl lastExecutionJSR() { int size = executionPredecessors.size(); int retcount = 0; - for (int i=size-1; i>=0; i--){ + for (int i=size-1; i>=0; i--) { InstructionContextImpl current = (InstructionContextImpl) (executionPredecessors.get(i)); Instruction currentlast = current.getInstruction().getInstruction(); if (currentlast instanceof RET) { retcount++; } - if (currentlast instanceof JsrInstruction){ + if (currentlast instanceof JsrInstruction) { retcount--; if (retcount == -1) { return current; @@ -315,7 +315,7 @@ public class ControlFlowGraph{ /* Satisfies InstructionContext.getSuccessors(). */ @Override - public InstructionContext[] getSuccessors(){ + public InstructionContext[] getSuccessors() { return contextsOf(_getSuccessors()); } @@ -326,15 +326,15 @@ public class ControlFlowGraph{ * (opposed to its physical successor) as defined here. */ // TODO: implement caching! - private InstructionHandle[] _getSuccessors(){ + private InstructionHandle[] _getSuccessors() { final InstructionHandle[] empty = new InstructionHandle[0]; final InstructionHandle[] single = new InstructionHandle[1]; Instruction inst = getInstruction().getInstruction(); - if (inst instanceof RET){ + if (inst instanceof RET) { Subroutine s = subroutines.subroutineOf(getInstruction()); - if (s==null){ //return empty; + if (s==null) { //return empty; // RET in dead code. "empty" would be the correct answer, but we know something about the surrounding project... throw new AssertionViolatedException("Asking for successors of a RET in dead code?!"); } @@ -345,36 +345,36 @@ public class ControlFlowGraph{ InstructionHandle[] jsrs = s.getEnteringJsrInstructions(); InstructionHandle[] ret = new InstructionHandle[jsrs.length]; - for (int i=0; i<jsrs.length; i++){ + for (int i=0; i<jsrs.length; i++) { ret[i] = jsrs[i].getNext(); } return ret; } // Terminates method normally. - if (inst instanceof ReturnInstruction){ + if (inst instanceof ReturnInstruction) { return empty; } // Terminates method abnormally, because JustIce mandates // subroutines not to be protected by exception handlers. - if (inst instanceof ATHROW){ + if (inst instanceof ATHROW) { return empty; } // See method comment. - if (inst instanceof JsrInstruction){ + if (inst instanceof JsrInstruction) { single[0] = ((JsrInstruction) inst).getTarget(); return single; } - if (inst instanceof GotoInstruction){ + if (inst instanceof GotoInstruction) { single[0] = ((GotoInstruction) inst).getTarget(); return single; } - if (inst instanceof BranchInstruction){ - if (inst instanceof Select){ + if (inst instanceof BranchInstruction) { + if (inst instanceof Select) { // BCEL's getTargets() returns only the non-default targets, // thanks to Eli Tilevich for reporting. InstructionHandle[] matchTargets = ((Select) inst).getTargets(); @@ -412,7 +412,7 @@ public class ControlFlowGraph{ * A Control Flow Graph; with additional JustIce checks * @param method_gen the method generator instance */ - public ControlFlowGraph(final MethodGen method_gen){ + public ControlFlowGraph(final MethodGen method_gen) { this(method_gen, true); } @@ -422,7 +422,7 @@ public class ControlFlowGraph{ * @param enableJustIceCheck if true, additional JustIce checks are performed * @since 6.0 */ - public ControlFlowGraph(final MethodGen method_gen, final boolean enableJustIceCheck){ + public ControlFlowGraph(final MethodGen method_gen, final boolean enableJustIceCheck) { subroutines = new Subroutines(method_gen, enableJustIceCheck); exceptionhandlers = new ExceptionHandlers(method_gen); @@ -437,9 +437,9 @@ public class ControlFlowGraph{ /** * Returns the InstructionContext of a given instruction. */ - public InstructionContext contextOf(final InstructionHandle inst){ + public InstructionContext contextOf(final InstructionHandle inst) { InstructionContext ic = instructionContexts.get(inst); - if (ic == null){ + if (ic == null) { throw new AssertionViolatedException("InstructionContext requested for an InstructionHandle that's not known!"); } return ic; @@ -449,9 +449,9 @@ public class ControlFlowGraph{ * Returns the InstructionContext[] of a given InstructionHandle[], * in a naturally ordered manner. */ - public InstructionContext[] contextsOf(final InstructionHandle[] insts){ + public InstructionContext[] contextsOf(final InstructionHandle[] insts) { InstructionContext[] ret = new InstructionContext[insts.length]; - for (int i=0; i<insts.length; i++){ + for (int i=0; i<insts.length; i++) { ret[i] = contextOf(insts[i]); } return ret; @@ -462,7 +462,7 @@ public class ControlFlowGraph{ * for the method whose control flow is represented by this ControlFlowGraph * <B>(NOT ORDERED!)</B>. */ - public InstructionContext[] getInstructionContexts(){ + public InstructionContext[] getInstructionContexts() { InstructionContext[] ret = new InstructionContext[instructionContexts.values().size()]; return instructionContexts.values().toArray(ret); } @@ -471,7 +471,7 @@ public class ControlFlowGraph{ * Returns true, if and only if the said instruction is not reachable; that means, * if it is not part of this ControlFlowGraph. */ - public boolean isDead(final InstructionHandle i){ + public boolean isDead(final InstructionHandle i) { return subroutines.subroutineOf(i) == null; } } Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java?rev=1749600&r1=1749599&r2=1749600&view=diff ============================================================================== --- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java (original) +++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java Tue Jun 21 20:43:38 2016 @@ -36,7 +36,7 @@ public class ExceptionHandler{ private final InstructionHandle handlerpc; /** Leave instance creation to JustIce. */ - ExceptionHandler(final ObjectType catch_type, final InstructionHandle handler_pc){ + ExceptionHandler(final ObjectType catch_type, final InstructionHandle handler_pc) { catchtype = catch_type; handlerpc = handler_pc; } @@ -44,14 +44,14 @@ public class ExceptionHandler{ /** * Returns the type of the exception that's handled. <B>'null' means 'ANY'.</B> */ - public ObjectType getExceptionType(){ + public ObjectType getExceptionType() { return catchtype; } /** * Returns the InstructionHandle where the handler starts off. */ - public InstructionHandle getHandlerStart(){ + public InstructionHandle getHandlerStart() { return handlerpc; } } Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java?rev=1749600&r1=1749599&r2=1749600&view=diff ============================================================================== --- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java (original) +++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java Tue Jun 21 20:43:38 2016 @@ -42,15 +42,15 @@ public class ExceptionHandlers{ /** * Constructor. Creates a new ExceptionHandlers instance. */ - public ExceptionHandlers(final MethodGen mg){ + public ExceptionHandlers(final MethodGen mg) { exceptionhandlers = new HashMap<>(); CodeExceptionGen[] cegs = mg.getExceptionHandlers(); for (CodeExceptionGen ceg : cegs) { ExceptionHandler eh = new ExceptionHandler(ceg.getCatchType(), ceg.getHandlerPC()); - for (InstructionHandle ih=ceg.getStartPC(); ih != ceg.getEndPC().getNext(); ih=ih.getNext()){ + for (InstructionHandle ih=ceg.getStartPC(); ih != ceg.getEndPC().getNext(); ih=ih.getNext()) { Set<ExceptionHandler> hs; hs = exceptionhandlers.get(ih); - if (hs == null){ + if (hs == null) { hs = new HashSet<>(); exceptionhandlers.put(ih, hs); } @@ -63,7 +63,7 @@ public class ExceptionHandlers{ * Returns all the ExceptionHandler instances representing exception * handlers that protect the instruction ih. */ - public ExceptionHandler[] getExceptionHandlers(final InstructionHandle ih){ + public ExceptionHandler[] getExceptionHandlers(final InstructionHandle ih) { Set<ExceptionHandler> hsSet = exceptionhandlers.get(ih); if (hsSet == null) { return new ExceptionHandler[0];
