private void searchStateClass(HashMap<String, State> availableStates) throws NoSuchFieldException, IllegalAccessException, InstantiationException, IOException {

        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        JavaFileManager fm = compiler.getStandardFileManager(new DiagnosticCollector<JavaFileObject>(), null, null);
        Set<JavaFileObject.Kind> kind = new HashSet<JavaFileObject.Kind>(){{
            add(JavaFileObject.Kind.CLASS);
        }};

        if (null == availableStates) {
            return;
        }

        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        String regex = ".*/(.*)\\.class$";
        Pattern ptn = Pattern.compile(regex);
        String className;

        for (String packageName : STATE_PACKAGES) {
            for (JavaFileObject f : fm.list(StandardLocation.CLASS_PATH, packageName, kind, false)) {
                Matcher m = ptn.matcher(f.getName());
                if (m.find()) {
                    try {
                        className = m.group(1);
                        if (!className.contains("$")) { // ignore inner class case
                            State state = (State) loader.loadClass(packageName + "." + className).newInstance();
                            availableStates.put(className, state);
                        }
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }