Pass2Verifier.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  *  Unless required by applicable law or agreed to in writing, software
  12.  *  distributed under the License is distributed on an "AS IS" BASIS,
  13.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  *  See the License for the specific language governing permissions and
  15.  *  limitations under the License.
  16.  */
  17. package org.apache.bcel.verifier.statics;

  18. import java.util.HashMap;
  19. import java.util.HashSet;
  20. import java.util.Locale;
  21. import java.util.Map;
  22. import java.util.Objects;
  23. import java.util.Set;

  24. import org.apache.bcel.Const;
  25. import org.apache.bcel.Constants;
  26. import org.apache.bcel.Repository;
  27. import org.apache.bcel.classfile.Attribute;
  28. import org.apache.bcel.classfile.ClassFormatException;
  29. import org.apache.bcel.classfile.Code;
  30. import org.apache.bcel.classfile.CodeException;
  31. import org.apache.bcel.classfile.Constant;
  32. import org.apache.bcel.classfile.ConstantClass;
  33. import org.apache.bcel.classfile.ConstantDouble;
  34. import org.apache.bcel.classfile.ConstantFieldref;
  35. import org.apache.bcel.classfile.ConstantFloat;
  36. import org.apache.bcel.classfile.ConstantInteger;
  37. import org.apache.bcel.classfile.ConstantInterfaceMethodref;
  38. import org.apache.bcel.classfile.ConstantLong;
  39. import org.apache.bcel.classfile.ConstantMethodref;
  40. import org.apache.bcel.classfile.ConstantNameAndType;
  41. import org.apache.bcel.classfile.ConstantPool;
  42. import org.apache.bcel.classfile.ConstantString;
  43. import org.apache.bcel.classfile.ConstantUtf8;
  44. import org.apache.bcel.classfile.ConstantValue;
  45. import org.apache.bcel.classfile.Deprecated;
  46. import org.apache.bcel.classfile.DescendingVisitor;
  47. import org.apache.bcel.classfile.EmptyVisitor;
  48. import org.apache.bcel.classfile.ExceptionTable;
  49. import org.apache.bcel.classfile.Field;
  50. import org.apache.bcel.classfile.InnerClass;
  51. import org.apache.bcel.classfile.InnerClasses;
  52. import org.apache.bcel.classfile.JavaClass;
  53. import org.apache.bcel.classfile.LineNumber;
  54. import org.apache.bcel.classfile.LineNumberTable;
  55. import org.apache.bcel.classfile.LocalVariable;
  56. import org.apache.bcel.classfile.LocalVariableTable;
  57. import org.apache.bcel.classfile.Method;
  58. import org.apache.bcel.classfile.Node;
  59. import org.apache.bcel.classfile.SourceFile;
  60. import org.apache.bcel.classfile.Synthetic;
  61. import org.apache.bcel.classfile.Unknown;
  62. import org.apache.bcel.classfile.Utility;
  63. import org.apache.bcel.generic.ArrayType;
  64. import org.apache.bcel.generic.ObjectType;
  65. import org.apache.bcel.generic.Type;
  66. import org.apache.bcel.verifier.PassVerifier;
  67. import org.apache.bcel.verifier.VerificationResult;
  68. import org.apache.bcel.verifier.Verifier;
  69. import org.apache.bcel.verifier.VerifierFactory;
  70. import org.apache.bcel.verifier.exc.AssertionViolatedException;
  71. import org.apache.bcel.verifier.exc.ClassConstraintException;
  72. import org.apache.bcel.verifier.exc.LocalVariableInfoInconsistentException;

  73. /**
  74.  * This PassVerifier verifies a class file according to pass 2 as described in The Java Virtual Machine Specification,
  75.  * 2nd edition. More detailed information is to be found at the do_verify() method's documentation.
  76.  *
  77.  * @see #do_verify()
  78.  */
  79. public final class Pass2Verifier extends PassVerifier implements Constants {

  80.     /**
  81.      * A Visitor class that ensures the constant pool satisfies the static constraints. The visitXXX() methods throw
  82.      * ClassConstraintException instances otherwise.
  83.      *
  84.      * @see #constantPoolEntriesSatisfyStaticConstraints()
  85.      */
  86.     private final class CPESSC_Visitor extends EmptyVisitor {
  87.         private final Class<?> CONST_Class;

  88.         /*
  89.          * private Class<?> CONST_Fieldref; private Class<?> CONST_Methodref; private Class<?> CONST_InterfaceMethodref;
  90.          */
  91.         private final Class<?> CONST_String;
  92.         private final Class<?> CONST_Integer;
  93.         private final Class<?> CONST_Float;
  94.         private final Class<?> CONST_Long;
  95.         private final Class<?> CONST_Double;
  96.         private final Class<?> CONST_NameAndType;
  97.         private final Class<?> CONST_Utf8;

  98.         private final JavaClass jc;
  99.         private final ConstantPool cp; // ==jc.getConstantPool() -- only here to save typing work and computing power.
  100.         private final int cplen; // == cp.getLength() -- to save computing power.
  101.         private final DescendingVisitor carrier;

  102.         private final Set<String> fieldNames = new HashSet<>();
  103.         private final Set<String> fieldNamesAndDesc = new HashSet<>();
  104.         private final Set<String> methodNamesAndDesc = new HashSet<>();

  105.         private CPESSC_Visitor(final JavaClass jc) {
  106.             this.jc = jc;
  107.             this.cp = jc.getConstantPool();
  108.             this.cplen = cp.getLength();

  109.             this.CONST_Class = ConstantClass.class;
  110.             /*
  111.              * CONST_Fieldref = ConstantFieldref.class; CONST_Methodref = ConstantMethodref.class; CONST_InterfaceMethodref =
  112.              * ConstantInterfaceMethodref.class;
  113.              */
  114.             this.CONST_String = ConstantString.class;
  115.             this.CONST_Integer = ConstantInteger.class;
  116.             this.CONST_Float = ConstantFloat.class;
  117.             this.CONST_Long = ConstantLong.class;
  118.             this.CONST_Double = ConstantDouble.class;
  119.             this.CONST_NameAndType = ConstantNameAndType.class;
  120.             this.CONST_Utf8 = ConstantUtf8.class;

  121.             this.carrier = new DescendingVisitor(jc, this);
  122.             this.carrier.visit();
  123.         }

  124.         private void checkIndex(final Node referrer, final int index, final Class<?> shouldbe) {
  125.             if (index < 0 || index >= cplen) {
  126.                 throw new ClassConstraintException("Invalid index '" + index + "' used by '" + tostring(referrer) + "'.");
  127.             }
  128.             final Constant c = cp.getConstant(index);
  129.             if (!shouldbe.isInstance(c)) {
  130.                 /* String isnot = shouldbe.toString().substring(shouldbe.toString().lastIndexOf(".")+1); //Cut all before last "." */
  131.                 throw new ClassConstraintException(
  132.                     "Illegal constant '" + tostring(c) + "' at index '" + index + "'. '" + tostring(referrer) + "' expects a '" + shouldbe + "'.");
  133.             }
  134.         }

  135.         // SYNTHETIC: see above
  136.         // DEPRECATED: see above
  137.         /////////////////////////////////////////////////////////
  138.         // method_info-structure-ATTRIBUTES (vmspec2 4.6, 4.7) //
  139.         /////////////////////////////////////////////////////////
  140.         @Override
  141.         public void visitCode(final Code obj) { // vmspec2 4.7.3
  142.             try {
  143.                 // No code attribute allowed for native or abstract methods: see visitMethod(Method).
  144.                 // Code array constraints are checked in Pass3 (3a and 3b).

  145.                 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

  146.                 final String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
  147.                 if (!name.equals("Code")) {
  148.                     throw new ClassConstraintException("The Code attribute '" + tostring(obj) + "' is not correctly named 'Code' but '" + name + "'.");
  149.                 }

  150.                 if (!(carrier.predecessor() instanceof Method)) {
  151.                     addMessage("Code attribute '" + tostring(obj) + "' is not declared in a method_info structure but in '" + carrier.predecessor()
  152.                             + "'. Ignored.");
  153.                     return;
  154.                 }
  155.                 final Method m = (Method) carrier.predecessor(); // we can assume this method was visited before;
  156.                                                                  // i.e. the data consistency was verified.

  157.                 if (obj.getCode().length == 0) {
  158.                     throw new ClassConstraintException("Code array of Code attribute '" + tostring(obj) + "' (method '" + m + "') must not be empty.");
  159.                 }

  160.                 // In JustIce, the check for correct offsets into the code array is delayed to Pass 3a.
  161.                 final CodeException[] excTable = obj.getExceptionTable();
  162.                 for (final CodeException element : excTable) {
  163.                     final int excIndex = element.getCatchType();
  164.                     if (excIndex != 0) { // if 0, it catches all Throwables
  165.                         checkIndex(obj, excIndex, CONST_Class);
  166.                         final ConstantClass cc = (ConstantClass) cp.getConstant(excIndex);
  167.                         // cannot be sure this ConstantClass has already been visited (checked)!
  168.                         checkIndex(cc, cc.getNameIndex(), CONST_Utf8);
  169.                         final String cname = Utility.pathToPackage(((ConstantUtf8) cp.getConstant(cc.getNameIndex())).getBytes());

  170.                         Verifier v = VerifierFactory.getVerifier(cname);
  171.                         VerificationResult vr = v.doPass1();

  172.                         if (vr != VerificationResult.VR_OK) {
  173.                             throw new ClassConstraintException("Code attribute '" + tostring(obj) + "' (method '" + m + "') has an exception_table entry '"
  174.                                     + tostring(element) + "' that references '" + cname + "' as an Exception but it does not pass verification pass 1: " + vr);
  175.                         }
  176.                         // We cannot safely trust any other "instanceof" mechanism. We need to transitively verify
  177.                         // the ancestor hierarchy.
  178.                         JavaClass e = Repository.lookupClass(cname);
  179.                         final JavaClass t = Repository.lookupClass(Type.THROWABLE.getClassName());
  180.                         final JavaClass o = Repository.lookupClass(Type.OBJECT.getClassName());
  181.                         while (e != o) {
  182.                             if (e == t) {
  183.                                 break; // It's a subclass of Throwable, OKAY, leave.
  184.                             }

  185.                             v = VerifierFactory.getVerifier(e.getSuperclassName());
  186.                             vr = v.doPass1();
  187.                             if (vr != VerificationResult.VR_OK) {
  188.                                 throw new ClassConstraintException("Code attribute '" + tostring(obj) + "' (method '" + m + "') has an exception_table entry '"
  189.                                         + tostring(element) + "' that references '" + cname + "' as an Exception but '" + e.getSuperclassName()
  190.                                         + "' in the ancestor hierachy does not pass verification pass 1: " + vr);
  191.                             }
  192.                             e = Repository.lookupClass(e.getSuperclassName());
  193.                         }
  194.                         if (e != t) {
  195.                             throw new ClassConstraintException(
  196.                                     "Code attribute '" + tostring(obj) + "' (method '" + m + "') has an exception_table entry '" + tostring(element)
  197.                                             + "' that references '" + cname + "' as an Exception but it is not a subclass of '" + t.getClassName() + "'.");
  198.                         }
  199.                     }
  200.                 }

  201.                 // Create object for local variables information
  202.                 // This is highly unelegant due to usage of the Visitor pattern.
  203.                 // TODO: rework it.
  204.                 int methodNumber = -1;
  205.                 final Method[] ms = Repository.lookupClass(verifier.getClassName()).getMethods();
  206.                 for (int mn = 0; mn < ms.length; mn++) {
  207.                     if (m == ms[mn]) {
  208.                         methodNumber = mn;
  209.                         break;
  210.                     }
  211.                 }
  212.                 // If the .class file is malformed the loop above may not find a method.
  213.                 // Try matching names instead of pointers.
  214.                 if (methodNumber < 0) {
  215.                     for (int mn = 0; mn < ms.length; mn++) {
  216.                         if (m.getName().equals(ms[mn].getName())) {
  217.                             methodNumber = mn;
  218.                             break;
  219.                         }
  220.                     }
  221.                 }

  222.                 if (methodNumber < 0) { // Mmmmh. Can we be sure BCEL does not sometimes instantiate new objects?
  223.                     throw new AssertionViolatedException("Could not find a known BCEL Method object in the corresponding BCEL JavaClass object.");
  224.                 }
  225.                 localVariablesInfos[methodNumber] = new LocalVariablesInfo(obj.getMaxLocals());

  226.                 int numOfLvtAttribs = 0;
  227.                 // Now iterate through the attributes the Code attribute has.
  228.                 final Attribute[] atts = obj.getAttributes();
  229.                 for (final Attribute att : atts) {
  230.                     if (!(att instanceof LineNumberTable) && !(att instanceof LocalVariableTable)) {
  231.                         addMessage("Attribute '" + tostring(att) + "' as an attribute of Code attribute '" + tostring(obj) + "' (method '" + m
  232.                                 + "') is unknown and will therefore be ignored.");
  233.                     } else { // LineNumberTable or LocalVariableTable
  234.                         addMessage("Attribute '" + tostring(att) + "' as an attribute of Code attribute '" + tostring(obj) + "' (method '" + m
  235.                                 + "') will effectively be ignored and is only useful for debuggers and such.");
  236.                     }

  237.                     // LocalVariableTable check (partially delayed to Pass3a).
  238.                     // Here because its easier to collect the information of the
  239.                     // (possibly more than one) LocalVariableTables belonging to
  240.                     // one certain Code attribute.
  241.                     if (att instanceof LocalVariableTable) { // checks conforming to vmspec2 4.7.9

  242.                         final LocalVariableTable lvt = (LocalVariableTable) att;

  243.                         checkIndex(lvt, lvt.getNameIndex(), CONST_Utf8);

  244.                         final String lvtname = ((ConstantUtf8) cp.getConstant(lvt.getNameIndex())).getBytes();
  245.                         if (!lvtname.equals("LocalVariableTable")) {
  246.                             throw new ClassConstraintException("The LocalVariableTable attribute '" + tostring(lvt)
  247.                                     + "' is not correctly named 'LocalVariableTable' but '" + lvtname + "'.");
  248.                         }

  249.                         // In JustIce, the check for correct offsets into the code array is delayed to Pass 3a.
  250.                         for (final LocalVariable localvariable : lvt.getLocalVariableTable()) {
  251.                             checkIndex(lvt, localvariable.getNameIndex(), CONST_Utf8);
  252.                             final String localname = ((ConstantUtf8) cp.getConstant(localvariable.getNameIndex())).getBytes();
  253.                             if (!validJavaIdentifier(localname)) {
  254.                                 throw new ClassConstraintException("LocalVariableTable '" + tostring(lvt) + "' references a local variable by the name '"
  255.                                         + localname + "' which is not a legal Java simple name.");
  256.                             }

  257.                             checkIndex(lvt, localvariable.getSignatureIndex(), CONST_Utf8);
  258.                             final String localsig = ((ConstantUtf8) cp.getConstant(localvariable.getSignatureIndex())).getBytes(); // Local sig.(=descriptor)
  259.                             Type t;
  260.                             try {
  261.                                 t = Type.getType(localsig);
  262.                             } catch (final ClassFormatException cfe) {
  263.                                 throw new ClassConstraintException("Illegal descriptor (==signature) '" + localsig + "' used by LocalVariable '"
  264.                                         + tostring(localvariable) + "' referenced by '" + tostring(lvt) + "'.", cfe);
  265.                             }
  266.                             final int localindex = localvariable.getIndex();
  267.                             if ((t == Type.LONG || t == Type.DOUBLE ? localindex + 1 : localindex) >= obj.getMaxLocals()) {
  268.                                 throw new ClassConstraintException("LocalVariableTable attribute '" + tostring(lvt) + "' references a LocalVariable '"
  269.                                         + tostring(localvariable) + "' with an index that exceeds the surrounding Code attribute's max_locals value of '"
  270.                                         + obj.getMaxLocals() + "'.");
  271.                             }

  272.                             try {
  273.                                 localVariablesInfos[methodNumber].add(localindex, localname, localvariable.getStartPC(), localvariable.getLength(), t);
  274.                             } catch (final LocalVariableInfoInconsistentException lviie) {
  275.                                 throw new ClassConstraintException("Conflicting information in LocalVariableTable '" + tostring(lvt)
  276.                                         + "' found in Code attribute '" + tostring(obj) + "' (method '" + tostring(m) + "'). " + lviie.getMessage(), lviie);
  277.                             }
  278.                         } // for all local variables localvariables[i] in the LocalVariableTable attribute atts[a] END

  279.                         numOfLvtAttribs++;
  280.                         if (!m.isStatic() && numOfLvtAttribs > obj.getMaxLocals()) {
  281.                             throw new ClassConstraintException("Number of LocalVariableTable attributes of Code attribute '" + tostring(obj) + "' (method '"
  282.                                     + tostring(m) + "') exceeds number of local variable slots '" + obj.getMaxLocals()
  283.                                     + "' ('There may be at most one LocalVariableTable attribute per local variable in the Code attribute.').");
  284.                         }
  285.                     } // if atts[a] instanceof LocalVariableTable END
  286.                 } // for all attributes atts[a] END

  287.             } catch (final ClassNotFoundException e) {
  288.                 // FIXME: this might not be the best way to handle missing classes.
  289.                 throw new AssertionViolatedException("Missing class: " + e, e);
  290.             }

  291.         } // visitCode(Code) END

  292.         @Override
  293.         public void visitCodeException(final CodeException obj) {
  294.             // Code constraints are checked in Pass3 (3a and 3b).
  295.             // This does not represent an Attribute but is only
  296.             // related to internal BCEL data representation.

  297.             // see visitCode(Code)
  298.         }

  299.         /////////////////////////////
  300.         // CONSTANTS (vmspec2 4.4) //
  301.         /////////////////////////////
  302.         @Override
  303.         public void visitConstantClass(final ConstantClass obj) {
  304.             if (obj.getTag() != Const.CONSTANT_Class) {
  305.                 throw new ClassConstraintException("Wrong constant tag in '" + tostring(obj) + "'.");
  306.             }
  307.             checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

  308.         }

  309.         @Override
  310.         public void visitConstantDouble(final ConstantDouble obj) {
  311.             if (obj.getTag() != Const.CONSTANT_Double) {
  312.                 throw new ClassConstraintException("Wrong constant tag in '" + tostring(obj) + "'.");
  313.             }
  314.             // no indices to check
  315.         }

  316.         @Override
  317.         public void visitConstantFieldref(final ConstantFieldref obj) {
  318.             if (obj.getTag() != Const.CONSTANT_Fieldref) {
  319.                 throw new ClassConstraintException("Wrong constant tag in '" + tostring(obj) + "'.");
  320.             }
  321.             checkIndex(obj, obj.getClassIndex(), CONST_Class);
  322.             checkIndex(obj, obj.getNameAndTypeIndex(), CONST_NameAndType);
  323.         }

  324.         @Override
  325.         public void visitConstantFloat(final ConstantFloat obj) {
  326.             if (obj.getTag() != Const.CONSTANT_Float) {
  327.                 throw new ClassConstraintException("Wrong constant tag in '" + tostring(obj) + "'.");
  328.             }
  329.             // no indices to check
  330.         }

  331.         @Override
  332.         public void visitConstantInteger(final ConstantInteger obj) {
  333.             if (obj.getTag() != Const.CONSTANT_Integer) {
  334.                 throw new ClassConstraintException("Wrong constant tag in '" + tostring(obj) + "'.");
  335.             }
  336.             // no indices to check
  337.         }

  338.         @Override
  339.         public void visitConstantInterfaceMethodref(final ConstantInterfaceMethodref obj) {
  340.             if (obj.getTag() != Const.CONSTANT_InterfaceMethodref) {
  341.                 throw new ClassConstraintException("Wrong constant tag in '" + tostring(obj) + "'.");
  342.             }
  343.             checkIndex(obj, obj.getClassIndex(), CONST_Class);
  344.             checkIndex(obj, obj.getNameAndTypeIndex(), CONST_NameAndType);
  345.         }

  346.         @Override
  347.         public void visitConstantLong(final ConstantLong obj) {
  348.             if (obj.getTag() != Const.CONSTANT_Long) {
  349.                 throw new ClassConstraintException("Wrong constant tag in '" + tostring(obj) + "'.");
  350.             }
  351.             // no indices to check
  352.         }

  353.         @Override
  354.         public void visitConstantMethodref(final ConstantMethodref obj) {
  355.             if (obj.getTag() != Const.CONSTANT_Methodref) {
  356.                 throw new ClassConstraintException("Wrong constant tag in '" + tostring(obj) + "'.");
  357.             }
  358.             checkIndex(obj, obj.getClassIndex(), CONST_Class);
  359.             checkIndex(obj, obj.getNameAndTypeIndex(), CONST_NameAndType);
  360.         }

  361.         @Override
  362.         public void visitConstantNameAndType(final ConstantNameAndType obj) {
  363.             if (obj.getTag() != Const.CONSTANT_NameAndType) {
  364.                 throw new ClassConstraintException("Wrong constant tag in '" + tostring(obj) + "'.");
  365.             }
  366.             checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
  367.             // checkIndex(obj, obj.getDescriptorIndex(), CONST_Utf8); //inconsistently named in BCEL, see below.
  368.             checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);
  369.         }

  370.         @Override
  371.         public void visitConstantPool(final ConstantPool obj) {
  372.             // No need to. We're piggybacked by the DescendingVisitor.
  373.             // This does not represent an Attribute but is only
  374.             // related to internal BCEL data representation.
  375.         }

  376.         @Override
  377.         public void visitConstantString(final ConstantString obj) {
  378.             if (obj.getTag() != Const.CONSTANT_String) {
  379.                 throw new ClassConstraintException("Wrong constant tag in '" + tostring(obj) + "'.");
  380.             }
  381.             checkIndex(obj, obj.getStringIndex(), CONST_Utf8);
  382.         }

  383.         @Override
  384.         public void visitConstantUtf8(final ConstantUtf8 obj) {
  385.             if (obj.getTag() != Const.CONSTANT_Utf8) {
  386.                 throw new ClassConstraintException("Wrong constant tag in '" + tostring(obj) + "'.");
  387.             }
  388.             // no indices to check
  389.         }

  390.         ////////////////////////////////////////////////////////
  391.         // field_info-structure-ATTRIBUTES (vmspec2 4.5, 4.7) //
  392.         ////////////////////////////////////////////////////////
  393.         @Override
  394.         public void visitConstantValue(final ConstantValue obj) { // vmspec2 4.7.2
  395.             // Despite its name, this really is an Attribute,
  396.             // not a constant!
  397.             checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

  398.             final String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
  399.             if (!name.equals("ConstantValue")) {
  400.                 throw new ClassConstraintException(
  401.                     "The ConstantValue attribute '" + tostring(obj) + "' is not correctly named 'ConstantValue' but '" + name + "'.");
  402.             }

  403.             final Object pred = carrier.predecessor();
  404.             if (pred instanceof Field) { // ConstantValue attributes are quite senseless if the predecessor is not a field.
  405.                 final Field f = (Field) pred;
  406.                 // Field constraints have been checked before -- so we are safe using their type information.
  407.                 final Type fieldType = Type.getType(((ConstantUtf8) cp.getConstant(f.getSignatureIndex())).getBytes());

  408.                 final int index = obj.getConstantValueIndex();
  409.                 if (index < 0 || index >= cplen) {
  410.                     throw new ClassConstraintException("Invalid index '" + index + "' used by '" + tostring(obj) + "'.");
  411.                 }
  412.                 final Constant c = cp.getConstant(index);

  413.                 if (CONST_Long.isInstance(c) && fieldType.equals(Type.LONG) || CONST_Float.isInstance(c) && fieldType.equals(Type.FLOAT)) {
  414.                     return;
  415.                 }
  416.                 if (CONST_Double.isInstance(c) && fieldType.equals(Type.DOUBLE)) {
  417.                     return;
  418.                 }
  419.                 if (CONST_Integer.isInstance(c) && (fieldType.equals(Type.INT) || fieldType.equals(Type.SHORT) || fieldType.equals(Type.CHAR)
  420.                     || fieldType.equals(Type.BYTE) || fieldType.equals(Type.BOOLEAN))) {
  421.                     return;
  422.                 }
  423.                 if (CONST_String.isInstance(c) && fieldType.equals(Type.STRING)) {
  424.                     return;
  425.                 }

  426.                 throw new ClassConstraintException("Illegal type of ConstantValue '" + obj + "' embedding Constant '" + c + "'. It is referenced by field '"
  427.                     + tostring(f) + "' expecting a different type: '" + fieldType + "'.");
  428.             }
  429.         }

  430.         @Override
  431.         public void visitDeprecated(final Deprecated obj) { // vmspec2 4.7.10
  432.             checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

  433.             final String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
  434.             if (!name.equals("Deprecated")) {
  435.                 throw new ClassConstraintException("The Deprecated attribute '" + tostring(obj) + "' is not correctly named 'Deprecated' but '" + name + "'.");
  436.             }
  437.         }

  438.         @Override
  439.         public void visitExceptionTable(final ExceptionTable obj) { // vmspec2 4.7.4
  440.             try {
  441.                 // incorrectly named, it's the Exceptions attribute (vmspec2 4.7.4)
  442.                 checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

  443.                 final String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
  444.                 if (!name.equals("Exceptions")) {
  445.                     throw new ClassConstraintException(
  446.                         "The Exceptions attribute '" + tostring(obj) + "' is not correctly named 'Exceptions' but '" + name + "'.");
  447.                 }

  448.                 final int[] excIndices = obj.getExceptionIndexTable();

  449.                 for (final int excIndice : excIndices) {
  450.                     checkIndex(obj, excIndice, CONST_Class);

  451.                     final ConstantClass cc = (ConstantClass) cp.getConstant(excIndice);
  452.                     checkIndex(cc, cc.getNameIndex(), CONST_Utf8); // can't be sure this ConstantClass has already been visited (checked)!
  453.                     // convert internal notation on-the-fly to external notation:
  454.                     final String cname = Utility.pathToPackage(((ConstantUtf8) cp.getConstant(cc.getNameIndex())).getBytes());

  455.                     Verifier v = VerifierFactory.getVerifier(cname);
  456.                     VerificationResult vr = v.doPass1();

  457.                     if (vr != VerificationResult.VR_OK) {
  458.                         throw new ClassConstraintException("Exceptions attribute '" + tostring(obj) + "' references '" + cname
  459.                             + "' as an Exception but it does not pass verification pass 1: " + vr);
  460.                     }
  461.                     // We cannot safely trust any other "instanceof" mechanism. We need to transitively verify
  462.                     // the ancestor hierarchy.
  463.                     JavaClass e = Repository.lookupClass(cname);
  464.                     final JavaClass t = Repository.lookupClass(Type.THROWABLE.getClassName());
  465.                     final JavaClass o = Repository.lookupClass(Type.OBJECT.getClassName());
  466.                     while (e != o) {
  467.                         if (e == t) {
  468.                             break; // It's a subclass of Throwable, OKAY, leave.
  469.                         }

  470.                         v = VerifierFactory.getVerifier(e.getSuperclassName());
  471.                         vr = v.doPass1();
  472.                         if (vr != VerificationResult.VR_OK) {
  473.                             throw new ClassConstraintException("Exceptions attribute '" + tostring(obj) + "' references '" + cname + "' as an Exception but '"
  474.                                 + e.getSuperclassName() + "' in the ancestor hierachy does not pass verification pass 1: " + vr);
  475.                         }
  476.                         e = Repository.lookupClass(e.getSuperclassName());
  477.                     }
  478.                     if (e != t) {
  479.                         throw new ClassConstraintException("Exceptions attribute '" + tostring(obj) + "' references '" + cname
  480.                             + "' as an Exception but it is not a subclass of '" + t.getClassName() + "'.");
  481.                     }
  482.                 }

  483.             } catch (final ClassNotFoundException e) {
  484.                 // FIXME: this might not be the best way to handle missing classes.
  485.                 throw new AssertionViolatedException("Missing class: " + e, e);
  486.             }
  487.         }

  488.         //////////////////////////
  489.         // FIELDS (vmspec2 4.5) //
  490.         //////////////////////////
  491.         @Override
  492.         public void visitField(final Field obj) {

  493.             if (jc.isClass()) {
  494.                 int maxone = 0;
  495.                 if (obj.isPrivate()) {
  496.                     maxone++;
  497.                 }
  498.                 if (obj.isProtected()) {
  499.                     maxone++;
  500.                 }
  501.                 if (obj.isPublic()) {
  502.                     maxone++;
  503.                 }
  504.                 if (maxone > 1) {
  505.                     throw new ClassConstraintException(
  506.                         "Field '" + tostring(obj) + "' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set.");
  507.                 }

  508.                 if (obj.isFinal() && obj.isVolatile()) {
  509.                     throw new ClassConstraintException(
  510.                         "Field '" + tostring(obj) + "' must only have at most one of its ACC_FINAL, ACC_VOLATILE modifiers set.");
  511.                 }
  512.             } else { // isInterface!
  513.                 if (!obj.isPublic()) {
  514.                     throw new ClassConstraintException("Interface field '" + tostring(obj) + "' must have the ACC_PUBLIC modifier set but hasn't!");
  515.                 }
  516.                 if (!obj.isStatic()) {
  517.                     throw new ClassConstraintException("Interface field '" + tostring(obj) + "' must have the ACC_STATIC modifier set but hasn't!");
  518.                 }
  519.                 if (!obj.isFinal()) {
  520.                     throw new ClassConstraintException("Interface field '" + tostring(obj) + "' must have the ACC_FINAL modifier set but hasn't!");
  521.                 }
  522.             }

  523.             if ((obj.getAccessFlags() & ~(Const.ACC_PUBLIC | Const.ACC_PRIVATE | Const.ACC_PROTECTED | Const.ACC_STATIC | Const.ACC_FINAL | Const.ACC_VOLATILE |
  524.                 Const.ACC_TRANSIENT)) > 0) {
  525.                 addMessage("Field '" + tostring(obj) + "' has access flag(s) other than ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED,"
  526.                     + " ACC_STATIC, ACC_FINAL, ACC_VOLATILE, ACC_TRANSIENT set (ignored).");
  527.             }

  528.             checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

  529.             final String name = obj.getName();
  530.             if (!validFieldName(name)) {
  531.                 throw new ClassConstraintException("Field '" + tostring(obj) + "' has illegal name '" + obj.getName() + "'.");
  532.             }

  533.             // A descriptor is often named signature in BCEL
  534.             checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);

  535.             final String sig = ((ConstantUtf8) cp.getConstant(obj.getSignatureIndex())).getBytes(); // Field or Method sig.(=descriptor)

  536.             try {
  537.                 Type.getType(sig); /* Don't need the return value */
  538.             } catch (final ClassFormatException cfe) {
  539.                 throw new ClassConstraintException("Illegal descriptor (==signature) '" + sig + "' used by '" + tostring(obj) + "'.", cfe);
  540.             }

  541.             final String nameanddesc = name + sig;
  542.             if (fieldNamesAndDesc.contains(nameanddesc)) {
  543.                 throw new ClassConstraintException("No two fields (like '" + tostring(obj) + "') are allowed have same names and descriptors!");
  544.             }
  545.             if (fieldNames.contains(name)) {
  546.                 addMessage("More than one field of name '" + name + "' detected (but with different type descriptors). This is very unusual.");
  547.             }
  548.             fieldNamesAndDesc.add(nameanddesc);
  549.             fieldNames.add(name);

  550.             final Attribute[] atts = obj.getAttributes();
  551.             for (final Attribute att : atts) {
  552.                 if (!(att instanceof ConstantValue) && !(att instanceof Synthetic) && !(att instanceof Deprecated)) {
  553.                     addMessage("Attribute '" + tostring(att) + "' as an attribute of Field '" + tostring(obj) + "' is unknown and will therefore be ignored.");
  554.                 }
  555.                 if (!(att instanceof ConstantValue)) {
  556.                     addMessage("Attribute '" + tostring(att) + "' as an attribute of Field '" + tostring(obj)
  557.                         + "' is not a ConstantValue and is therefore only of use for debuggers and such.");
  558.                 }
  559.             }
  560.         }

  561.         @Override
  562.         public void visitInnerClass(final InnerClass obj) {
  563.             // This does not represent an Attribute but is only
  564.             // related to internal BCEL data representation.
  565.         }

  566.         @Override
  567.         public void visitInnerClasses(final InnerClasses innerClasses) { // vmspec2 4.7.5

  568.             // exactly one InnerClasses attr per ClassFile if some inner class is refernced: see visitJavaClass()

  569.             checkIndex(innerClasses, innerClasses.getNameIndex(), CONST_Utf8);

  570.             final String name = ((ConstantUtf8) cp.getConstant(innerClasses.getNameIndex())).getBytes();
  571.             if (!name.equals("InnerClasses")) {
  572.                 throw new ClassConstraintException(
  573.                     "The InnerClasses attribute '" + tostring(innerClasses) + "' is not correctly named 'InnerClasses' but '" + name + "'.");
  574.             }

  575.             innerClasses.forEach(ic -> {
  576.                 checkIndex(innerClasses, ic.getInnerClassIndex(), CONST_Class);
  577.                 final int outerIdx = ic.getOuterClassIndex();
  578.                 if (outerIdx != 0) {
  579.                     checkIndex(innerClasses, outerIdx, CONST_Class);
  580.                 }
  581.                 final int innernameIdx = ic.getInnerNameIndex();
  582.                 if (innernameIdx != 0) {
  583.                     checkIndex(innerClasses, innernameIdx, CONST_Utf8);
  584.                 }
  585.                 int acc = ic.getInnerAccessFlags();
  586.                 acc &= ~(Const.ACC_PUBLIC | Const.ACC_PRIVATE | Const.ACC_PROTECTED | Const.ACC_STATIC | Const.ACC_FINAL | Const.ACC_INTERFACE |
  587.                     Const.ACC_ABSTRACT);
  588.                 if (acc != 0) {
  589.                     addMessage("Unknown access flag for inner class '" + tostring(ic) + "' set (InnerClasses attribute '" + tostring(innerClasses) + "').");
  590.                 }
  591.             });
  592.             // Semantical consistency is not yet checked by Sun, see vmspec2 4.7.5.
  593.             // [marked TODO in JustIce]
  594.         }

  595.         ///////////////////////////////////////
  596.         // ClassFile structure (vmspec2 4.1) //
  597.         ///////////////////////////////////////
  598.         @Override
  599.         public void visitJavaClass(final JavaClass obj) {
  600.             final Attribute[] atts = obj.getAttributes();
  601.             boolean foundSourceFile = false;
  602.             boolean foundInnerClasses = false;

  603.             // Is there an InnerClass referenced?
  604.             // This is a costly check; existing verifiers don't do it!
  605.             final boolean hasInnerClass = new InnerClassDetector(jc).innerClassReferenced();

  606.             for (final Attribute att : atts) {
  607.                 if (!(att instanceof SourceFile) && !(att instanceof Deprecated) && !(att instanceof InnerClasses) && !(att instanceof Synthetic)) {
  608.                     addMessage("Attribute '" + tostring(att) + "' as an attribute of the ClassFile structure '" + tostring(obj)
  609.                         + "' is unknown and will therefore be ignored.");
  610.                 }

  611.                 if (att instanceof SourceFile) {
  612.                     if (foundSourceFile) {
  613.                         throw new ClassConstraintException(
  614.                             "A ClassFile structure (like '" + tostring(obj) + "') may have no more than one SourceFile attribute."); // vmspec2 4.7.7
  615.                     }
  616.                     foundSourceFile = true;
  617.                 }

  618.                 if (att instanceof InnerClasses) {
  619.                     if (!foundInnerClasses) {
  620.                         foundInnerClasses = true;
  621.                     } else if (hasInnerClass) {
  622.                         throw new ClassConstraintException("A Classfile structure (like '" + tostring(obj) + "') must have exactly one InnerClasses attribute"
  623.                             + " if at least one Inner Class is referenced (which is the case)." + " More than one InnerClasses attribute was found.");
  624.                     }
  625.                     if (!hasInnerClass) {
  626.                         addMessage("No referenced Inner Class found, but InnerClasses attribute '" + tostring(att)
  627.                             + "' found. Strongly suggest removal of that attribute.");
  628.                     }
  629.                 }

  630.             }
  631.             if (hasInnerClass && !foundInnerClasses) {
  632.                 // throw new ClassConstraintException("A Classfile structure (like '"+tostring(obj)+
  633.                 // "') must have exactly one InnerClasses attribute if at least one Inner Class is referenced (which is the case)."+
  634.                 // " No InnerClasses attribute was found.");
  635.                 // vmspec2, page 125 says it would be a constraint: but existing verifiers
  636.                 // don't check it and javac doesn't satisfy it when it comes to anonymous
  637.                 // inner classes
  638.                 addMessage("A Classfile structure (like '" + tostring(obj)
  639.                     + "') must have exactly one InnerClasses attribute if at least one Inner Class is referenced (which is the case)."
  640.                     + " No InnerClasses attribute was found.");
  641.             }
  642.         }

  643.         @Override
  644.         public void visitLineNumber(final LineNumber obj) {
  645.             // This does not represent an Attribute but is only
  646.             // related to internal BCEL data representation.

  647.             // see visitLineNumberTable(LineNumberTable)
  648.         }

  649.         // SYNTHETIC: see above
  650.         // DEPRECATED: see above
  651.         //////////////////////////////////////////////////////////////
  652.         // code_attribute-structure-ATTRIBUTES (vmspec2 4.7.3, 4.7) //
  653.         //////////////////////////////////////////////////////////////
  654.         @Override
  655.         public void visitLineNumberTable(final LineNumberTable obj) { // vmspec2 4.7.8
  656.             checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

  657.             final String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
  658.             if (!name.equals("LineNumberTable")) {
  659.                 throw new ClassConstraintException(
  660.                     "The LineNumberTable attribute '" + tostring(obj) + "' is not correctly named 'LineNumberTable' but '" + name + "'.");
  661.             }

  662.             // In JustIce, this check is delayed to Pass 3a.
  663.             // LineNumber[] linenumbers = obj.getLineNumberTable();
  664.             // ...validity check...

  665.         }

  666.         //////////
  667.         // BCEL //
  668.         //////////
  669.         @Override
  670.         public void visitLocalVariable(final LocalVariable obj) {
  671.             // This does not represent an Attribute but is only
  672.             // related to internal BCEL data representation.

  673.             // see visitLocalVariableTable(LocalVariableTable)
  674.         }

  675.         @Override
  676.         public void visitLocalVariableTable(final LocalVariableTable obj) { // vmspec2 4.7.9
  677.             // In JustIce, this check is partially delayed to Pass 3a.
  678.             // The other part can be found in the visitCode(Code) method.
  679.         }

  680.         ///////////////////////////
  681.         // METHODS (vmspec2 4.6) //
  682.         ///////////////////////////
  683.         @Override
  684.         public void visitMethod(final Method obj) {

  685.             checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

  686.             final String name = obj.getName();
  687.             if (!validMethodName(name, true)) {
  688.                 throw new ClassConstraintException("Method '" + tostring(obj) + "' has illegal name '" + name + "'.");
  689.             }

  690.             // A descriptor is often named signature in BCEL
  691.             checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);

  692.             final String sig = ((ConstantUtf8) cp.getConstant(obj.getSignatureIndex())).getBytes(); // Method's signature(=descriptor)

  693.             Type t;
  694.             Type[] ts; // needed below the try block.
  695.             try {
  696.                 t = Type.getReturnType(sig);
  697.                 ts = Type.getArgumentTypes(sig);
  698.             } catch (final ClassFormatException cfe) {
  699.                 throw new ClassConstraintException("Illegal descriptor (==signature) '" + sig + "' used by Method '" + tostring(obj) + "'.", cfe);
  700.             }

  701.             // Check if referenced objects exist.
  702.             Type act = t;
  703.             if (act instanceof ArrayType) {
  704.                 act = ((ArrayType) act).getBasicType();
  705.             }
  706.             if (act instanceof ObjectType) {
  707.                 final Verifier v = VerifierFactory.getVerifier(((ObjectType) act).getClassName());
  708.                 final VerificationResult vr = v.doPass1();
  709.                 if (vr != VerificationResult.VR_OK) {
  710.                     throw new ClassConstraintException(
  711.                         "Method '" + tostring(obj) + "' has a return type that does not pass verification pass 1: '" + vr + "'.");
  712.                 }
  713.             }

  714.             for (final Type element : ts) {
  715.                 act = element;
  716.                 if (act instanceof ArrayType) {
  717.                     act = ((ArrayType) act).getBasicType();
  718.                 }
  719.                 if (act instanceof ObjectType) {
  720.                     final Verifier v = VerifierFactory.getVerifier(((ObjectType) act).getClassName());
  721.                     final VerificationResult vr = v.doPass1();
  722.                     if (vr != VerificationResult.VR_OK) {
  723.                         throw new ClassConstraintException(
  724.                             "Method '" + tostring(obj) + "' has an argument type that does not pass verification pass 1: '" + vr + "'.");
  725.                     }
  726.                 }
  727.             }

  728.             // Nearly forgot this! Funny return values are allowed, but a non-empty arguments list makes a different method out of
  729.             // it!
  730.             if (name.equals(Const.STATIC_INITIALIZER_NAME) && ts.length != 0) {
  731.                 throw new ClassConstraintException("Method '" + tostring(obj) + "' has illegal name '" + name + "'."
  732.                     + " Its name resembles the class or interface initialization method" + " which it isn't because of its arguments (==descriptor).");
  733.             }

  734.             if (jc.isClass()) {
  735.                 int maxone = 0;
  736.                 if (obj.isPrivate()) {
  737.                     maxone++;
  738.                 }
  739.                 if (obj.isProtected()) {
  740.                     maxone++;
  741.                 }
  742.                 if (obj.isPublic()) {
  743.                     maxone++;
  744.                 }
  745.                 if (maxone > 1) {
  746.                     throw new ClassConstraintException(
  747.                         "Method '" + tostring(obj) + "' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set.");
  748.                 }

  749.                 if (obj.isAbstract()) {
  750.                     if (obj.isFinal()) {
  751.                         throw new ClassConstraintException("Abstract method '" + tostring(obj) + "' must not have the ACC_FINAL modifier set.");
  752.                     }
  753.                     if (obj.isNative()) {
  754.                         throw new ClassConstraintException("Abstract method '" + tostring(obj) + "' must not have the ACC_NATIVE modifier set.");
  755.                     }
  756.                     if (obj.isPrivate()) {
  757.                         throw new ClassConstraintException("Abstract method '" + tostring(obj) + "' must not have the ACC_PRIVATE modifier set.");
  758.                     }
  759.                     if (obj.isStatic()) {
  760.                         throw new ClassConstraintException("Abstract method '" + tostring(obj) + "' must not have the ACC_STATIC modifier set.");
  761.                     }
  762.                     if (obj.isStrictfp()) {
  763.                         throw new ClassConstraintException("Abstract method '" + tostring(obj) + "' must not have the ACC_STRICT modifier set.");
  764.                     }
  765.                     if (obj.isSynchronized()) {
  766.                         throw new ClassConstraintException("Abstract method '" + tostring(obj) + "' must not have the ACC_SYNCHRONIZED modifier set.");
  767.                     }
  768.                 }

  769.                 // A specific instance initialization method... (vmspec2,Page 116).
  770.                 // ..may have at most one of ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC set: is checked above.
  771.                 // ..may also have ACC_STRICT set, but none of the other flags in table 4.5 (vmspec2, page 115)
  772.                 if (name.equals(Const.CONSTRUCTOR_NAME) && (obj.isStatic() || obj.isFinal() || obj.isSynchronized() || obj.isNative() || obj.isAbstract())) {
  773.                     throw new ClassConstraintException("Instance initialization method '" + tostring(obj) + "' must not have"
  774.                             + " any of the ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT modifiers set.");
  775.                 }
  776.             } else if (!name.equals(Const.STATIC_INITIALIZER_NAME)) { // vmspec2, p.116, 2nd paragraph
  777.                 if (jc.getMajor() >= Const.MAJOR_1_8) {
  778.                     if (obj.isPublic() == obj.isPrivate()) {
  779.                         throw new ClassConstraintException(
  780.                             "Interface method '" + tostring(obj) + "' must have" + " exactly one of its ACC_PUBLIC and ACC_PRIVATE modifiers set.");
  781.                     }
  782.                     if (obj.isProtected() || obj.isFinal() || obj.isSynchronized() || obj.isNative()) {
  783.                         throw new ClassConstraintException("Interface method '" + tostring(obj) + "' must not have"
  784.                             + " any of the ACC_PROTECTED, ACC_FINAL, ACC_SYNCHRONIZED, or ACC_NATIVE modifiers set.");
  785.                     }

  786.                 } else {
  787.                     if (!obj.isPublic()) {
  788.                         throw new ClassConstraintException("Interface method '" + tostring(obj) + "' must have the ACC_PUBLIC modifier set but hasn't!");
  789.                     }
  790.                     if (!obj.isAbstract()) {
  791.                         throw new ClassConstraintException("Interface method '" + tostring(obj) + "' must have the ACC_ABSTRACT modifier set but hasn't!");
  792.                     }
  793.                     if (obj.isPrivate() || obj.isProtected() || obj.isStatic() || obj.isFinal() || obj.isSynchronized() || obj.isNative() || obj.isStrictfp()) {
  794.                         throw new ClassConstraintException("Interface method '" + tostring(obj) + "' must not have"
  795.                             + " any of the ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED,"
  796.                             + " ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT modifiers set.");
  797.                     }
  798.                 }
  799.             }

  800.             if ((obj.getAccessFlags() & ~(Const.ACC_PUBLIC | Const.ACC_PRIVATE | Const.ACC_PROTECTED | Const.ACC_STATIC | Const.ACC_FINAL |
  801.                 Const.ACC_SYNCHRONIZED | Const.ACC_NATIVE | Const.ACC_ABSTRACT | Const.ACC_STRICT)) > 0) {
  802.                 addMessage("Method '" + tostring(obj) + "' has access flag(s) other than" + " ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,"
  803.                     + " ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT set (ignored).");
  804.             }

  805.             final String nameanddesc = name + sig;
  806.             if (methodNamesAndDesc.contains(nameanddesc)) {
  807.                 throw new ClassConstraintException("No two methods (like '" + tostring(obj) + "') are allowed have same names and desciptors!");
  808.             }
  809.             methodNamesAndDesc.add(nameanddesc);

  810.             final Attribute[] atts = obj.getAttributes();
  811.             int numCodeAtts = 0;
  812.             for (final Attribute att : atts) {
  813.                 if (!(att instanceof Code) && !(att instanceof ExceptionTable) && !(att instanceof Synthetic) && !(att instanceof Deprecated)) {
  814.                     addMessage("Attribute '" + tostring(att) + "' as an attribute of Method '" + tostring(obj) + "' is unknown and will therefore be ignored.");
  815.                 }
  816.                 if (!(att instanceof Code) && !(att instanceof ExceptionTable)) {
  817.                     addMessage("Attribute '" + tostring(att) + "' as an attribute of Method '" + tostring(obj)
  818.                         + "' is neither Code nor Exceptions and is therefore only of use for debuggers and such.");
  819.                 }
  820.                 if (att instanceof Code && (obj.isNative() || obj.isAbstract())) {
  821.                     throw new ClassConstraintException(
  822.                         "Native or abstract methods like '" + tostring(obj) + "' must not have a Code attribute like '" + tostring(att) + "'."); // vmspec2
  823.                                                                                                                                                  // page120,
  824.                                                                                                                                                  // 4.7.3
  825.                 }
  826.                 if (att instanceof Code) {
  827.                     numCodeAtts++;
  828.                 }
  829.             }
  830.             if (!obj.isNative() && !obj.isAbstract() && numCodeAtts != 1) {
  831.                 throw new ClassConstraintException(
  832.                     "Non-native, non-abstract methods like '" + tostring(obj) + "' must have exactly one Code attribute (found: " + numCodeAtts + ").");
  833.             }
  834.         }

  835.         ///////////////////////////////////////////////////////
  836.         // ClassFile-structure-ATTRIBUTES (vmspec2 4.1, 4.7) //
  837.         ///////////////////////////////////////////////////////
  838.         @Override
  839.         public void visitSourceFile(final SourceFile obj) { // vmspec2 4.7.7

  840.             // zero or one SourceFile attr per ClassFile: see visitJavaClass()

  841.             checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

  842.             final String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
  843.             if (!name.equals("SourceFile")) {
  844.                 throw new ClassConstraintException("The SourceFile attribute '" + tostring(obj) + "' is not correctly named 'SourceFile' but '" + name + "'.");
  845.             }

  846.             checkIndex(obj, obj.getSourceFileIndex(), CONST_Utf8);

  847.             final String sourceFileName = ((ConstantUtf8) cp.getConstant(obj.getSourceFileIndex())).getBytes(); // ==obj.getSourceFileName() ?
  848.             final String sourceFileNameLc = sourceFileName.toLowerCase(Locale.ENGLISH);

  849.             if (sourceFileName.indexOf('/') != -1 || sourceFileName.indexOf('\\') != -1 || sourceFileName.indexOf(':') != -1
  850.                 || sourceFileNameLc.lastIndexOf(".java") == -1) {
  851.                 addMessage("SourceFile attribute '" + tostring(obj)
  852.                     + "' has a funny name: remember not to confuse certain parsers working on javap's output. Also, this name ('" + sourceFileName
  853.                     + "') is considered an unqualified (simple) file name only.");
  854.             }
  855.         }

  856.         @Override
  857.         public void visitSynthetic(final Synthetic obj) { // vmspec2 4.7.6
  858.             checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
  859.             final String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
  860.             if (!name.equals("Synthetic")) {
  861.                 throw new ClassConstraintException("The Synthetic attribute '" + tostring(obj) + "' is not correctly named 'Synthetic' but '" + name + "'.");
  862.             }
  863.         }

  864.         ////////////////////////////////////////////////////
  865.         // MISC-structure-ATTRIBUTES (vmspec2 4.7.1, 4.7) //
  866.         ////////////////////////////////////////////////////
  867.         @Override
  868.         public void visitUnknown(final Unknown obj) { // vmspec2 4.7.1
  869.             // Represents an unknown attribute.
  870.             checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

  871.             // Maybe only misnamed? Give a (warning) message.
  872.             addMessage("Unknown attribute '" + tostring(obj) + "'. This attribute is not known in any context!");
  873.         }
  874.     }

  875.     /**
  876.      * A Visitor class that ensures the ConstantCP-subclassed entries of the constant pool are valid. <B>Precondition:
  877.      * index-style cross referencing in the constant pool must be valid.</B>
  878.      *
  879.      * @see #constantPoolEntriesSatisfyStaticConstraints()
  880.      * @see org.apache.bcel.classfile.ConstantCP
  881.      */
  882.     private final class FAMRAV_Visitor extends EmptyVisitor {
  883.         private final ConstantPool cp; // ==jc.getConstantPool() -- only here to save typing work.

  884.         private FAMRAV_Visitor(final JavaClass jc) {
  885.             this.cp = jc.getConstantPool();
  886.         }

  887.         @Override
  888.         public void visitConstantFieldref(final ConstantFieldref obj) {
  889.             if (obj.getTag() != Const.CONSTANT_Fieldref) {
  890.                 throw new ClassConstraintException("ConstantFieldref '" + tostring(obj) + "' has wrong tag!");
  891.             }
  892.             final int nameAndTypeIndex = obj.getNameAndTypeIndex();
  893.             final ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(nameAndTypeIndex);
  894.             final String name = ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes(); // Field or Method name
  895.             if (!validFieldName(name)) {
  896.                 throw new ClassConstraintException("Invalid field name '" + name + "' referenced by '" + tostring(obj) + "'.");
  897.             }

  898.             final int classIndex = obj.getClassIndex();
  899.             final ConstantClass cc = (ConstantClass) cp.getConstant(classIndex);
  900.             final String className = ((ConstantUtf8) cp.getConstant(cc.getNameIndex())).getBytes(); // Class Name in internal form
  901.             if (!validClassName(className)) {
  902.                 throw new ClassConstraintException("Illegal class name '" + className + "' used by '" + tostring(obj) + "'.");
  903.             }

  904.             final String sig = ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes(); // Field or Method sig.(=descriptor)

  905.             try {
  906.                 Type.getType(sig); /* Don't need the return value */
  907.             } catch (final ClassFormatException cfe) {
  908.                 throw new ClassConstraintException("Illegal descriptor (==signature) '" + sig + "' used by '" + tostring(obj) + "'.", cfe);
  909.             }
  910.         }

  911.         @Override
  912.         public void visitConstantInterfaceMethodref(final ConstantInterfaceMethodref obj) {
  913.             if (obj.getTag() != Const.CONSTANT_InterfaceMethodref) {
  914.                 throw new ClassConstraintException("ConstantInterfaceMethodref '" + tostring(obj) + "' has wrong tag!");
  915.             }
  916.             final int nameAndTypeIndex = obj.getNameAndTypeIndex();
  917.             final ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(nameAndTypeIndex);
  918.             final String name = ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes(); // Field or Method name
  919.             if (!validInterfaceMethodName(name)) {
  920.                 throw new ClassConstraintException("Invalid (interface) method name '" + name + "' referenced by '" + tostring(obj) + "'.");
  921.             }

  922.             final int classIndex = obj.getClassIndex();
  923.             final ConstantClass cc = (ConstantClass) cp.getConstant(classIndex);
  924.             final String className = ((ConstantUtf8) cp.getConstant(cc.getNameIndex())).getBytes(); // Class Name in internal form
  925.             if (!validClassName(className)) {
  926.                 throw new ClassConstraintException("Illegal class name '" + className + "' used by '" + tostring(obj) + "'.");
  927.             }

  928.             final String sig = ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes(); // Field or Method sig.(=descriptor)

  929.             try {
  930.                 final Type t = Type.getReturnType(sig);
  931.                 if (name.equals(Const.STATIC_INITIALIZER_NAME) && t != Type.VOID) {
  932.                     addMessage("Class or interface initialization method '" + Const.STATIC_INITIALIZER_NAME + "' usually has VOID return type instead of '" + t
  933.                         + "'. Note this is really not a requirement of The Java Virtual Machine Specification, Second Edition.");
  934.                 }
  935.             } catch (final ClassFormatException cfe) {
  936.                 throw new ClassConstraintException("Illegal descriptor (==signature) '" + sig + "' used by '" + tostring(obj) + "'.", cfe);
  937.             }

  938.         }

  939.         @Override
  940.         public void visitConstantMethodref(final ConstantMethodref obj) {
  941.             if (obj.getTag() != Const.CONSTANT_Methodref) {
  942.                 throw new ClassConstraintException("ConstantMethodref '" + tostring(obj) + "' has wrong tag!");
  943.             }
  944.             final int nameAndTypeIndex = obj.getNameAndTypeIndex();
  945.             final ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(nameAndTypeIndex);
  946.             final String name = ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes(); // Field or Method name
  947.             if (!validClassMethodName(name)) {
  948.                 throw new ClassConstraintException("Invalid (non-interface) method name '" + name + "' referenced by '" + tostring(obj) + "'.");
  949.             }

  950.             final int classIndex = obj.getClassIndex();
  951.             final ConstantClass cc = (ConstantClass) cp.getConstant(classIndex);
  952.             final String className = ((ConstantUtf8) cp.getConstant(cc.getNameIndex())).getBytes(); // Class Name in internal form
  953.             if (!validClassName(className)) {
  954.                 throw new ClassConstraintException("Illegal class name '" + className + "' used by '" + tostring(obj) + "'.");
  955.             }

  956.             final String sig = ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes(); // Field or Method sig.(=descriptor)

  957.             try {
  958.                 final Type t = Type.getReturnType(sig);
  959.                 if (name.equals(Const.CONSTRUCTOR_NAME) && t != Type.VOID) {
  960.                     throw new ClassConstraintException("Instance initialization method must have VOID return type.");
  961.                 }
  962.             } catch (final ClassFormatException cfe) {
  963.                 throw new ClassConstraintException("Illegal descriptor (==signature) '" + sig + "' used by '" + tostring(obj) + "'.", cfe);
  964.             }
  965.         }

  966.     }

  967.     /**
  968.      * This class serves for finding out if a given JavaClass' ConstantPool references an Inner Class. The Java Virtual
  969.      * Machine Specification, Second Edition is not very precise about when an "InnerClasses" attribute has to appear.
  970.      * However, it states that there has to be exactly one InnerClasses attribute in the ClassFile structure if the constant
  971.      * pool of a class or interface refers to any class or interface "that is not a member of a package". Sun does not mean
  972.      * "member of the default package". In "Inner Classes Specification" they point out how a "bytecode name" is derived so
  973.      * one has to deduce what a class name of a class "that is not a member of a package" looks like: there is at least one
  974.      * character in the byte- code name that cannot be part of a legal Java Language Class name (and not equal to '/'). This
  975.      * assumption is wrong as the delimiter is '$' for which Character.isJavaIdentifierPart() == true. Hence, you really run
  976.      * into trouble if you have a toplevel class called "A$XXX" and another toplevel class called "A" with in inner class
  977.      * called "XXX". JustIce cannot repair this; please note that existing verifiers at this time even fail to detect
  978.      * missing InnerClasses attributes in pass 2.
  979.      */
  980.     private static final class InnerClassDetector extends EmptyVisitor {
  981.         private boolean hasInnerClass;
  982.         private final JavaClass jc;
  983.         private final ConstantPool cp;

  984.         /** Constructs an InnerClassDetector working on the JavaClass _jc. */
  985.         public InnerClassDetector(final JavaClass javaClass) {
  986.             this.jc = javaClass;
  987.             this.cp = jc.getConstantPool();
  988.             new DescendingVisitor(jc, this).visit();
  989.         }

  990.         /**
  991.          * Returns if the JavaClass this InnerClassDetector is working on has an Inner Class reference in its constant pool.
  992.          *
  993.          * @return Whether this InnerClassDetector is working on has an Inner Class reference in its constant pool.
  994.          */
  995.         public boolean innerClassReferenced() {
  996.             return hasInnerClass;
  997.         }

  998.         /** This method casually visits ConstantClass references. */
  999.         @Override
  1000.         public void visitConstantClass(final ConstantClass obj) {
  1001.             final Constant c = cp.getConstant(obj.getNameIndex());
  1002.             if (c instanceof ConstantUtf8) { // Ignore the case where it's not a ConstantUtf8 here, we'll find out later.
  1003.                 final String className = ((ConstantUtf8) c).getBytes();
  1004.                 if (className.startsWith(Utility.packageToPath(jc.getClassName()) + "$")) {
  1005.                     hasInnerClass = true;
  1006.                 }
  1007.             }
  1008.         }
  1009.     }

  1010.     /**
  1011.      * This method is here to save typing work and improve code readability.
  1012.      */
  1013.     private static String tostring(final Node n) {
  1014.         return new StringRepresentation(n).toString();
  1015.     }

  1016.     /**
  1017.      * This method returns true if and only if the supplied String represents a valid method name that may be referenced by
  1018.      * ConstantMethodref objects.
  1019.      */
  1020.     private static boolean validClassMethodName(final String name) {
  1021.         return validMethodName(name, false);
  1022.     }

  1023.     /**
  1024.      * This method returns true if and only if the supplied String represents a valid Java class name.
  1025.      */
  1026.     private static boolean validClassName(final String name) {
  1027.         /*
  1028.          * TODO: implement. Are there any restrictions?
  1029.          */
  1030.         Objects.requireNonNull(name, "name");
  1031.         return true;
  1032.     }

  1033.     /**
  1034.      * This method returns true if and only if the supplied String represents a valid Java field name.
  1035.      */
  1036.     private static boolean validFieldName(final String name) {
  1037.         // vmspec2 2.7, vmspec2 2.2
  1038.         return validJavaIdentifier(name);
  1039.     }

  1040.     /**
  1041.      * This method returns true if and only if the supplied String represents a valid Java interface method name that may be
  1042.      * referenced by ConstantInterfaceMethodref objects.
  1043.      */
  1044.     private static boolean validInterfaceMethodName(final String name) {
  1045.         // I guess we should assume special names forbidden here.
  1046.         if (name.startsWith("<")) {
  1047.             return false;
  1048.         }
  1049.         return validJavaLangMethodName(name);
  1050.     }

  1051.     /**
  1052.      * This method returns true if and only if the supplied String represents a valid Java identifier (so-called simple or
  1053.      * unqualified name).
  1054.      */
  1055.     private static boolean validJavaIdentifier(final String name) {
  1056.         // vmspec2 2.7, vmspec2 2.2
  1057.         if (name.isEmpty() || !Character.isJavaIdentifierStart(name.charAt(0))) {
  1058.             return false;
  1059.         }

  1060.         for (int i = 1; i < name.length(); i++) {
  1061.             if (!Character.isJavaIdentifierPart(name.charAt(i))) {
  1062.                 return false;
  1063.             }
  1064.         }
  1065.         return true;
  1066.     }

  1067.     /**
  1068.      * This method returns true if and only if the supplied String represents a valid Java programming language method name
  1069.      * stored as a simple (non-qualified) name. Conforming to: The Java Virtual Machine Specification, Second Edition,
  1070.      * �2.7, �2.7.1, �2.2.
  1071.      */
  1072.     private static boolean validJavaLangMethodName(final String name) {
  1073.         return validJavaIdentifier(name);
  1074.     }

  1075.     /**
  1076.      * This method returns true if and only if the supplied String represents a valid method name. This is basically the
  1077.      * same as a valid identifier name in the Java programming language, but the special name for the instance
  1078.      * initialization method is allowed and the special name for the class/interface initialization method may be allowed.
  1079.      */
  1080.     private static boolean validMethodName(final String name, final boolean allowStaticInit) {
  1081.         if (validJavaLangMethodName(name)) {
  1082.             return true;
  1083.         }

  1084.         if (allowStaticInit) {
  1085.             return name.equals(Const.CONSTRUCTOR_NAME) || name.equals(Const.STATIC_INITIALIZER_NAME);
  1086.         }
  1087.         return name.equals(Const.CONSTRUCTOR_NAME);
  1088.     }

  1089.     /**
  1090.      * The LocalVariableInfo instances used by Pass3bVerifier. localVariablesInfos[i] denotes the information for the local
  1091.      * variables of method number i in the JavaClass this verifier operates on.
  1092.      */
  1093.     private LocalVariablesInfo[] localVariablesInfos;
  1094.     /** The Verifier that created this. */
  1095.     private final Verifier verifier;

  1096.     /**
  1097.      * Should only be instantiated by a Verifier.
  1098.      *
  1099.      * @see Verifier
  1100.      */
  1101.     public Pass2Verifier(final Verifier verifier) {
  1102.         this.verifier = verifier;
  1103.     }

  1104.     /**
  1105.      * Ensures that the constant pool entries satisfy the static constraints as described in The Java Virtual Machine
  1106.      * Specification, 2nd Edition.
  1107.      *
  1108.      * @throws ClassConstraintException otherwise.
  1109.      */
  1110.     private void constantPoolEntriesSatisfyStaticConstraints() {
  1111.         try {
  1112.             // Most of the consistency is handled internally by BCEL; here
  1113.             // we only have to verify if the indices of the constants point
  1114.             // to constants of the appropriate type and such.
  1115.             final JavaClass jc = Repository.lookupClass(verifier.getClassName());
  1116.             new CPESSC_Visitor(jc); // constructor implicitly traverses jc

  1117.         } catch (final ClassNotFoundException e) {
  1118.             // FIXME: this might not be the best way to handle missing classes.
  1119.             throw new AssertionViolatedException("Missing class: " + e, e);
  1120.         }
  1121.     }

  1122.     /**
  1123.      * Pass 2 is the pass where static properties of the class file are checked without looking into "Code" arrays of
  1124.      * methods. This verification pass is usually invoked when a class is resolved; and it may be possible that this
  1125.      * verification pass has to load in other classes such as superclasses or implemented interfaces. Therefore, Pass 1 is
  1126.      * run on them.<BR>
  1127.      * Note that most referenced classes are <B>not</B> loaded in for verification or for an existance check by this pass;
  1128.      * only the syntactical correctness of their names and descriptors (a.k.a. signatures) is checked.<BR>
  1129.      * Very few checks that conceptually belong here are delayed until pass 3a in JustIce. JustIce does not only check for
  1130.      * syntactical correctness but also for semantical sanity - therefore it needs access to the "Code" array of methods in
  1131.      * a few cases. Please see the pass 3a documentation, too.
  1132.      *
  1133.      * @see Pass3aVerifier
  1134.      */
  1135.     @Override
  1136.     public VerificationResult do_verify() {
  1137.         try {
  1138.             final VerificationResult vr1 = verifier.doPass1();
  1139.             if (vr1.equals(VerificationResult.VR_OK)) {

  1140.                 // For every method, we could have information about the local variables out of LocalVariableTable attributes of
  1141.                 // the Code attributes.
  1142.                 localVariablesInfos = new LocalVariablesInfo[Repository.lookupClass(verifier.getClassName()).getMethods().length];

  1143.                 VerificationResult vr = VerificationResult.VR_OK; // default.
  1144.                 try {
  1145.                     constantPoolEntriesSatisfyStaticConstraints();
  1146.                     fieldAndMethodRefsAreValid();
  1147.                     everyClassHasAnAccessibleSuperclass();
  1148.                     finalMethodsAreNotOverridden();
  1149.                 } catch (final ClassConstraintException cce) {
  1150.                     vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, cce.getMessage());
  1151.                 }
  1152.                 return vr;
  1153.             }
  1154.             return VerificationResult.VR_NOTYET;

  1155.         } catch (final ClassNotFoundException e) {
  1156.             // FIXME: this might not be the best way to handle missing classes.
  1157.             throw new AssertionViolatedException("Missing class: " + e, e);
  1158.         }
  1159.     }

  1160.     /**
  1161.      * Ensures that every class has a super class and that <B>final</B> classes are not subclassed. This means, the class
  1162.      * this Pass2Verifier operates on has proper super classes (transitively) up to {@link Object}. The reason for really
  1163.      * loading (and Pass1-verifying) all of those classes here is that we need them in Pass2 anyway to verify no final
  1164.      * methods are overridden (that could be declared anywhere in the ancestor hierarchy).
  1165.      *
  1166.      * @throws ClassConstraintException otherwise.
  1167.      */
  1168.     private void everyClassHasAnAccessibleSuperclass() {
  1169.         try {
  1170.             final Set<String> hs = new HashSet<>(); // save class names to detect circular inheritance
  1171.             JavaClass jc = Repository.lookupClass(verifier.getClassName());
  1172.             int supidx = -1;

  1173.             while (supidx != 0) {
  1174.                 supidx = jc.getSuperclassNameIndex();

  1175.                 if (supidx == 0) {
  1176.                     if (jc != Repository.lookupClass(Type.OBJECT.getClassName())) {
  1177.                         throw new ClassConstraintException(
  1178.                             "Superclass of '" + jc.getClassName() + "' missing but not " + Type.OBJECT.getClassName() + " itself!");
  1179.                     }
  1180.                 } else {
  1181.                     final String supername = jc.getSuperclassName();
  1182.                     if (!hs.add(supername)) { // If supername already is in the list
  1183.                         throw new ClassConstraintException("Circular superclass hierarchy detected.");
  1184.                     }
  1185.                     final Verifier v = VerifierFactory.getVerifier(supername);
  1186.                     final VerificationResult vr = v.doPass1();

  1187.                     if (vr != VerificationResult.VR_OK) {
  1188.                         throw new ClassConstraintException("Could not load in ancestor class '" + supername + "'.");
  1189.                     }
  1190.                     jc = Repository.lookupClass(supername);

  1191.                     if (jc.isFinal()) {
  1192.                         throw new ClassConstraintException(
  1193.                             "Ancestor class '" + supername + "' has the FINAL access modifier and must therefore not be subclassed.");
  1194.                     }
  1195.                 }
  1196.             }

  1197.         } catch (final ClassNotFoundException e) {
  1198.             // FIXME: this might not be the best way to handle missing classes.
  1199.             throw new AssertionViolatedException("Missing class: " + e, e);
  1200.         }
  1201.     }

  1202.     /**
  1203.      * Ensures that the ConstantCP-subclassed entries of the constant pool are valid. According to "Yellin: Low Level
  1204.      * Security in Java", this method does not verify the existence of referenced entities (such as classes) but only the
  1205.      * formal correctness (such as well-formed signatures). The visitXXX() methods throw ClassConstraintException instances
  1206.      * otherwise. <B>Precondition: index-style cross referencing in the constant pool must be valid. Simply invoke
  1207.      * constant_pool_entries_satisfy_static_constraints() before.</B>
  1208.      *
  1209.      * @throws ClassConstraintException otherwise.
  1210.      * @see #constantPoolEntriesSatisfyStaticConstraints()
  1211.      */
  1212.     private void fieldAndMethodRefsAreValid() {
  1213.         try {
  1214.             final JavaClass jc = Repository.lookupClass(verifier.getClassName());
  1215.             final DescendingVisitor v = new DescendingVisitor(jc, new FAMRAV_Visitor(jc));
  1216.             v.visit();

  1217.         } catch (final ClassNotFoundException e) {
  1218.             // FIXME: this might not be the best way to handle missing classes.
  1219.             throw new AssertionViolatedException("Missing class: " + e, e);
  1220.         }
  1221.     }

  1222.     /**
  1223.      * Ensures that <B>final</B> methods are not overridden. <B>Precondition to run this method:
  1224.      * constant_pool_entries_satisfy_static_constraints() and every_class_has_an_accessible_superclass() have to be invoked
  1225.      * before (in that order).</B>
  1226.      *
  1227.      * @throws ClassConstraintException otherwise.
  1228.      * @see #constantPoolEntriesSatisfyStaticConstraints()
  1229.      * @see #everyClassHasAnAccessibleSuperclass()
  1230.      */
  1231.     private void finalMethodsAreNotOverridden() {
  1232.         try {
  1233.             final Map<String, String> map = new HashMap<>();
  1234.             JavaClass jc = Repository.lookupClass(verifier.getClassName());

  1235.             int supidx = -1;
  1236.             while (supidx != 0) {
  1237.                 supidx = jc.getSuperclassNameIndex();

  1238.                 final Method[] methods = jc.getMethods();
  1239.                 for (final Method method : methods) {
  1240.                     final String nameAndSig = method.getName() + method.getSignature();

  1241.                     if (map.containsKey(nameAndSig) && method.isFinal()) {
  1242.                         if (!method.isPrivate()) {
  1243.                             throw new ClassConstraintException("Method '" + nameAndSig + "' in class '" + map.get(nameAndSig)
  1244.                                 + "' overrides the final (not-overridable) definition in class '" + jc.getClassName() + "'.");
  1245.                         }
  1246.                         addMessage("Method '" + nameAndSig + "' in class '" + map.get(nameAndSig)
  1247.                             + "' overrides the final (not-overridable) definition in class '" + jc.getClassName()
  1248.                             + "'. This is okay, as the original definition was private; however this constraint leverage"
  1249.                             + " was introduced by JLS 8.4.6 (not vmspec2) and the behavior of the Sun verifiers.");
  1250.                     } else if (!method.isStatic()) { // static methods don't inherit
  1251.                         map.put(nameAndSig, jc.getClassName());
  1252.                     }
  1253.                 }

  1254.                 jc = Repository.lookupClass(jc.getSuperclassName());
  1255.                 // Well, for OBJECT this returns OBJECT so it works (could return anything but must not throw an Exception).
  1256.             }

  1257.         } catch (final ClassNotFoundException e) {
  1258.             // FIXME: this might not be the best way to handle missing classes.
  1259.             throw new AssertionViolatedException("Missing class: " + e, e);
  1260.         }

  1261.     }

  1262.     /**
  1263.      * Returns a LocalVariablesInfo object containing information about the usage of the local variables in the Code
  1264.      * attribute of the said method or <B>null</B> if the class file this Pass2Verifier operates on could not be
  1265.      * pass-2-verified correctly. The method number method_nr is the method you get using
  1266.      * <B>Repository.lookupClass(myOwner.getClassname()).getMethods()[method_nr];</B>. You should not add own information.
  1267.      * Leave that to JustIce.
  1268.      */
  1269.     public LocalVariablesInfo getLocalVariablesInfo(final int methodNr) {
  1270.         if (verify() != VerificationResult.VR_OK) {
  1271.             return null; // It's cached, don't worry.
  1272.         }
  1273.         if (methodNr < 0 || methodNr >= localVariablesInfos.length) {
  1274.             throw new AssertionViolatedException("Method number out of range.");
  1275.         }
  1276.         return localVariablesInfos[methodNr];
  1277.     }
  1278. }