com.sun.tools.classfile.Dependencies.ClassFileError Java Examples

The following examples show how to use com.sun.tools.classfile.Dependencies.ClassFileError. 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: ClassFileReader.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }

    ClassFile cf;
    try {
        cf = readClassFile(nextEntry);
    } catch (IOException ex) {
        throw new ClassFileError(ex);
    }
    JarEntry entry = nextEntry;
    nextEntry = null;
    while (entries.hasMoreElements()) {
        JarEntry e = entries.nextElement();
        String name = e.getName();
        if (name.endsWith(".class")) {
            nextEntry = e;
            break;
        }
    }
    return cf;
}
 
Example #2
Source File: ClassFileReader.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public boolean hasNext() {
    if (nextEntry != null && cf != null) {
        return true;
    }
    while (nextEntry != null) {
        try {
            cf = reader.readClassFile(jf, nextEntry);
            return true;
        } catch (ClassFileError | IOException ex) {
            skippedEntries.add(String.format("%s: %s (%s)",
                                             ex.getMessage(),
                                             nextEntry.getName(),
                                             jf.getName()));
        }
        nextEntry = nextEntry();
    }
    return false;
}
 
Example #3
Source File: ClassFileReader.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }

    ClassFile cf;
    try {
        cf = readClassFile(nextEntry);
    } catch (IOException ex) {
        throw new ClassFileError(ex);
    }
    JarEntry entry = nextEntry;
    nextEntry = null;
    while (entries.hasMoreElements()) {
        JarEntry e = entries.nextElement();
        String name = e.getName();
        if (name.endsWith(".class")) {
            nextEntry = e;
            break;
        }
    }
    return cf;
}
 
