Search in sources :

Example 1 with BadClassFile

use of com.sun.tools.javac.jvm.ClassReader.BadClassFile in project ceylon-compiler by ceylon.

the class T6435291 method main.

public static void main(String... args) {
    javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, null, null, null, null, null);
    JavaCompiler compiler = JavaCompiler.instance(task.getContext());
    try {
        compiler.resolveIdent("T").complete();
    } catch (BadClassFile e) {
        System.err.println("Passed: expected completion failure " + e.getClass().getName());
        return;
    } catch (Exception e) {
        throw new RuntimeException("Failed: unexpected exception");
    }
    throw new RuntimeException("Failed: no error reported");
}
Also used : JavacTaskImpl(com.sun.tools.javac.api.JavacTaskImpl) BadClassFile(com.sun.tools.javac.jvm.ClassReader.BadClassFile) JavaCompiler(com.sun.tools.javac.main.JavaCompiler)

Example 2 with BadClassFile

use of com.sun.tools.javac.jvm.ClassReader.BadClassFile in project ceylon-compiler by ceylon.

the class T6330997 method main.

public static void main(String... args) {
    increaseMajor("T1.class", 1);
    increaseMajor("T2.class", 2);
    javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, null, null, null, null, null);
    JavaCompiler compiler = JavaCompiler.instance(task.getContext());
    try {
        compiler.resolveIdent("T1").complete();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Failed: unexpected exception while reading class T1");
    }
    try {
        compiler.resolveIdent("T2").complete();
    } catch (BadClassFile e) {
        System.err.println("Passed: expected completion failure " + e.getClass().getName());
        return;
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Failed: unexpected exception while reading class T2");
    }
    throw new RuntimeException("Failed: no error reported");
}
Also used : JavacTaskImpl(com.sun.tools.javac.api.JavacTaskImpl) BadClassFile(com.sun.tools.javac.jvm.ClassReader.BadClassFile) JavaCompiler(com.sun.tools.javac.main.JavaCompiler)

Aggregations

JavacTaskImpl (com.sun.tools.javac.api.JavacTaskImpl)2 BadClassFile (com.sun.tools.javac.jvm.ClassReader.BadClassFile)2 JavaCompiler (com.sun.tools.javac.main.JavaCompiler)2