com.sun.tools.classfile.Descriptor Java Examples

The following examples show how to use com.sun.tools.classfile.Descriptor. 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: TencentKona-8   Author: Tencent   File: CheckACC_STRICTFlagOnclinitTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #2
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #3
Source Project: jdk8u60   Author: chenghanpeng   File: CheckACC_STRICTFlagOnclinitTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #4
Source Project: jdk8u60   Author: chenghanpeng   File: CheckACC_STRICTFlagOnDefaultMethodTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #5
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: CheckACC_STRICTFlagOnclinitTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #6
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: CheckACC_STRICTFlagOnDefaultMethodTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #7
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: CheckACC_STRICTFlagOnclinitTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #8
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #9
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: CheckACC_STRICTFlagOnclinitTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #10
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: CheckACC_STRICTFlagOnDefaultMethodTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #11
Source Project: hottub   Author: dsrg-uoft   File: CheckACC_STRICTFlagOnclinitTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #12
Source Project: hottub   Author: dsrg-uoft   File: CheckACC_STRICTFlagOnDefaultMethodTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #13
Source Project: openjdk-8-source   Author: keerath   File: CheckACC_STRICTFlagOnclinitTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #14
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #15
Source Project: openjdk-8   Author: bpupadhyaya   File: CheckACC_STRICTFlagOnclinitTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #16
Source Project: openjdk-8   Author: bpupadhyaya   File: CheckACC_STRICTFlagOnDefaultMethodTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void check(String dir, String... fileNames)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    for (String fileName : fileNames) {
        ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName));

        for (Method method : classFileToCheck.methods) {
            if ((method.access_flags.flags & ACC_STRICT) == 0) {
                errors.add(String.format(offendingMethodErrorMessage,
                        method.getName(classFileToCheck.constant_pool),
                        classFileToCheck.getName()));
            }
        }
    }
}
 
Example #17
Source Project: TencentKona-8   Author: Tencent   File: ClassWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
String getValue(Descriptor d) {
    try {
        return d.getValue(constant_pool);
    } catch (ConstantPoolException e) {
        return report(e);
    }
}
 
Example #18
void check()
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    ClassFile classFileToCheck = ClassFile.read(new File("Test.class"));

    for (Method method : classFileToCheck.methods) {
        if ((method.access_flags.flags & ACC_STRICT) == 0) {
            errors.add(String.format(offendingMethodErrorMessage,
                    method.getName(classFileToCheck.constant_pool),
                    classFileToCheck.getName()));
        }
    }
}
 
Example #19
Source Project: TencentKona-8   Author: Tencent   File: DetectMutableStaticFields.java    License: GNU General Public License v2.0 5 votes vote down vote up
void analyzeClassFile(ClassFile classFileToCheck)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    boolean enumClass =
            (classFileToCheck.access_flags.flags & ACC_ENUM) != 0;
    boolean nonFinalStaticEnumField;
    boolean nonFinalStaticField;

    currentFieldsToIgnore =
            classFieldsToIgnoreMap.get(classFileToCheck.getName());

    for (Field field : classFileToCheck.fields) {
        if (ignoreField(field.getName(classFileToCheck.constant_pool))) {
            continue;
        }
        nonFinalStaticEnumField =
                (field.access_flags.flags & (ACC_ENUM | ACC_FINAL)) == 0;
        nonFinalStaticField =
                (field.access_flags.flags & ACC_STATIC) != 0 &&
                (field.access_flags.flags & ACC_FINAL) == 0;
        if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) {
            errors.add("There is a mutable field named " +
                    field.getName(classFileToCheck.constant_pool) +
                    ", at class " +
                    classFileToCheck.getName());
        }
    }
}
 
Example #20
Source Project: jdk8u60   Author: chenghanpeng   File: ClassWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
String getValue(Descriptor d) {
    try {
        return d.getValue(constant_pool);
    } catch (ConstantPoolException e) {
        return report(e);
    }
}
 
Example #21
Source Project: jdk8u60   Author: chenghanpeng   File: CheckACC_STRICTFlagOnPkgAccessClassTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
void check()
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    ClassFile classFileToCheck = ClassFile.read(new File("Test.class"));

    for (Method method : classFileToCheck.methods) {
        if ((method.access_flags.flags & ACC_STRICT) == 0) {
            errors.add(String.format(offendingMethodErrorMessage,
                    method.getName(classFileToCheck.constant_pool),
                    classFileToCheck.getName()));
        }
    }
}
 
Example #22
Source Project: jdk8u60   Author: chenghanpeng   File: DetectMutableStaticFields.java    License: GNU General Public License v2.0 5 votes vote down vote up
void analyzeClassFile(ClassFile classFileToCheck)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    boolean enumClass =
            (classFileToCheck.access_flags.flags & ACC_ENUM) != 0;
    boolean nonFinalStaticEnumField;
    boolean nonFinalStaticField;

    currentFieldsToIgnore =
            classFieldsToIgnoreMap.get(classFileToCheck.getName());

    for (Field field : classFileToCheck.fields) {
        if (ignoreField(field.getName(classFileToCheck.constant_pool))) {
            continue;
        }
        nonFinalStaticEnumField =
                (field.access_flags.flags & (ACC_ENUM | ACC_FINAL)) == 0;
        nonFinalStaticField =
                (field.access_flags.flags & ACC_STATIC) != 0 &&
                (field.access_flags.flags & ACC_FINAL) == 0;
        if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) {
            errors.add("There is a mutable field named " +
                    field.getName(classFileToCheck.constant_pool) +
                    ", at class " +
                    classFileToCheck.getName());
        }
    }
}
 
