Package edu.umd.cs.findbugs.classfile

Examples of edu.umd.cs.findbugs.classfile.InvalidClassFileFormatException


        try {
            ClassNode cn = new ClassNode();
            classReader.accept(cn, 0);
            return cn;
        } catch (RuntimeException e) {
            throw new InvalidClassFileFormatException(descriptor, entry, e);
        }
    }
View Full Code Here


        builder.setCodeBaseEntry(codeBaseEntry);
        builder.setAccessFlags(javaClass.getAccessFlags());
        ClassDescriptor classDescriptor = DescriptorFactory.createClassDescriptorFromDottedClassName(javaClass.getClassName());
        if (expectedClassDescriptor != null && expectedClassDescriptor.equals(classDescriptor)) {
            throw new InvalidClassFileFormatException("Expected " + expectedClassDescriptor, classDescriptor, codeBaseEntry);
        }
        builder.setClassDescriptor(classDescriptor);

        builder.setSuperclassDescriptor(DescriptorFactory.createClassDescriptorFromDottedClassName(javaClass.getSuperclassName()));
        String[] allInterfaces = javaClass.getInterfaceNames();
View Full Code Here

    @Override
    public void parse(ClassNameAndSuperclassInfo.Builder builder) throws InvalidClassFileFormatException {
        try {
            int magic = in.readInt();
            if (magic != 0xcafebabe) {
                throw new InvalidClassFileFormatException("Classfile header isn't 0xCAFEBABE", expectedClassDescriptor,
                        codeBaseEntry);
            }
            int major_version = in.readUnsignedShort();
            int minor_version = in.readUnsignedShort();
            int constant_pool_count = in.readUnsignedShort();

            constantPool = new Constant[constant_pool_count];
            for (int i = 1; i < constantPool.length; i++) {
                constantPool[i] = readConstant();
                if (constantPool[i].tag == IClassConstants.CONSTANT_Double
                        || constantPool[i].tag == IClassConstants.CONSTANT_Long) {
                    // Double and Long constants take up two constant pool
                    // entries
                    ++i;
                }
            }

            int access_flags = in.readUnsignedShort();

            int this_class = in.readUnsignedShort();
            ClassDescriptor thisClassDescriptor = getClassDescriptor(this_class);

            int super_class = in.readUnsignedShort();
            ClassDescriptor superClassDescriptor = getClassDescriptor(super_class);

            int interfaces_count = in.readUnsignedShort();
            if (interfaces_count < 0) {
                throw new InvalidClassFileFormatException(expectedClassDescriptor, codeBaseEntry);
            }
            ClassDescriptor[] interfaceDescriptorList;
            if (interfaces_count == 0) {
                interfaceDescriptorList = ClassDescriptor.EMPTY_ARRAY;
            } else {
                interfaceDescriptorList = new ClassDescriptor[interfaces_count];
                for (int i = 0; i < interfaceDescriptorList.length; i++) {
                    interfaceDescriptorList[i] = getClassDescriptor(in.readUnsignedShort());
                }
            }
            // Extract all references to other classes,
            // both CONSTANT_Class entries and also referenced method
            // signatures.
            Collection<ClassDescriptor> referencedClassDescriptorList = extractReferencedClasses();

            builder.setClassDescriptor(thisClassDescriptor);
            builder.setSuperclassDescriptor(superClassDescriptor);
            builder.setInterfaceDescriptorList(interfaceDescriptorList);
            builder.setCodeBaseEntry(codeBaseEntry);
            builder.setAccessFlags(access_flags);
            builder.setReferencedClassDescriptors(referencedClassDescriptorList);
            builder.setClassfileVersion(major_version, minor_version);
        } catch (IOException e) {
            throw new InvalidClassFileFormatException(expectedClassDescriptor, codeBaseEntry, e);
        }
    }
View Full Code Here

     * @throws IOException
     */
    private Constant readConstant() throws InvalidClassFileFormatException, IOException {
        int tag = in.readUnsignedByte();
        if (tag < 0 || tag >= CONSTANT_FORMAT_MAP.length) {
            throw new InvalidClassFileFormatException(expectedClassDescriptor, codeBaseEntry);
        }
        String format = CONSTANT_FORMAT_MAP[tag];
        if (format == null) {
            throw new InvalidClassFileFormatException(expectedClassDescriptor, codeBaseEntry);
        }

        Object[] data = new Object[format.length()];
        for (int i = 0; i < format.length(); i++) {
            char spec = format.charAt(i);
View Full Code Here

     * @throws InvalidClassFileFormatException
     *             if the index is not valid
     */
    private void checkConstantPoolIndex(int index) throws InvalidClassFileFormatException {
        if (index < 0 || index >= constantPool.length || constantPool[index] == null) {
            throw new InvalidClassFileFormatException(expectedClassDescriptor, codeBaseEntry);
        }
    }
View Full Code Here

     * @throws InvalidClassFileFormatException
     *             if the constant's tag does not match the expected tag
     */
    private void checkConstantTag(Constant constant, int expectedTag) throws InvalidClassFileFormatException {
        if (constant.tag != expectedTag) {
            throw new InvalidClassFileFormatException(expectedClassDescriptor, codeBaseEntry);
        }
    }
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.classfile.InvalidClassFileFormatException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.