Esempio n. 1
0
 private static String getClassName(byte[] bytecode) throws IllegalClassFormatException {
   try {
     return new ClassReader(bytecode).getClassName();
   } catch (Throwable t) {
     /* If the class file contains errors, ASM will just crash. */
     IllegalClassFormatException e = new IllegalClassFormatException();
     e.initCause(t);
     throw e;
   }
 }
  @Override
  public void onLoad(ClassPool pool, String classname)
      throws NotFoundException, CannotCompileException {
    logger.debug("loading className:{}", classname);

    try {
      // Find Modifier from agent and try transforming
      String replace = classname.replace('.', '/');
      ClassFileTransformer classFileTransformer = agent.getClassFileTransformer();
      byte[] transform = classFileTransformer.transform(this.loader, replace, null, null, null);
      if (transform != null) {
        pool.makeClass(new ByteArrayInputStream(transform));
        return;
      }
    } catch (IOException ex) {
      throw new NotFoundException(classname + " not found. Caused:" + ex.getMessage(), ex);
    } catch (IllegalClassFormatException ex) {
      throw new RuntimeException(classname + " not found. Caused:" + ex.getMessage(), ex);
    }

    // find from modifierMap
    findModifierMap(pool, classname);
  }