Java Code Examples for org.apache.bcel.classfile.ConstantPool

The following examples show how to use org.apache.bcel.classfile.ConstantPool. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: uyuni   Source File: FindStrings.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Main class, to find strings in class files.
 * @param args Arguments to program.
 */
public static void main(String[] args) {
    try {
        JavaClass clazz = Repository.lookupClass(args[0]);
        ConstantPool cp = clazz.getConstantPool();
        Constant[] consts = cp.getConstantPool();


        for (int i = 0; i < consts.length; i++) {

            if (consts[i] instanceof ConstantString) {
                System.out.println("Found String: " +
                        ((ConstantString)consts[i]).getBytes(cp));
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source Project: cloud-opensource-java   Source File: ClassDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the indices of all class symbol references to {@code targetClassName} in the constant
 * pool of {@code sourceJavaClass}.
 */
ImmutableSet<Integer> constantPoolIndexForClass(
    JavaClass sourceJavaClass, String targetClassName) {
  ImmutableSet.Builder<Integer> constantPoolIndicesForTarget = ImmutableSet.builder();

  ConstantPool sourceConstantPool = sourceJavaClass.getConstantPool();
  Constant[] constantPool = sourceConstantPool.getConstantPool();
  // constantPool indexes start from 1. 0th entry is null.
  for (int poolIndex = 1; poolIndex < constantPool.length; poolIndex++) {
    Constant constant = constantPool[poolIndex];
    if (constant != null) {
      byte constantTag = constant.getTag();
      if (constantTag == Const.CONSTANT_Class) {
        ConstantClass constantClass = (ConstantClass) constant;
        ClassSymbol classSymbol = makeSymbol(constantClass, sourceConstantPool, sourceJavaClass);
        if (targetClassName.equals(classSymbol.getClassBinaryName())) {
          constantPoolIndicesForTarget.add(poolIndex);
        }
      }
    }
  }

  return constantPoolIndicesForTarget.build();
}
 
Example 3
/**
 * Returns true if given constant pool probably has a reference to any of supplied methods
 * Useful to exclude from analysis uninteresting classes
 * @param cp constant pool
 * @param methods methods collection
 * @return true if method is found
 */
public static boolean hasInterestingMethod(ConstantPool cp, Collection<MethodDescriptor> methods) {
    for (Constant c : cp.getConstantPool()) {
        if (c instanceof ConstantMethodref || c instanceof ConstantInterfaceMethodref) {
            ConstantCP desc = (ConstantCP) c;
            ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(desc.getNameAndTypeIndex());
            String className = cp.getConstantString(desc.getClassIndex(), Const.CONSTANT_Class);
            String name = ((ConstantUtf8) cp.getConstant(nameAndType.getNameIndex())).getBytes();
            String signature = ((ConstantUtf8) cp.getConstant(nameAndType.getSignatureIndex())).getBytes();
            // We don't know whether method is static thus cannot use equals
            int hash = FieldOrMethodDescriptor.getNameSigHashCode(name, signature);
            for (MethodDescriptor method : methods) {
                if (method.getNameSigHashCode() == hash
                        && (method.getSlashedClassName().isEmpty() || method.getSlashedClassName().equals(className))
                        && method.getName().equals(name) && method.getSignature().equals(signature)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 4
@Override
public void visit(ConstantPool pool) {
    for (Constant constant : pool.getConstantPool()) {
        if (constant instanceof ConstantClass) {
            ConstantClass cc = (ConstantClass) constant;
            @SlashedClassName
            String className = cc.getBytes(pool);
            if ("java/util/Calendar".equals(className) || "java/text/DateFormat".equals(className)) {
                sawDateClass = true;
                break;
            }
            if (className.charAt(0) != '[') {
                try {
                    ClassDescriptor cDesc = DescriptorFactory.createClassDescriptor(className);

                    if (subtypes2.isSubtype(cDesc, calendarType) || subtypes2.isSubtype(cDesc, dateFormatType)) {
                        sawDateClass = true;
                        break;
                    }
                } catch (ClassNotFoundException e) {
                    reporter.reportMissingClass(e);
                }
            }
        }
    }
}
 
Example 5
public boolean isCaught(ClassContext classContext, Method method, UnconditionalValueDerefSet entryFact, ValueNumber paramVN) {
    boolean caught = true;

    Set<Location> dereferenceSites = entryFact.getDerefLocationSet(paramVN);
    if (dereferenceSites != null && !dereferenceSites.isEmpty()) {
        ConstantPool cp = classContext.getJavaClass().getConstantPool();

        for (Location loc : dereferenceSites) {
            if (!FindNullDeref.catchesNull(cp, method.getCode(), loc)) {
                caught = false;
            }
        }

    }
    return caught;
}
 
Example 6
/**
 * Called to indicate that a field load or store was encountered.
 *
 * @param cpIndex
 *            the constant pool index of the fieldref
 * @param isStatic
 *            true if it is a static field access
 * @param isLoad
 *            true if the access is a load
 */
private void setField(int cpIndex, boolean isStatic, boolean isLoad) {
    // We only allow one field access for an accessor method.
    accessCount++;
    if (accessCount != 1) {
        access = null;
        return;
    }

    ConstantPool cp = javaClass.getConstantPool();
    ConstantFieldref fieldref = (ConstantFieldref) cp.getConstant(cpIndex);

    ConstantClass cls = (ConstantClass) cp.getConstant(fieldref.getClassIndex());
    String className = cls.getBytes(cp).replace('/', '.');

    ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(fieldref.getNameAndTypeIndex());
    String fieldName = nameAndType.getName(cp);
    String fieldSig = nameAndType.getSignature(cp);


    XField xfield = Hierarchy.findXField(className, fieldName, fieldSig, isStatic);
    if (xfield != null && xfield.isStatic() == isStatic && isValidAccessMethod(methodSig, xfield, isLoad)) {
        access = new InnerClassAccess(methodName, methodSig, xfield, isLoad);
    }

}
 
Example 7
Source Project: spacewalk   Source File: FindStrings.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Main class, to find strings in class files.
 * @param args Arguments to program.
 */
public static void main(String[] args) {
    try {
        JavaClass clazz = Repository.lookupClass(args[0]);
        ConstantPool cp = clazz.getConstantPool();
        Constant[] consts = cp.getConstantPool();


        for (int i = 0; i < consts.length; i++) {

            if (consts[i] instanceof ConstantString) {
                System.out.println("Found String: " +
                        ((ConstantString)consts[i]).getBytes(cp));
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 8
Source Project: commons-bcel   Source File: helloify.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(final String[] argv) throws Exception {
    for (final String arg : argv) {
        if (arg.endsWith(".class")) {
            final JavaClass java_class = new ClassParser(arg).parse();
            final ConstantPool constants = java_class.getConstantPool();
            final String file_name = arg.substring(0, arg.length() - 6) + "_hello.class";
            cp = new ConstantPoolGen(constants);

            helloifyClassName(java_class);

            out = cp.addFieldref("java.lang.System", "out", "Ljava/io/PrintStream;");
            println = cp.addMethodref("java.io.PrintStream", "println", "(Ljava/lang/String;)V");
            // Patch all methods.
            final Method[] methods = java_class.getMethods();

            for (int j = 0; j < methods.length; j++) {
                methods[j] = helloifyMethod(methods[j]);
            }

            // Finally dump it back to a file.
            java_class.setConstantPool(cp.getFinalConstantPool());
            java_class.dump(file_name);
        }
    }
}
 
Example 9
Source Project: commons-bcel   Source File: listclass.java    License: Apache License 2.0 6 votes vote down vote up
public static String[] getClassDependencies(final ConstantPool pool) {
    final String[] tempArray = new String[pool.getLength()];
    int size = 0;
    final StringBuilder buf = new StringBuilder();

    for (int idx = 0; idx < pool.getLength(); idx++) {
        final Constant c = pool.getConstant(idx);
        if (c != null && c.getTag() == Constants.CONSTANT_Class) {
            final ConstantUtf8 c1 = (ConstantUtf8) pool.getConstant(((ConstantClass) c).getNameIndex());
            buf.setLength(0);
            buf.append(c1.getBytes());
            for (int n = 0; n < buf.length(); n++) {
                if (buf.charAt(n) == '/') {
                    buf.setCharAt(n, '.');
                }
            }

            tempArray[size++] = buf.toString();
        }
    }

    final String[] dependencies = new String[size];
    System.arraycopy(tempArray, 0, dependencies, 0, size);
    return dependencies;
}
 
Example 10
Source Project: commons-bcel   Source File: InvokeInstruction.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return mnemonic for instruction with symbolic references resolved
 */
@Override
public String toString( final ConstantPool cp ) {
    final Constant c = cp.getConstant(super.getIndex());
    final StringTokenizer tok = new StringTokenizer(cp.constantToString(c));

    final String opcodeName = Const.getOpcodeName(super.getOpcode());

    final StringBuilder sb = new StringBuilder(opcodeName);
    if (tok.hasMoreTokens()) {
        sb.append(" ");
        sb.append(tok.nextToken().replace('.', '/'));
        if (tok.hasMoreTokens()) {
            sb.append(tok.nextToken());
        }
    }

    return sb.toString();
}
 
Example 11
Source Project: commons-bcel   Source File: ClassGen.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return the (finally) built up Java class object.
 */
public JavaClass getJavaClass() {
    final int[] interfaces = getInterfaces();
    final Field[] fields = getFields();
    final Method[] methods = getMethods();
    Attribute[] attributes = null;
    if (annotationList.isEmpty()) {
        attributes = getAttributes();
    } else {
        // TODO: Sometime later, trash any attributes called 'RuntimeVisibleAnnotations' or 'RuntimeInvisibleAnnotations'
        final Attribute[] annAttributes  = AnnotationEntryGen.getAnnotationAttributes(cp, getAnnotationEntries());
        attributes = new Attribute[attributeList.size()+annAttributes.length];
        attributeList.toArray(attributes);
        System.arraycopy(annAttributes,0,attributes,attributeList.size(),annAttributes.length);
    }
    // Must be last since the above calls may still add something to it
    final ConstantPool _cp = this.cp.getFinalConstantPool();
    return new JavaClass(classNameIndex, superclass_name_index, fileName, major, minor,
            super.getAccessFlags(), _cp, interfaces, fields, methods, attributes);
}
 
Example 12
Source Project: commons-bcel   Source File: ClassLoader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Override this method to create you own classes on the fly. The
 * name contains the special token $$BCEL$$. Everything before that
 * token is considered to be a package name. You can encode your own
 * arguments into the subsequent string. You must ensure however not
 * to use any "illegal" characters, i.e., characters that may not
 * appear in a Java class name too
 * <p>
 * The default implementation interprets the string as a encoded compressed
 * Java class, unpacks and decodes it with the Utility.decode() method, and
 * parses the resulting byte array and returns the resulting JavaClass object.
 * </p>
 *
 * @param class_name compressed byte code with "$$BCEL$$" in it
 */
protected JavaClass createClass( final String class_name ) {
    final int index = class_name.indexOf(BCEL_TOKEN);
    final String real_name = class_name.substring(index + BCEL_TOKEN.length());
    JavaClass clazz = null;
    try {
        final byte[] bytes = Utility.decode(real_name, true);
        final ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes), "foo");
        clazz = parser.parse();
    } catch (final IOException e) {
        e.printStackTrace();
        return null;
    }
    // Adapt the class name to the passed value
    final ConstantPool cp = clazz.getConstantPool();
    final ConstantClass cl = (ConstantClass) cp.getConstant(clazz.getClassNameIndex(),
            Const.CONSTANT_Class);
    final ConstantUtf8 name = (ConstantUtf8) cp.getConstant(cl.getNameIndex(),
            Const.CONSTANT_Utf8);
    name.setBytes(class_name.replace('.', '/'));
    return clazz;
}
 
Example 13
Source Project: commons-bcel   Source File: ConstantHTML.java    License: Apache License 2.0 6 votes vote down vote up
ConstantHTML(final String dir, final String class_name, final String class_package, final Method[] methods,
        final ConstantPool constant_pool) throws IOException {
    this.className = class_name;
    this.classPackage = class_package;
    this.constantPool = constant_pool;
    this.methods = methods;
    constants = constant_pool.getConstantPool();
    file = new PrintWriter(new FileOutputStream(dir + class_name + "_cp.html"));
    constantRef = new String[constants.length];
    constantRef[0] = "&lt;unknown&gt;";
    file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>");
    // Loop through constants, constants[0] is reserved
    for (int i = 1; i < constants.length; i++) {
        if (i % 2 == 0) {
            file.print("<TR BGCOLOR=\"#C0C0C0\"><TD>");
        } else {
            file.print("<TR BGCOLOR=\"#A0A0A0\"><TD>");
        }
        if (constants[i] != null) {
            writeConstant(i);
        }
        file.print("</TD></TR>\n");
    }
    file.println("</TABLE></BODY></HTML>");
    file.close();
}
 
Example 14
/**
 * Verify for an inner class declared inside the 'main' method that the
 * enclosing method attribute is set correctly.
 */
public void testCheckMethodLevelNamedInnerClass()
        throws ClassNotFoundException
{
    final JavaClass clazz = getTestClass(PACKAGE_BASE_NAME+".data.AttributeTestClassEM01$1S");
    final ConstantPool pool = clazz.getConstantPool();
    final Attribute[] encMethodAttrs = findAttribute("EnclosingMethod", clazz);
    assertTrue("Expected 1 EnclosingMethod attribute but found "
            + encMethodAttrs.length, encMethodAttrs.length == 1);
    final EnclosingMethod em = (EnclosingMethod) encMethodAttrs[0];
    final String enclosingClassName = em.getEnclosingClass().getBytes(pool);
    final String enclosingMethodName = em.getEnclosingMethod().getName(pool);
    assertTrue(
            "Expected class name to be '"+PACKAGE_BASE_SIG+"/data/AttributeTestClassEM01' but was "
                    + enclosingClassName, enclosingClassName
                    .equals(PACKAGE_BASE_SIG+"/data/AttributeTestClassEM01"));
    assertTrue("Expected method name to be 'main' but was "
            + enclosingMethodName, enclosingMethodName.equals("main"));
}
 
Example 15
/**
 * Verify for an inner class declared at the type level that the
 * EnclosingMethod attribute is set correctly (i.e. to a null value)
 */
public void testCheckClassLevelNamedInnerClass()
        throws ClassNotFoundException
{
    final JavaClass clazz = getTestClass(PACKAGE_BASE_NAME+".data.AttributeTestClassEM02$1");
    final ConstantPool pool = clazz.getConstantPool();
    final Attribute[] encMethodAttrs = findAttribute("EnclosingMethod", clazz);
    assertTrue("Expected 1 EnclosingMethod attribute but found "
            + encMethodAttrs.length, encMethodAttrs.length == 1);
    final EnclosingMethod em = (EnclosingMethod) encMethodAttrs[0];
    final String enclosingClassName = em.getEnclosingClass().getBytes(pool);
    assertTrue(
            "The class is not within a method, so method_index should be null, but it is "
                    + em.getEnclosingMethodIndex(), em
                    .getEnclosingMethodIndex() == 0);
    assertTrue(
            "Expected class name to be '"+PACKAGE_BASE_SIG+"/data/AttributeTestClassEM02' but was "
                    + enclosingClassName, enclosingClassName
                    .equals(PACKAGE_BASE_SIG+"/data/AttributeTestClassEM02"));
}
 
Example 16
Source Project: cloud-opensource-java   Source File: ClassDumper.java    License: Apache License 2.0 5 votes vote down vote up
private static ConstantNameAndType constantNameAndType(
    ConstantCP constantCP, ConstantPool constantPool) {
  int nameAndTypeIndex = constantCP.getNameAndTypeIndex();
  Constant constantAtNameAndTypeIndex = constantPool.getConstant(nameAndTypeIndex);
  if (!(constantAtNameAndTypeIndex instanceof ConstantNameAndType)) {
    // This constant_pool entry must be a CONSTANT_NameAndType_info
    // as specified https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.2
    throw new ClassFormatException(
        "Failed to lookup nameAndType constant indexed at "
            + nameAndTypeIndex
            + ". However, the content is not ConstantNameAndType. It is "
            + constantAtNameAndTypeIndex);
  }
  return (ConstantNameAndType) constantAtNameAndTypeIndex;
}
 
Example 17
Source Project: cloud-opensource-java   Source File: ClassDumper.java    License: Apache License 2.0 5 votes vote down vote up
private static ClassSymbol makeSymbol(
    ConstantClass constantClass, ConstantPool constantPool, JavaClass sourceClass) {
  int nameIndex = constantClass.getNameIndex();
  Constant classNameConstant = constantPool.getConstant(nameIndex);
  if (!(classNameConstant instanceof ConstantUtf8)) {
    // This constant_pool entry must be a CONSTANT_Utf8_info
    // as specified https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.1
    throw new ClassFormatException(
        "Failed to lookup ConstantUtf8 constant indexed at "
            + nameIndex
            + ". However, the content is not ConstantUtf8. It is "
            + classNameConstant);
  }
  ConstantUtf8 classNameConstantUtf8 = (ConstantUtf8) classNameConstant;
  // classNameConstantUtf8 has internal form of class names that uses '.' to separate identifiers
  String targetClassNameInternalForm = classNameConstantUtf8.getBytes();
  // Adjust the internal form to comply with binary names defined in JLS 13.1
  String targetClassName = targetClassNameInternalForm.replace('/', '.');
  String superClassName = sourceClass.getSuperclassName();

  // Relationships between superclass and subclass need special validation for 'final' keyword
  boolean referenceIsForInheritance = superClassName.equals(targetClassName);
  if (referenceIsForInheritance) {
    return new SuperClassSymbol(targetClassName);
  }
  return new ClassSymbol(targetClassName);
}
 
Example 18
Source Project: cloud-opensource-java   Source File: ClassDumper.java    License: Apache License 2.0 5 votes vote down vote up
private static MethodSymbol makeSymbol(
    ConstantCP constantMethodref, ConstantPool constantPool) {
  String className = constantMethodref.getClass(constantPool);
  ConstantNameAndType constantNameAndType = constantNameAndType(constantMethodref, constantPool);
  String methodName = constantNameAndType.getName(constantPool);
  String descriptor = constantNameAndType.getSignature(constantPool);
  // constantMethodref is either ConstantMethodref or ConstantInterfaceMethodref
  boolean isInterfaceMethod = constantMethodref instanceof ConstantInterfaceMethodref;
  return new MethodSymbol(className, methodName, descriptor, isInterfaceMethod);
}
 
Example 19
Source Project: cloud-opensource-java   Source File: ClassDumper.java    License: Apache License 2.0 5 votes vote down vote up
private static FieldSymbol makeSymbol(
    ConstantFieldref constantFieldref, ConstantPool constantPool) {
  // Either a class type or an interface type
  String className = constantFieldref.getClass(constantPool);
  ConstantNameAndType constantNameAndType = constantNameAndType(constantFieldref, constantPool);
  String fieldName = constantNameAndType.getName(constantPool);
  String descriptor = constantNameAndType.getSignature(constantPool);
  return new FieldSymbol(className, fieldName, descriptor);
}
 
Example 20
Source Project: cloud-opensource-java   Source File: ClassDumper.java    License: Apache License 2.0 5 votes vote down vote up
static ImmutableSet<String> listInnerClassNames(JavaClass javaClass) {
  ImmutableSet.Builder<String> innerClassNames = ImmutableSet.builder();
  String topLevelClassName = javaClass.getClassName();
  ConstantPool constantPool = javaClass.getConstantPool();
  for (Attribute attribute : javaClass.getAttributes()) {
    if (attribute.getTag() == Const.ATTR_INNER_CLASSES) {
      // This innerClasses variable does not include double-nested inner classes
      InnerClasses innerClasses = (InnerClasses) attribute;
      for (InnerClass innerClass : innerClasses.getInnerClasses()) {
        int classIndex = innerClass.getInnerClassIndex();
        String innerClassName = constantPool.getConstantString(classIndex, Const.CONSTANT_Class);
        int outerClassIndex = innerClass.getOuterClassIndex();
        if (outerClassIndex > 0) {
          String outerClassName =
              constantPool.getConstantString(outerClassIndex, Const.CONSTANT_Class);
          String normalOuterClassName = outerClassName.replace('/', '.');
          if (!normalOuterClassName.equals(topLevelClassName)) {
            continue;
          }
        }

        // Class names stored in constant pool have '/' as separator. We want '.' (as binary name)
        String normalInnerClassName = innerClassName.replace('/', '.');
        innerClassNames.add(normalInnerClassName);
      }
    }
  }
  return innerClassNames.build();
}
 
Example 21
@Override
public void visitClassContext(ClassContext classContext) {

    JavaClass javaClass = classContext.getJavaClass();

    if (!javaClass.getPackageName().contains(".pages")) {
        return;
    }

    //The package contains ".pages" and has some references to tapestry
    // then it must be an endpoint.
    //The constants pool contains all references that are reused in the bytecode
    // including full class name and interface name.
    if (javaClass.getPackageName().contains(".pages")) {
        ConstantPool constants = javaClass.getConstantPool();
        for (Constant c : constants.getConstantPool()) {
            if (c instanceof ConstantUtf8) {
                ConstantUtf8 utf8 = (ConstantUtf8) c;
                String constantValue = String.valueOf(utf8.getBytes());
                if (constantValue.startsWith("Lorg/apache/tapestry5/annotations")) {
                    bugReporter.reportBug(new BugInstance(this, TAPESTRY_ENDPOINT_TYPE, Priorities.LOW_PRIORITY) //
                            .addClass(javaClass));
                    return;
                }
            }
        }
    }

}
 
Example 22
@Override
public void visitConstantPool(ConstantPool obj) {
    super.visitConstantPool(obj);
    Constant[] constant_pool = obj.getConstantPool();
    for (int i = 1; i < constant_pool.length; i++) {
        constant_pool[i].accept(this);
        byte tag = constant_pool[i].getTag();
        if ((tag == Const.CONSTANT_Double) || (tag == Const.CONSTANT_Long)) {
            i++;
        }
    }
}
 
Example 23
public static boolean hasInterestingClass(ConstantPool cp, Collection<String> classes) {
    for (Constant c : cp.getConstantPool()) {
        if (c instanceof ConstantClass) {
            String className = ((ConstantUtf8) cp.getConstant(((ConstantClass) c).getNameIndex())).getBytes();
            if (classes.contains(className)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 24
Source Project: spotbugs   Source File: Util.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public static @CheckForNull CodeException getSurroundingTryBlock(ConstantPool constantPool, Code code,
        @CheckForNull String vmNameOfExceptionClass, int pc) {
    int size = Integer.MAX_VALUE;
    if (code.getExceptionTable() == null) {
        return null;
    }
    CodeException result = null;
    for (CodeException catchBlock : code.getExceptionTable()) {
        if (vmNameOfExceptionClass != null) {
            Constant catchType = constantPool.getConstant(catchBlock.getCatchType());
            if (catchType == null && !vmNameOfExceptionClass.isEmpty() || catchType instanceof ConstantClass
                    && !((ConstantClass) catchType).getBytes(constantPool).equals(vmNameOfExceptionClass)) {
                continue;
            }
        }
        int startPC = catchBlock.getStartPC();
        int endPC = catchBlock.getEndPC();
        if (pc >= startPC && pc <= endPC) {
            int thisSize = endPC - startPC;
            if (size > thisSize) {
                size = thisSize;
                result = catchBlock;
            }
        }
    }
    return result;
}
 
Example 25
public static boolean catchesNull(ConstantPool constantPool, Code code, Location location) {
    int position = location.getHandle().getPosition();

    for (String t : catchTypesForNull) {
        int catchSize = Util.getSizeOfSurroundingTryBlock(constantPool, code, t, position);
        if (catchSize < Integer.MAX_VALUE) {
            return true;
        }
    }

    return false;
}
 
Example 26
private boolean safeCallToPrimateParseMethod(XMethod calledMethod, Location location) {
    int position = location.getHandle().getPosition();

    if (Values.DOTTED_JAVA_LANG_INTEGER.equals(calledMethod.getClassName())) {

        ConstantPool constantPool = classContext.getJavaClass().getConstantPool();
        Code code = method.getCode();

        int catchSize;

        catchSize = Util.getSizeOfSurroundingTryBlock(constantPool, code, "java/lang/NumberFormatException", position);
        if (catchSize < Integer.MAX_VALUE) {
            return true;
        }
        catchSize = Util.getSizeOfSurroundingTryBlock(constantPool, code, "java/lang/IllegalArgumentException", position);
        if (catchSize < Integer.MAX_VALUE) {
            return true;
        }

        catchSize = Util.getSizeOfSurroundingTryBlock(constantPool, code, "java/lang/RuntimeException", position);
        if (catchSize < Integer.MAX_VALUE) {
            return true;
        }
        catchSize = Util.getSizeOfSurroundingTryBlock(constantPool, code, "java/lang/Exception", position);
        if (catchSize < Integer.MAX_VALUE) {
            return true;
        }
    }
    return false;
}
 
Example 27
/** @see com.puppycrawl.tools.checkstyle.bcel.IDeepVisitor */
public void visitObject(Object aObject)
{
    final JavaClass javaClass = (JavaClass) aObject;
    final ConstantPool pool = javaClass.getConstantPool();
    mCurrentPoolGen = new ConstantPoolGen(pool);
}
 
Example 28
/**
 * @see org.apache.bcel.classfile.Visitor
 */
public void visitConstantPool(ConstantPool aConstantPool)
{
    for (Iterator iter = mVisitors.iterator(); iter.hasNext();) {
        IDeepVisitor visitor = (IDeepVisitor) iter.next();
        Visitor v = visitor.getClassFileVisitor();
        aConstantPool.accept(v);
    }
}
 
Example 29
/** @see com.puppycrawl.tools.checkstyle.bcel.IDeepVisitor */
public void visitObject(Object aObject)
{
    final JavaClass javaClass = (JavaClass) aObject;
    final ConstantPool pool = javaClass.getConstantPool();
    mCurrentPoolGen = new ConstantPoolGen(pool);
}
 
Example 30
/**
 * @see org.apache.bcel.classfile.Visitor
 */
public void visitConstantPool(ConstantPool aConstantPool)
{
    for (Iterator iter = mVisitors.iterator(); iter.hasNext();) {
        IDeepVisitor visitor = (IDeepVisitor) iter.next();
        Visitor v = visitor.getClassFileVisitor();
        aConstantPool.accept(v);
    }
}