Get the name of the missing class from a ClassNotFoundException.

@param ex
the ClassNotFoundException
@return the name of the missing class, or null if we couldn't figure out
the class name
436956
public static @DottedClassName
    String getMissingClassName(ClassNotFoundException ex) {
        // If the exception has a ResourceNotFoundException as the cause,
        // then we have an easy answer.
        Throwable cause = ex.getCause();
        if (cause instanceof ResourceNotFoundException) {
            String resourceName = ((ResourceNotFoundException) cause).getResourceName();
            if (resourceName != null) {
                ClassDescriptor classDesc = DescriptorFactory.createClassDescriptorFromResourceName(resourceName);
                return classDesc.toDottedClassName();
            }
        }

        if (ex.getMessage() == null) {
            return null;
        }

        // Try the regular expression patterns to parse the class name
        // from the exception message.
        for (Pattern pattern : patternList) {
            Matcher matcher = pattern.matcher(ex.getMessage());
            if (matcher.matches()) {
                String className = matcher.group(1);
                ClassName.assertIsDotted(className);
                return className;
            }
        }
        return null;
    }
363807
private Class<?> getImportedClassImpl(final String name) throws UtilEvalError {
        // Try explicitly imported class, e.g. import foo.Bar;
        String fullname = this.importedClasses.get(name);
        // not sure if we should really recurse here for explicitly imported
        // class in parent...
        if (fullname != null) {
            /* Found the full name in imported classes. */
            // Try to make the full imported name
            Class<?> clas = this.classForName(fullname);

            if ( clas != null )
                return clas;

            // Handle imported inner class case
            // Imported full name wasn't found as an absolute class
            // If it is compound, try to resolve to an inner class.
            // (maybe this should happen in the BshClassManager?)
            if (Name.isCompound(fullname))
                try {
                    clas = this.getNameResolver(fullname).toClass();
                } catch (final ClassNotFoundException e) { /* not a class */ }
            Interpreter.debug(
                        "imported unpackaged name not found:", fullname);
            // If found cache the full name in the BshClassManager
            if (clas != null) {
                // (should we cache info in not a class case too?)
                this.getClassManager().cacheClassInfo(fullname, clas);
                return clas;
            }
            // It was explicitly imported, but we don't know what it is.
            // should we throw an error here??
            return null;
        }
        /* Try imported packages, e.g. "import foo.bar.*;" in reverse order of
         * import... (give later imports precedence...) */
        for (final String s: this.importedPackages) {
            final Class<?> c = this.classForName(s + "." + name);
            if (c != null)
                return c;
        }
        final BshClassManager bcm = this.getClassManager();
        /* Try super import if available Note: we do this last to allow
         * explicitly imported classes and packages to take priority. This
         * method will also throw an error indicating ambiguity if it
         * exists... */
        if (bcm.hasSuperImport()) {
            final String s = bcm.getClassNameByUnqName(name);
            if (s != null)
                return this.classForName(s);
        }
        return null;
    }
66334
private int getMatchedDepth(String exceptionType, Throwable ex) {
        Throwable t = ex.getCause();
        if (t != null) {
            return getMatchedDepth(exceptionType, t);
        } else {
            return getMatchedDepth(exceptionType, ex.getClass(), 0);
        }
    }
245892
public static String getStackTrace(final Throwable ex) {
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw, true);
        ex.printStackTrace(pw);
        pw.flush();
        sw.flush();
        return sw.toString();
    }
869500
public Class<?> getClassByName(String name) throws ClassNotFoundException {
    return Class.forName(name, true, classLoader);
  }
936816
public String getColumnClassName(int column) throws SQLException
    {
        sourceResultSet.checkColumnBounds(column);
        VoltType type = sourceResultSet.table.getColumnType(column - 1);
        String result = type.getJdbcClass();
        if (result == null) {
            throw SQLError.get(SQLError.TRANSLATION_NOT_FOUND, type);
        }
        return result;
    }