Example #4
Source File: ClassFileReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    try {
        ClassFile cf = readClassFile(path);
        count++;
        return cf;
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #5
Source File: ClassFileReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected Set<String> scan() {
    try {
        ClassFile cf = ClassFile.read(path);
        String name = cf.access_flags.is(AccessFlags.ACC_MODULE)
            ? "module-info" : cf.getName();
        return Collections.singleton(name);
    } catch (ConstantPoolException|IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #6
Source File: ClassFileReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    Path path = entries.get(index++);
    try {
        return readClassFile(path);
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #7
Source File: ClassFileReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected ClassFile readClassFile(JarFile jarfile, JarEntry e) throws IOException {
    try (InputStream is = jarfile.getInputStream(e)) {
        ClassFile cf = ClassFile.read(is);
        if (jarfile.isMultiRelease()) {
            VersionHelper.add(jarfile, e, cf);
        }
        return cf;
    } catch (ConstantPoolException ex) {
        throw new ClassFileError(ex);
    }
}
 
Example #8
Source File: DependencyFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Set<Location> parse(Archive archive, Finder finder, String name)
    throws IOException
{
    ClassFile cf = archive.reader().getClassFile(name);
    if (cf == null) {
        throw new IllegalArgumentException(archive.getName() +
            " does not contain " + name);
    }

    if (cf.access_flags.is(AccessFlags.ACC_MODULE))
        return Collections.emptySet();

    Set<Location> targets = new HashSet<>();
    String cn;
    try {
        cn =  cf.getName().replace('/', '.');
    } catch (ConstantPoolException e) {
        throw new Dependencies.ClassFileError(e);
    }

    if (!finder.accept(archive, cn, cf.access_flags))
        return targets;

    // tests if this class matches the -include
    if (!filter.matches(cn))
        return targets;

    // skip checking filter.matches
    for (Dependency d : finder.findDependencies(cf)) {
        if (filter.accepts(d)) {
            targets.add(d.getTarget());
            archive.addClass(d.getOrigin(), d.getTarget());
        } else {
            // ensure that the parsed class is added the archive
            archive.addClass(d.getOrigin());
        }
        parsedClasses.putIfAbsent(d.getOrigin(), archive);
    }
    return targets;
}
 
Example #9
Source File: ClassFileReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected ClassFile readClassFile(Path p) throws IOException {
    InputStream is = null;
    try {
        is = Files.newInputStream(p);
        return ClassFile.read(is);
    } catch (ConstantPoolException e) {
        throw new ClassFileError(e);
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
 
Example #10
Source File: ClassFileReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    try {
        ClassFile cf = readClassFile(path);
        count++;
        return cf;
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #11
Source File: ClassFileReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    Path path = entries.get(index++);
    try {
        return readClassFile(path);
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #12
Source File: ClassFileReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected ClassFile readClassFile(JarFile jarfile, JarEntry e) throws IOException {
    InputStream is = null;
    try {
        is = jarfile.getInputStream(e);
        return ClassFile.read(is);
    } catch (ConstantPoolException ex) {
        throw new ClassFileError(ex);
    } finally {
        if (is != null)
            is.close();
    }
}
 
Example #13
Source File: ClassFileReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public boolean hasNext() {
    if (nextEntry != null && cf != null) {
        return true;
    }
    while (nextEntry != null) {
        try {
            cf = reader.readClassFile(jf, nextEntry);
            return true;
        } catch (ClassFileError | IOException ex) {
            skippedEntries.add(nextEntry.getName());
        }
        nextEntry = nextEntry();
    }
    return false;
}
 
Example #14
Source File: ClassFileReader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected ClassFile readClassFile(Path p) throws IOException {
    InputStream is = null;
    try {
        is = Files.newInputStream(p);
        return ClassFile.read(is);
    } catch (ConstantPoolException e) {
        throw new ClassFileError(e);
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
 
Example #15
Source File: ClassFileReader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    try {
        ClassFile cf = readClassFile(path);
        count++;
        return cf;
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #16
Source File: ClassFileReader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    Path path = entries.get(index++);
    try {
        return readClassFile(path);
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #17
Source File: ClassFileReader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private ClassFile readClassFile(JarEntry e) throws IOException {
    InputStream is = null;
    try {
        is = jarfile.getInputStream(e);
        return ClassFile.read(is);
    } catch (ConstantPoolException ex) {
        throw new ClassFileError(ex);
    } finally {
        if (is != null)
            is.close();
    }
}
 
Example #18
Source File: ClassFileReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected ClassFile readClassFile(Path p) throws IOException {
    InputStream is = null;
    try {
        is = Files.newInputStream(p);
        return ClassFile.read(is);
    } catch (ConstantPoolException e) {
        throw new ClassFileError(e);
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
 
Example #19
Source File: ClassFileReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    try {
        ClassFile cf = readClassFile(path);
        count++;
        return cf;
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #20
Source File: ClassFileReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    Path path = entries.get(index++);
    try {
        return readClassFile(path);
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #21
Source File: ClassFileReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private ClassFile readClassFile(JarEntry e) throws IOException {
    InputStream is = null;
    try {
        is = jarfile.getInputStream(e);
        return ClassFile.read(is);
    } catch (ConstantPoolException ex) {
        throw new ClassFileError(ex);
    } finally {
        if (is != null)
            is.close();
    }
}
 
Example #22
Source File: ClassFileReader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    try {
        ClassFile cf = readClassFile(path);
        count++;
        return cf;
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #23
Source File: ClassFileReader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    try {
        ClassFile cf = readClassFile(path);
        count++;
        return cf;
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #24
Source File: ClassFileReader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    Path path = entries.get(index++);
    try {
        return readClassFile(path);
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #25
Source File: ClassFileReader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected ClassFile readClassFile(JarFile jarfile, JarEntry e) throws IOException {
    InputStream is = null;
    try {
        is = jarfile.getInputStream(e);
        return ClassFile.read(is);
    } catch (ConstantPoolException ex) {
        throw new ClassFileError(ex);
    } finally {
        if (is != null)
            is.close();
    }
}
 
Example #26
Source File: ClassFileReader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean hasNext() {
    if (nextEntry != null && cf != null) {
        return true;
    }
    while (nextEntry != null) {
        try {
            cf = reader.readClassFile(jf, nextEntry);
            return true;
        } catch (ClassFileError | IOException ex) {
            skippedEntries.add(nextEntry.getName());
        }
        nextEntry = nextEntry();
    }
    return false;
}
 
Example #27
Source File: ClassFileReader.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected ClassFile readClassFile(Path p) throws IOException {
    InputStream is = null;
    try {
        is = Files.newInputStream(p);
        return ClassFile.read(is);
    } catch (ConstantPoolException e) {
        throw new ClassFileError(e);
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
 
Example #28
Source File: ClassFileReader.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    try {
        ClassFile cf = readClassFile(path);
        count++;
        return cf;
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #29
Source File: ClassFileReader.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public ClassFile next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    Path path = entries.get(index++);
    try {
        return readClassFile(path);
    } catch (IOException e) {
        throw new ClassFileError(e);
    }
}
 
Example #30
Source File: ClassFileReader.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected ClassFile readClassFile(JarFile jarfile, JarEntry e) throws IOException {
    InputStream is = null;
    try {
        is = jarfile.getInputStream(e);
        return ClassFile.read(is);
    } catch (ConstantPoolException ex) {
        throw new ClassFileError(ex);
    } finally {
        if (is != null)
            is.close();
    }
}