<p>getInterestingSomething.</p>

@param cause     a {@link java.lang.Throwable} object.
@param sourceDir source dir
@return a {@link ameba.exception.AmebaException.InterestingSomething} object.
519623
public static InterestingSomething getInterestingSomething(Throwable cause, File sourceDir) {
        InterestingSomething something = null;
        for (StackTraceElement stackTraceElement : cause.getStackTrace()) {
            if (stackTraceElement.getLineNumber() > 0) {
                String path = stackTraceElement.getClassName().replace(".", "/");
                path = path.substring(0, path.lastIndexOf("/"));
                File source = new File(sourceDir, path);
                if (source.exists() && source.isDirectory()) {
                    String fN = stackTraceElement.getFileName();
                    int index = fN.indexOf("$");
                    if (index < 0) {
                        fN = fN.substring(0, fN.indexOf("."));
                    } else {
                        fN = fN.substring(0, index);
                    }
                    source = new File(source, fN + ".java");
                    if (something == null) {
                        something = new InterestingSomething(stackTraceElement, source);
                        something.setUsefulFiles(Lists.newArrayList());
                        something.setUsefulStackTraceElement(Lists.newArrayList());
                    } else {
                        if (source.exists()) {
                            something.getUsefulStackTraceElements().add(stackTraceElement);
                            something.getUsefulFiles().add(source);
                        }
                    }
                }
            }
        }
        return something;
    }
1190304
public static Throwable getCause(Throwable thr) {
		Throwable cause = thr.getCause();
		while (cause != null && cause != thr && cause != cause.getCause() && cause.getCause() != null) {
			cause = cause.getCause();
		}
		return cause == null ? thr : cause;
	}
941113
public static boolean shouldNotIgnoreException(Throwable cause) {
        String message = String.valueOf(cause.getMessage()).toLowerCase();

        // is ssl exception
        if (cause.getCause() instanceof SSLException || cause instanceof DecoderException | cause instanceof NotSslRecordException) {
            return false;
        }

        // first try to match connection reset / broke peer based on the regex.
        // This is the fastest way but may fail on different jdk impls or OS's
        if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
            return false;
        }

        // Inspect the StackTraceElements to see if it was a connection reset / broken pipe or not
        StackTraceElement[] elements = cause.getStackTrace();
        for (StackTraceElement element : elements) {
            String classname = element.getClassName();
            String methodname = element.getMethodName();

            // skip all classes that belong to the io.netty package
            if (classname.startsWith("io.netty.")) {
                continue;
            }

            // check if the method name is read if not skip it
            if (!"read".equals(methodname)) {
                continue;
            }

            // This will also match against SocketInputStream which is used by openjdk 7 and maybe
            // also others
            if (IGNORABLE_CLASS_IN_STACK.matcher(classname).matches()) {
                return false;
            }

            try {
                // No match by now.. Try to load the class via classloader and inspect it.
                // This is mainly done as other JDK implementations may differ in name of
                // the impl.
                Class<?> clazz = PlatformDependent.getClassLoader(ExceptionHandler.class).loadClass(classname);

                if (SocketChannel.class.isAssignableFrom(clazz)
                    || DatagramChannel.class.isAssignableFrom(clazz)) {
                    return false;
                }

                // also match against SctpChannel via String matching as it may not present.
                if (PlatformDependent.javaVersion() >= 7
                    && "com.sun.nio.sctp.SctpChannel".equals(clazz.getSuperclass().getName())) {
                    return false;
                }
            } catch (ClassNotFoundException e) {
                // This should not happen just ignore
            }
        }
        return true;
    }
326437
public static void registerInterest(String sourceKey, String regex, String rewritePattern, TypeReferenceLocation... locations)
    {
        patternsBySource.put(sourceKey, new PatternAndLocation(locations, regex, rewritePattern));
    }
1103074
private Throwable extractThrowable(Throwable exception, Class<?> causeClass) {
        if (exception == null) {
            return null;
        } else if (causeClass.isInstance(exception)) {
            return exception;
        } else {
            return extractThrowable(exception.getCause(), causeClass);
        }
    }
751804
@SuppressWarnings("unchecked")
    public <T extends Throwable> T causeOfType(Class<T> type)
    {
        IdentityHashMap<Throwable, Throwable> seen =
            new IdentityHashMap<Throwable, Throwable>();

        Throwable cause = getCause();
        while (cause != null && ! type.isInstance(cause))
        {
            if (seen.put(cause, cause) != null)  // cycle check
            {
                return null;
            }
            cause = cause.getCause();
        }
        return (T) cause;
    }
1021569
public static KbTypeException fromThrowable(Throwable cause) {
    return (cause instanceof KbTypeException)
                   ? (KbTypeException) cause
                   : new KbTypeException(cause);
  }
898058
public static Throwable getCause(Throwable e) {
        Throwable cause = null; 
        Throwable result = e;
        while (null != (cause = result.getCause()) && (result != cause)) {
            result = cause;
        }
        return result;
    }
1334220
public Throwable getMostSpecificCause()
    {
        Throwable rootCause = null;
        Throwable cause = getCause();
        while (cause != null  &&  cause != rootCause) {
            rootCause = cause;
            cause = cause.getCause();
        }

        return (rootCause == null ? this : rootCause);
    }
290677
public List<Throwable> getCauses(Throwable t)
    {
        List<Throwable> causes = new LinkedList<Throwable>();
        Throwable next = t;
        while (next.getCause() != null)
        {
            next = next.getCause();
            causes.add(next);
        }
        return causes;
    }
710108
protected static Throwable newEncoderException(final String message,
                                                   final Throwable cause) {

        try {
            return ENCODER_EXCEPTION
                .getConstructor(String.class, Throwable.class)
                .newInstance(message, cause);
        } catch (final NoSuchMethodException nsme) {
            throw new RuntimeException(nsme);
        } catch (final InstantiationException ie) {
            throw new RuntimeException(ie);
        } catch (final IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (final InvocationTargetException ite) {
            throw new RuntimeException(ite);
        }
    }
1074646
public static Set<String> getBuildFilesForSourceDirs( List<String> sourceDirs, String[] includes, String[] excludes )
        throws MojoExecutionException
    {
        Set<String> result = new LinkedHashSet<String>();

        for ( String sourceDir : sourceDirs )
        {
            try
            {
                if ( FileUtils.fileExists( sourceDir ) )
                {
                    result.addAll( FileUtils
                        .getFileNames( new File( sourceDir ),
                                       ( null == includes || 0 == includes.length ) ? DEFAULT_INCLUDES
                                                                                   : getAsCsv( includes ),
                                       ( null == excludes || 0 == excludes.length ) ? DEFAULT_EXCLUDES
                                                                                   : getAsCsv( excludes ), true ) );
                }
            }
            catch ( IOException e )
            {
                throw new MojoExecutionException( "IO Error resolving sourcedirs", e );
            }
        }
        // We might need to check if some of these files are already included through the weaveDirectories.

        return result;
    }
54499
public static MySQLErrPacket newInstance(final int sequenceId, final Exception cause) {
        if (cause instanceof SQLException) {
            SQLException sqlException = (SQLException) cause;
            return new MySQLErrPacket(sequenceId, sqlException.getErrorCode(), sqlException.getSQLState(), sqlException.getMessage());
        }
        if (cause instanceof ShardingCTLException) {
            ShardingCTLException shardingCTLException = (ShardingCTLException) cause;
            return new MySQLErrPacket(sequenceId, ShardingCTLErrorCode.valueOf(shardingCTLException), shardingCTLException.getShardingCTL());
        }
        if (cause instanceof TableModifyInTransactionException) {
            return new MySQLErrPacket(sequenceId, MySQLServerErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE, ((TableModifyInTransactionException) cause).getTableName());
        }
        if (cause instanceof UnknownDatabaseException) {
            return new MySQLErrPacket(sequenceId, MySQLServerErrorCode.ER_BAD_DB_ERROR, ((UnknownDatabaseException) cause).getDatabaseName());
        }
        if (cause instanceof NoDatabaseSelectedException) {
            return new MySQLErrPacket(sequenceId, MySQLServerErrorCode.ER_NO_DB_ERROR);
        }
        return new MySQLErrPacket(sequenceId, CommonErrorCode.UNKNOWN_EXCEPTION, cause.getMessage());
    }
790537
public static KbRuntimeException fromThrowable(Throwable cause) {
    return (cause instanceof KbRuntimeException)
                   ? (KbRuntimeException) cause
                   : new KbRuntimeException(cause);
  }
1224808
@Nonnull
    public static Consumer<Throwable> here(@Nonnull Consumer<? super Throwable> acceptor)
    {
        ContextException context = new ContextException();
        return (ex) ->
        {
            Throwable cause = ex;
            while (cause.getCause() != null)
                cause = cause.getCause();
            cause.initCause(context);
            if (acceptor != null)
                acceptor.accept(ex);
        }
863883
@SuppressWarnings("unchecked")
	public static Throwable getCausedBy(Throwable throwable, Class<? extends Exception>... causeClasses) {
		Throwable cause = throwable;
		while (cause != null) {
			for (Class<? extends Exception> causeClass : causeClasses) {
				if (causeClass.isInstance(cause)) {
					return cause;
				}
			}
			cause = cause.getCause();
		}
		return null;
	}
826858
@Nullable
    public static <T> T log(Throwable cause) {
        logger.warn("Unexpected exception from a completion action:", cause);
        return null;
    }