Java Code Examples for com.sun.tools.classfile.ConstantPoolException

Following code examples demonstrate how to use com.sun.tools.classfile.ConstantPoolExceptionfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use com.sun.tools.classfile.ConstantPoolExceptionand various code implementation of this class.

    public void test() throws IOException, ConstantPoolException {
        assertNull(
                ClassFile.read(getClassFile(NoSourceFileAttribute.class)).getAttribute(Attribute.SourceFile),
                "Classfile should have no SourceFile attribute when compiled without debug information.");
    } 


    public void test() throws IOException, ConstantPoolException {
        ClassFile classFile = readClassFile("NoInnerClassesTest");
        assertNull(classFile.getAttribute(Attribute.InnerClasses), "Found inner class attribute");
    } 

    static public JvmOpcodeClass read(Path path) throws ClassNotFoundException {
        try {
            return  new JvmOpcodeClass(ClassFile.read(path));
        } catch (ConstantPoolException e) {
            throw new InternalError(e);
        } catch (IOException e) {
            throw new ClassNotFoundException(e.toString());
        }
    } 

    private JvmOpcodeClass(ClassFile classFile) throws ConstantPoolException {
        this.classFile = classFile;
        for (Method method : classFile.methods) {
            String name = method.getName(classFile.constant_pool);
            String desc = method.descriptor.getValue(classFile.constant_pool);
            methods.put(name+":"+desc, new JvmOpcodeMethod(this.classFile, method));
        }
        prepare();
        init();
    } 

	public static String getPackage(File paramFile) {
		try {
			ClassFile classFile = ClassFile.read(paramFile);
			CPInfo classInfo = classFile.constant_pool.get(classFile.this_class);
			if(classInfo instanceof CONSTANT_Class_info) {
				CPInfo cp = classFile.constant_pool.get(((CONSTANT_Class_info) classInfo).name_index);
				if(cp instanceof CONSTANT_Utf8_info) {
					return StringUtils.replace(((CONSTANT_Utf8_info)cp).value, "/", ".");
				}
			}
			
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ConstantPoolException e) {
			e.printStackTrace();
		}
		
		return null;
	} 

    public static void main(String[] args) throws Exception {
        Entry[] lines = findEntries();
        if (lines == null || lines.length != 1) {
            int found = lines == null ? 0 : lines.length;
            error(String.format("LineNumberTable contains wrong number of entries - expected %d, found %d", 1, found));
        }

        int line = lines[0].line_number;
        if (line != 54) {
            error(String.format("LineNumberTable contains wrong line number - expected %d, found %d", 54, line));
        }
    } 

    public void handle(HttpExchange t) throws IOException {
        InputStream is = t.getRequestBody();
        try {
        } catch (ConstantPoolException e) {
            e.printStackTrace();
        }
        String response = "This is the response";
        t.sendResponseHeaders(200, response.length());
        OutputStream os = t.getResponseBody();
        os.write(response.getBytes());
        os.close();
    } 

    }

    public static void add(JarFile jarfile, JarEntry e, ClassFile cf)
            throws ConstantPoolException
    {
        String realName = SharedSecrets.javaUtilJarAccess().getRealName(jarfile, e);
        if (realName.startsWith(META_INF_VERSIONS)) {
            int len = META_INF_VERSIONS.length();
            int n = realName.indexOf('/', len);
            if (n > 0) {
                String version = realName.substring(len, n);
                assert (Integer.parseInt(version) > 8);
                String name = cf.getName().replace('/', '.');
                if (nameToVersion.containsKey(name)) {
                    if (!version.equals(nameToVersion.get(name))) {
                        throw new MultiReleaseException(
                                "err.multirelease.version.associated",
                                name, nameToVersion.get(name), version
                        );
                    }
                } else {
                    nameToVersion.put(name, version);
                }
            } else {
                throw new MultiReleaseException("err.multirelease.jar.malformed",
                        jarfile.getName(), realName);
            }
        }
    } 

    public JvmOpcodeObjectField(JvmOpcodeClass clazz, Field field) throws ConstantPoolException {
        this.clazz = clazz;
        this.field = field;
        fieldName = field.getName(clazz.getClassFile().constant_pool);
    } 

    public UserObjectField(UserClass clazz, Field field) throws ConstantPoolException {
        this.clazz = clazz;
        this.field = field;
        fieldName = field.getName(clazz.getClassFile().constant_pool);
    } 

Advertisement
Javadoc


This is NOT part of any supported API. If you write code that depends on this, you do

so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.

Read More
Advertisement