com.sun.tools.classfile.Descriptor.InvalidDescriptor Java Examples

The following examples show how to use com.sun.tools.classfile.Descriptor.InvalidDescriptor. 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 File: DetectMutableStaticFields.java    From openjdk-jdk9 with GNU General Public License v2.0 7 votes vote down vote up
private void run()
    throws
        IOException,
        ConstantPoolException,
        InvalidDescriptor,
        URISyntaxException {

    JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        for (String module: modules) {
            analyzeModule(fm, module);
        }
    }

    if (errors.size() > 0) {
        for (String error: errors) {
            System.err.println(error);
        }
        throw new AssertionError("There are mutable fields, "
            + "please check output");
    }
}
 
Example #2
Source File: DetectMutableStaticFields.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void run()
    throws
        IOException,
        ConstantPoolException,
        InvalidDescriptor,
        URISyntaxException {

    URI resource = findResource(keyResource);
    if (resource == null) {
        throw new AssertionError("Resource " + keyResource +
            "not found in the class path");
    }
    analyzeResource(resource);

    if (errors.size() > 0) {
        for (String error: errors) {
            System.err.println(error);
        }
        throw new AssertionError("There are mutable fields, "
            + "please check output");
    }
}
 
Example #3
Source File: ClassReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public Element readFrom(InputStream in) throws IOException {
    try {
        this.in = in;
        ClassFile c = ClassFile.read(in);
        // read the file header
        if (c.magic != 0xCAFEBABE) {
            throw new RuntimeException("bad magic number " +
                    Integer.toHexString(c.magic));
        }
        cfile.setAttr("magic", "" + c.magic);
        int minver = c.minor_version;
        int majver = c.major_version;
        cfile.setAttr("minver", "" + minver);
        cfile.setAttr("majver", "" + majver);
        readCP(c);
        readClass(c);
        return result();
    } catch (InvalidDescriptor | ConstantPoolException ex) {
        throw new IOException("Fatal error", ex);
    }
}
 
Example #4
Source File: ClassReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        klass.setAttr("super", c.getSuperclassName());
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example #5
Source File: DetectMutableStaticFields.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
void analyzeResource(URI resource)
    throws
        IOException,
        ConstantPoolException,
        InvalidDescriptor {
    JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    JavaFileManager.Location location =
            StandardLocation.locationFor(resource.getPath());
    fm.setLocation(location, com.sun.tools.javac.util.List.of(
            new File(resource.getPath())));

    for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) {
        String className = fm.inferBinaryName(location, file);
        int index = className.lastIndexOf('.');
        String pckName = index == -1 ? "" : className.substring(0, index);
        if (shouldAnalyzePackage(pckName)) {
            analyzeClassFile(ClassFile.read(file.openInputStream()));
        }
    }
}
 
Example #6
Source File: CheckACC_STRICTFlagOnclinitTest.java    From TencentKona-8 with 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 File: LVTHarness.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void checkClassFile(File file)
        throws IOException, ConstantPoolException, InvalidDescriptor {
    ClassFile classFile = ClassFile.read(file);
    ConstantPool constantPool = classFile.constant_pool;

    //lets get all the methods in the class file.
    for (Method method : classFile.methods) {
        for (ElementKey elementKey: aliveRangeMap.keySet()) {
            String methodDesc = method.getName(constantPool) +
                    method.descriptor.getParameterTypes(constantPool).replace(" ", "");
            if (methodDesc.equals(elementKey.elem.toString())) {
                checkMethod(constantPool, method, aliveRangeMap.get(elementKey));
                seenAliveRanges.add(elementKey);
            }
        }
    }
}
 
Example #8
Source File: LVTHarness.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
void checkClassFile(File file)
        throws IOException, ConstantPoolException, InvalidDescriptor {
    ClassFile classFile = ClassFile.read(file);
    ConstantPool constantPool = classFile.constant_pool;

    //lets get all the methods in the class file.
    for (Method method : classFile.methods) {
        for (ElementKey elementKey: aliveRangeMap.keySet()) {
            String methodDesc = method.getName(constantPool) +
                    method.descriptor.getParameterTypes(constantPool).replace(" ", "");
            if (methodDesc.equals(elementKey.elem.toString())) {
                checkMethod(constantPool, method, aliveRangeMap.get(elementKey));
                seenAliveRanges.add(elementKey);
            }
        }
    }
}
 
