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 ; }
Get the name of the missing class from a ClassNotFoundException .