Q:

ClassPool.get() throwing NotFoundException on class that clearly exists?

I am using the Javassist library to load a class at runtime.
public class FilterClassGenerator<T, DT> {
   private volatile static Long classNameIncrementor = 1L;

   private Class<T> listFilterClass;
   private Class<DT> dataObjectClass;

   public FilterClassGenerator(Class<T> listFilterClass, Class<DT> dataObjectClass) {
       this.listFilterClass = listFilterClass;
       this.dataObjectClass = dataObjectClass;
   }

   public T createFilterClass(ApiFilter filter) {
       try {
           ClassPool pool = ClassPool.getDefault();
           CtClass comparison = pool.makeClass("com.frammo.filterClasses." + generateNewClassName());
           comparison.setSuperclass(pool.get(listFilterClass.getName()));
           // More code

I am getting the following error at: 
 comparison.setSuperclass(pool.get(listFilterClass.getName()));
javassist.NotFoundException: com.frammo.stocks.api.simulation.IiiAccountComparisonFilter

But clearly this class exists!
package com.frammo.stocks.api.simulation;

// Imports

public abstract class IiiAccountComparisonFilter extends ListComparisonFilter<IiiAccount> {

}

Any ideas why it cannot find the class?

A:

This generally happens  when Class pool does not find the class in all available search paths. To fix this problem you need to add the class path of your class files to class pool's search path as given below:
    ClassPool.getDefault().insertClassPath(new ClassClassPath(YourCurrentClassName.class));

A:

I assume this happens because of your use of ClassPool.getDefault(). From the method's documentation:

The default class pool searches the system search path, which usually
  includes the platform library, extension libraries, and the search
  path specified by the -classpath option or the CLASSPATH environment
  variable.

I assume that your class com.frammo.stocks.api.simulation.IiiAccountComparisonFilter is not on the system class path.
You can verify this easily by calling:
Class.forName(
  "com.frammo.stocks.api.simulation.IiiAccountComparisonFilter",
  true,
  ClassLoader.getSystemClassLoader());

This will most likey throw an exception as well. Is your application running as a web application? Such applications load using a different class loader.
You need to make this class source known to the ClassPool. Check the ClassPool's API for how to do this.