Example #9
Source File: ClassReader.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        if (c.super_class != 0) {
            klass.setAttr("super", c.getSuperclassName());
        }
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example #10
Source File: ClassReader.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public Element readFrom(InputStream in) throws IOException {
    try {
        this.in = in;
        ClassFile c = ClassFile.read(in);
        // read the file header
        if (c.magic != 0xCAFEBABE) {
            throw new RuntimeException("bad magic number " +
                    Integer.toHexString(c.magic));
        }
        cfile.setAttr("magic", "" + c.magic);
        int minver = c.minor_version;
        int majver = c.major_version;
        cfile.setAttr("minver", "" + minver);
        cfile.setAttr("majver", "" + majver);
        readCP(c);
        readClass(c);
        return result();
    } catch (InvalidDescriptor | ConstantPoolException ex) {
        throw new IOException("Fatal error", ex);
    }
}
 
Example #11
Source File: ClassReader.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        klass.setAttr("super", c.getSuperclassName());
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example #12
Source File: DetectMutableStaticFields.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void run()
    throws
        IOException,
        ConstantPoolException,
        InvalidDescriptor,
        URISyntaxException {

    URI resource = findResource(keyResource);
    if (resource == null) {
        throw new AssertionError("Resource " + keyResource +
            "not found in the class path");
    }
    analyzeResource(resource);

    if (errors.size() > 0) {
        for (String error: errors) {
            System.err.println(error);
        }
        throw new AssertionError("There are mutable fields, "
            + "please check output");
    }
}
 
Example #13
Source File: LVTHarness.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
void checkClassFile(File file)
        throws IOException, ConstantPoolException, InvalidDescriptor {
    ClassFile classFile = ClassFile.read(file);
    ConstantPool constantPool = classFile.constant_pool;

    //lets get all the methods in the class file.
    for (Method method : classFile.methods) {
        for (ElementKey elementKey: aliveRangeMap.keySet()) {
            String methodDesc = method.getName(constantPool) +
                    method.descriptor.getParameterTypes(constantPool).replace(" ", "");
            if (methodDesc.equals(elementKey.elem.toString())) {
                checkMethod(constantPool, method, aliveRangeMap.get(elementKey));
                seenAliveRanges.add(elementKey);
            }
        }
    }
}
 
Example #14
Source File: CheckACC_STRICTFlagOnclinitTest.java    From openjdk-jdk8u-backup with 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 #15
Source File: CheckACC_STRICTFlagOnclinitTest.java    From openjdk-jdk9 with 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 File: CheckACC_STRICTFlagOnclinitTest.java    From jdk8u60 with 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 File: DetectMutableStaticFields.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void analyzeResource(URI resource)
    throws
        IOException,
        ConstantPoolException,
        InvalidDescriptor {
    JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    JavaFileManager.Location location =
            StandardLocation.locationFor(resource.getPath());
    fm.setLocation(location, com.sun.tools.javac.util.List.of(
            new File(resource.getPath())));

    for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) {
        String className = fm.inferBinaryName(location, file);
        int index = className.lastIndexOf('.');
        String pckName = index == -1 ? "" : className.substring(0, index);
        if (shouldAnalyzePackage(pckName)) {
            analyzeClassFile(ClassFile.read(file.openInputStream()));
        }
    }
}
 
Example #18
Source File: DetectMutableStaticFields.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
void analyzeResource(URI resource)
    throws
        IOException,
        ConstantPoolException,
        InvalidDescriptor {
    JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    JavaFileManager.Location location =
            StandardLocation.locationFor(resource.getPath());
    fm.setLocation(location, com.sun.tools.javac.util.List.of(
            new File(resource.getPath())));

    for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) {
        String className = fm.inferBinaryName(location, file);
        int index = className.lastIndexOf('.');
        String pckName = index == -1 ? "" : className.substring(0, index);
        if (shouldAnalyzePackage(pckName)) {
            analyzeClassFile(ClassFile.read(file.openInputStream()));
        }
    }
}
 
Example #19
Source File: ClassReader.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        klass.setAttr("super", c.getSuperclassName());
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example #20
Source File: ClassReader.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public Element readFrom(InputStream in) throws IOException {
    try {
        this.in = in;
        ClassFile c = ClassFile.read(in);
        // read the file header
        if (c.magic != 0xCAFEBABE) {
            throw new RuntimeException("bad magic number " +
                    Integer.toHexString(c.magic));
        }
        cfile.setAttr("magic", "" + c.magic);
        int minver = c.minor_version;
        int majver = c.major_version;
        cfile.setAttr("minver", "" + minver);
        cfile.setAttr("majver", "" + majver);
        readCP(c);
        readClass(c);
        return result();
    } catch (InvalidDescriptor | ConstantPoolException ex) {
        throw new IOException("Fatal error", ex);
    }
}
 