806534
public NonDelayedClassInfo getClassInfo() {

        String useName = getName();

        NonDelayedClassInfo useClassInfo = this.classInfo;

        if (useClassInfo != null) {
            if (!useClassInfo.isJavaClass() &&
                !(useClassInfo.isAnnotationPresent() ||
                  useClassInfo.isFieldAnnotationPresent() ||
                useClassInfo.isMethodAnnotationPresent())) {
                getInfoStore().recordAccess(useClassInfo);
            }
            return useClassInfo;
        }

        useClassInfo = getInfoStore().resolveClassInfo(useName);

        String[] useLogParms = getLogParms();
        if (useLogParms != null) {
            useLogParms[EXTRA_DATA_OFFSET_0] = useName;
        }

        if (useClassInfo == null) {
            // defect 84235: If an error caused this, the warning was reported at a lower level. Since this is 
            // going to be 'handled', we should not generate another warning message.
            //Tr.warning(tc, "ANNO_CLASSINFO_CLASS_NOTFOUND", getHashText(), useName); // CWWKC0025W

            if (useLogParms != null) {
                Tr.debug(tc, MessageFormat.format("[ {0} ] - Class not found [ {1} ]",
                                                  (Object[]) useLogParms));
            }

            useClassInfo = new NonDelayedClassInfo(useName, getInfoStore());

            this.isArtificial = true;

            // START: TFB: Defect 59284: More required updates:
            //
            // The newly created class info was not properly added as a class info,
            // leading to an NPE in the cache list management (in ClassInfoCache.makeFirst).

            getInfoStore().getClassInfoCache().addClassInfo(useClassInfo);

            // END: TFB: Defect 59284: More required updates:
        }

        // START: TFB: Defect 59284: Don't throw an exception for a failed load.
        //
        // Tracing enablement for defect 59284 showed an error of the sequence
        // of assigning the result class info hash text into the logging parameters.
        //
        // Prior to the assignment steps, 'this.classInfo' is null.
        //
        // A NullPointerException results, respective only of trace enablement
        // and irrespective of the d59284 changes.
        //
        // Move the logging code to after the 'this.classInfo' assignment.

        // if (useLogParms != null) {
        //     useLogParms[EXTRA_DATA_OFFSET_1] = this.classInfo.getHashText();
        // }

        useClassInfo.setDelayedClassInfo(this);
        this.classInfo = useClassInfo;

        if (useLogParms != null) {
            useLogParms[EXTRA_DATA_OFFSET_1] = this.classInfo.getHashText(); // D59284

            if (this.isArtificial) {
                Tr.debug(tc, MessageFormat.format("[ {0} ] RETURN [ {1} ] as [ {2} ] ** ARTFICIAL **",
                                                  (Object[]) useLogParms));
            } else {
                Tr.debug(tc, MessageFormat.format("[ {0} ] RETURN [ {1} ] as [ {2} ] ",
                                                  (Object[]) useLogParms));
            }
        }

        // END: TFB: Defect 59284: Don't throw an exception for a failed load.

        return useClassInfo;
    }
255482
public static String getMainClassName() {
		StackTraceElement trace[] = Thread.currentThread().getStackTrace();
		if (trace.length > 0) {
			return trace[trace.length - 1].getClassName();
		}
		return "Unknown";
	}
570850
static public void reportMissingClass(ClassNotFoundException e) {
        requireNonNull(e, "argument is null");
        String missing = AbstractBugReporter.getMissingClassName(e);
        if (skipReportingMissingClass(missing)) {
            return;
        }
        if (!analyzingApplicationClass()) {
            return;
        }

        RepositoryLookupFailureCallback lookupFailureCallback = getCurrentLookupFailureCallback();
        if (lookupFailureCallback != null) {
            lookupFailureCallback.reportMissingClass(e);
        }
    }