Example #23
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ClassWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
String getValue(Descriptor d) {
    try {
        return d.getValue(constant_pool);
    } catch (ConstantPoolException e) {
        return report(e);
    }
}
 
Example #24
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: CheckACC_STRICTFlagOnPkgAccessClassTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
void check()
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    ClassFile classFileToCheck = ClassFile.read(new File("Test.class"));

    for (Method method : classFileToCheck.methods) {
        if ((method.access_flags.flags & ACC_STRICT) == 0) {
            errors.add(String.format(offendingMethodErrorMessage,
                    method.getName(classFileToCheck.constant_pool),
                    classFileToCheck.getName()));
        }
    }
}
 
Example #25
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: DetectMutableStaticFields.java    License: GNU General Public License v2.0 5 votes vote down vote up
void analyzeClassFile(ClassFile classFileToCheck)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    boolean enumClass =
            (classFileToCheck.access_flags.flags & ACC_ENUM) != 0;
    boolean nonFinalStaticEnumField;
    boolean nonFinalStaticField;

    currentFieldsToIgnore =
            classFieldsToIgnoreMap.get(classFileToCheck.getName());

    for (Field field : classFileToCheck.fields) {
        if (ignoreField(field.getName(classFileToCheck.constant_pool))) {
            continue;
        }
        nonFinalStaticEnumField =
                (field.access_flags.flags & (ACC_ENUM | ACC_FINAL)) == 0;
        nonFinalStaticField =
                (field.access_flags.flags & ACC_STATIC) != 0 &&
                (field.access_flags.flags & ACC_FINAL) == 0;
        if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) {
            errors.add("There is a mutable field named " +
                    field.getName(classFileToCheck.constant_pool) +
                    ", at class " +
                    classFileToCheck.getName());
        }
    }
}
 
Example #26
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ClassWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
String getValue(Descriptor d) {
    try {
        return d.getValue(constant_pool);
    } catch (ConstantPoolException e) {
        return report(e);
    }
}
 
Example #27
void check()
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    ClassFile classFileToCheck = ClassFile.read(new File("Test.class"));

    for (Method method : classFileToCheck.methods) {
        if ((method.access_flags.flags & ACC_STRICT) == 0) {
            errors.add(String.format(offendingMethodErrorMessage,
                    method.getName(classFileToCheck.constant_pool),
                    classFileToCheck.getName()));
        }
    }
}
 
Example #28
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: DetectMutableStaticFields.java    License: GNU General Public License v2.0 5 votes vote down vote up
void analyzeClassFile(ClassFile classFileToCheck)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    boolean enumClass =
            (classFileToCheck.access_flags.flags & ACC_ENUM) != 0;
    boolean nonFinalStaticEnumField;
    boolean nonFinalStaticField;

    currentFieldsToIgnore =
            classFieldsToIgnoreMap.get(classFileToCheck.getName());

    for (Field field : classFileToCheck.fields) {
        if (ignoreField(field.getName(classFileToCheck.constant_pool))) {
            continue;
        }
        nonFinalStaticEnumField =
                (field.access_flags.flags & (ACC_ENUM | ACC_FINAL)) == 0;
        nonFinalStaticField =
                (field.access_flags.flags & ACC_STATIC) != 0 &&
                (field.access_flags.flags & ACC_FINAL) == 0;
        if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) {
            errors.add("There is a mutable field named " +
                    field.getName(classFileToCheck.constant_pool) +
                    ", at class " +
                    classFileToCheck.getName());
        }
    }
}
 
Example #29
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ClassWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
String getValue(Descriptor d) {
    try {
        return d.getValue(constant_pool);
    } catch (ConstantPoolException e) {
        return report(e);
    }
}
 
Example #30
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: StackMapWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
void setStackMap(StackMapTable_attribute attr) {
    if (attr == null) {
        map = null;
        return;
    }

    Method m = classWriter.getMethod();
    Descriptor d = m.descriptor;
    String[] args;
    try {
        ConstantPool cp = classWriter.getClassFile().constant_pool;
        String argString = d.getParameterTypes(cp);
        args = argString.substring(1, argString.length() - 1).split("[, ]+");
    } catch (ConstantPoolException | InvalidDescriptor e) {
        return;
    }
    boolean isStatic = m.access_flags.is(AccessFlags.ACC_STATIC);

    verification_type_info[] initialLocals = new verification_type_info[(isStatic ? 0 : 1) + args.length];
    if (!isStatic)
        initialLocals[0] = new CustomVerificationTypeInfo("this");
    for (int i = 0; i < args.length; i++) {
        initialLocals[(isStatic ? 0 : 1) + i] =
                new CustomVerificationTypeInfo(args[i].replace(".", "/"));
    }

    map = new HashMap<>();
    StackMapBuilder builder = new StackMapBuilder();

    // using -1 as the pc for the initial frame effectively compensates for
    // the difference in behavior for the first stack map frame (where the
    // pc offset is just offset_delta) compared to subsequent frames (where
    // the pc offset is always offset_delta+1).
    int pc = -1;

    map.put(pc, new StackMap(initialLocals, empty));

    for (int i = 0; i < attr.entries.length; i++)
        pc = attr.entries[i].accept(builder, pc);
}