Example #21
Source File: ClassReader.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public Element readFrom(InputStream in) throws IOException {
    try {
        this.in = in;
        ClassFile c = ClassFile.read(in);
        // read the file header
        if (c.magic != 0xCAFEBABE) {
            throw new RuntimeException("bad magic number " +
                    Integer.toHexString(c.magic));
        }
        cfile.setAttr("magic", "" + c.magic);
        int minver = c.minor_version;
        int majver = c.major_version;
        cfile.setAttr("minver", "" + minver);
        cfile.setAttr("majver", "" + majver);
        readCP(c);
        readClass(c);
        return result();
    } catch (InvalidDescriptor | ConstantPoolException ex) {
        throw new IOException("Fatal error", ex);
    }
}
 
Example #22
Source File: ClassReader.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        klass.setAttr("super", c.getSuperclassName());
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example #23
Source File: CheckACC_STRICTFlagOnDefaultMethodTest.java    From openjdk-jdk9 with 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 #24
Source File: ClassReader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        klass.setAttr("super", c.getSuperclassName());
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example #25
Source File: LVTHarness.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void checkClassFile(File file)
        throws IOException, ConstantPoolException, InvalidDescriptor {
    ClassFile classFile = ClassFile.read(file);
    ConstantPool constantPool = classFile.constant_pool;

    //lets get all the methods in the class file.
    for (Method method : classFile.methods) {
        for (ElementKey elementKey: aliveRangeMap.keySet()) {
            String methodDesc = method.getName(constantPool) +
                    method.descriptor.getParameterTypes(constantPool).replace(" ", "");
            if (methodDesc.equals(elementKey.elem.toString())) {
                checkMethod(constantPool, method, aliveRangeMap.get(elementKey));
                seenAliveRanges.add(elementKey);
            }
        }
    }
}
 
Example #26
Source File: ClassReader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Element readFrom(InputStream in) throws IOException {
    try {
        this.in = in;
        ClassFile c = ClassFile.read(in);
        // read the file header
        if (c.magic != 0xCAFEBABE) {
            throw new RuntimeException("bad magic number " +
                    Integer.toHexString(c.magic));
        }
        cfile.setAttr("magic", "" + c.magic);
        int minver = c.minor_version;
        int majver = c.major_version;
        cfile.setAttr("minver", "" + minver);
        cfile.setAttr("majver", "" + majver);
        readCP(c);
        readClass(c);
        return result();
    } catch (InvalidDescriptor | ConstantPoolException ex) {
        throw new IOException("Fatal error", ex);
    }
}
 
Example #27
Source File: CheckACC_STRICTFlagOnDefaultMethodTest.java    From openjdk-jdk8u with 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 #28
Source File: DetectMutableStaticFields.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void analyzeResource(URI resource)
    throws
        IOException,
        ConstantPoolException,
        InvalidDescriptor {
    JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    JavaFileManager.Location location =
            StandardLocation.locationFor(resource.getPath());
    fm.setLocation(location, com.sun.tools.javac.util.List.of(
            new File(resource.getPath())));

    for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) {
        String className = fm.inferBinaryName(location, file);
        int index = className.lastIndexOf('.');
        String pckName = index == -1 ? "" : className.substring(0, index);
        if (shouldAnalyzePackage(pckName)) {
            analyzeClassFile(ClassFile.read(file.openInputStream()));
        }
    }
}
 
Example #29
Source File: CheckACC_STRICTFlagOnclinitTest.java    From openjdk-jdk8u with 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 #30
Source File: DetectMutableStaticFields.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void run()
    throws
        IOException,
        ConstantPoolException,
        InvalidDescriptor,
        URISyntaxException {

    URI resource = findResource(keyResource);
    if (resource == null) {
        throw new AssertionError("Resource " + keyResource +
            "not found in the class path");
    }
    analyzeResource(resource);

    if (errors.size() > 0) {
        for (String error: errors) {
            System.err.println(error);
        }
        throw new AssertionError("There are mutable fields, "
            + "please check output");
    }
}