984336
@SuppressWarnings("rawtypes")
  public Class getException() {
    try {
      return Class.forName(errorParam, true, Thread.currentThread().getContextClassLoader()).newInstance().getClass();
    } catch (Exception e) {
      return null;
    }
  }
88034
public Class<?> getClass(Object example) {
    if (example instanceof HibernateProxy) {
      HibernateProxy proxy = (HibernateProxy) example;
      LazyInitializer initializer = proxy.getHibernateLazyInitializer();
      SessionImplementor implementor = initializer.getSession();

      if (initializer.isUninitialized()) {
        try {
          // getImplementation is going to want to talk to a session
          if (implementor.isClosed()) {
            // Give up and return example.getClass();
            return example.getClass();
          }
        } catch (NoSuchMethodError ex) {
          // We must be using Hibernate 3.0/3.1 which doesn't have
          // this method
        }
      }

      return initializer.getImplementation().getClass();
    } else {
      return example.getClass();
    }
  }
805028
public String getClassName() {
        switch (sort) {
        case VOID:
            return "void";
        case BOOLEAN:
            return "boolean";
        case CHAR:
            return "char";
        case BYTE:
            return "byte";
        case SHORT:
            return "short";
        case INT:
            return "int";
        case FLOAT:
            return "float";
        case LONG:
            return "long";
        case DOUBLE:
            return "double";
        case ARRAY:
            StringBuilder sb = new StringBuilder(getElementType().getClassName());
            for (int i = getDimensions(); i > 0; --i) {
                sb.append("[]");
            }
            return sb.toString();
        case OBJECT:
            return new String(buf, off, len).replace('/', '.').intern();
        default:
            return null;
        }
    }
1332552
@Override
	protected Class<?> findClass(final String name) throws ClassNotFoundException {
		log.trace("findClass:" + name);
		Class<?> clazz = findLoadedClass(name);
		if (clazz != null) {
			return clazz;
		}
		return super.findClass(name);
	}
1099624
public ClassLoader getExternalClassLoader()
    {
        Map<String,String> opts = _ap.getAnnotationProcessorEnvironment().getOptions();
        String classpath = opts.get("-classpath");

        if ( classpath != null )
        {
            String [] cpEntries = classpath.split( File.pathSeparator );
            ArrayList a = new ArrayList();
            for ( String e : cpEntries )
            {
                try
                {
                    File f = (new File(e)).getCanonicalFile();
                    URL u = f.toURL();
                    a.add(u);
                }
                catch (Exception ex)
                {
                    System.err.println( "getExternalClassLoader(): bad cp entry=" + e );
                    System.err.println( "Exception processing e=" + ex );
                }
            }
            URL [] urls = new URL[a.size()];
            urls = (URL[]) a.toArray(urls);

            return new URLClassLoader( urls, ControlChecker.class.getClassLoader() );
        }

        return null;
    }
1037598
def get_classname(obj):
    
    if isinstance(obj, javabridge.JB_Object):
        cls = javabridge.call(obj, "getClass", "()Ljava/lang/Class;")
        return javabridge.call(cls, "getName", "()Ljava/lang/String;")
    elif inspect.isclass(obj):
        return obj.__module__ + "." + obj.__name__
    else:
        return get_classname(obj.__class__)
814987
protected ClassLoader getClassLoader() {
        ClassLoader classLoader = null;
        try {
            classLoader = Thread.currentThread().getContextClassLoader();
        } catch (Throwable ex) {
            // Cannot access thread context ClassLoader - falling back...
        }
        return (classLoader != null ? classLoader : getClass().getClassLoader());
    }
105425
public static String getClassName(Class<?> cls) {
        if (cls.isMemberClass()) {
            String name = cls.getName();
            name = StringUtils.substringAfterLast(name, PACKAGE_SEPARATOR);
            return name;
        }

        return cls.getSimpleName();
    }