Esempio n. 1
0
  private static boolean verifyWithAsm(@NotNull OutputFile file, ClassLoader loader) {
    ClassNode classNode = new ClassNode();
    new ClassReader(file.asByteArray()).accept(classNode, 0);

    SimpleVerifier verifier = new SimpleVerifier();
    verifier.setClassLoader(loader);
    Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(verifier);

    boolean noErrors = true;
    for (MethodNode method : classNode.methods) {
      try {
        analyzer.analyze(classNode.name, method);
      } catch (Throwable e) {
        System.err.println(file.asText());
        System.err.println(classNode.name + "::" + method.name + method.desc);

        //noinspection InstanceofCatchParameter
        if (e instanceof AnalyzerException) {
          // Print the erroneous instruction
          TraceMethodVisitor tmv = new TraceMethodVisitor(new Textifier());
          ((AnalyzerException) e).node.accept(tmv);
          PrintWriter pw = new PrintWriter(System.err);
          tmv.p.print(pw);
          pw.flush();
        }

        e.printStackTrace();
        noErrors = false;
      }
    }
    return noErrors;
  }
Esempio n. 2
0
  @NotNull
  protected ClassFileFactory generateClassesInFile() {
    if (classFileFactory == null) {
      try {
        classFileFactory = generateFiles(myEnvironment, myFiles);

        if (DxChecker.RUN_DX_CHECKER) {
          DxChecker.check(classFileFactory);
        }
      } catch (Throwable e) {
        e.printStackTrace();
        System.err.println("Generating instructions as text...");
        try {
          if (classFileFactory == null) {
            System.out.println("Cannot generate text: exception was thrown during generation");
          } else {
            System.out.println(classFileFactory.createText());
          }
        } catch (Throwable e1) {
          System.err.println(
              "Exception thrown while trying to generate text, the actual exception follows:");
          e1.printStackTrace();
          System.err.println(
              "-----------------------------------------------------------------------------");
        }
        fail("See exceptions above");
      }
    }
    return classFileFactory;
  }