Example usage for java.lang StackTraceElement getClassName

List of usage examples for java.lang StackTraceElement getClassName

Introduction

In this page you can find the example usage for java.lang StackTraceElement getClassName.

Prototype

public String getClassName() 

Source Link

Document

Returns the fully qualified name of the class containing the execution point represented by this stack trace element.

Usage

From source file:org.spongepowered.asm.mixin.transformer.MixinTransformer.java

/**
 * If re-entrance is detected, attempt to find the source and log a warning
 *///from   w  ww  .  j av a 2  s .  c om
private void detectReEntrance() {
    Set<String> transformerClasses = new HashSet<String>();
    for (IClassTransformer transformer : Launch.classLoader.getTransformers()) {
        transformerClasses.add(transformer.getClass().getName());
    }

    transformerClasses.remove(this.getClass().getName());

    for (StackTraceElement stackElement : Thread.currentThread().getStackTrace()) {
        if (transformerClasses.contains(stackElement.getClassName())) {
            this.logger.warn("Re-entrance detected from transformer " + stackElement.getClassName()
                    + ", this will cause serious problems.");
            return;
        }
    }

    this.logger.warn("Re-entrance detected from unknown source, this will cause serious problems.",
            new RuntimeException());
}

From source file:org.apache.sysml.runtime.instructions.gpu.context.JCudaObject.java

private String getClassAndMethod(StackTraceElement st) {
    String[] str = st.getClassName().split("\\.");
    return str[str.length - 1] + "." + st.getMethodName();
}

From source file:org.openmrs.module.ModuleClassLoader.java

/**
 * Custom loadClass implementation to allow for loading from a given ModuleClassLoader and skip
 * the modules that have been tried already
 * //w ww.  j  a  va 2s. co  m
 * @param name String path and name of the class to load
 * @param resolve boolean whether or not to resolve this class before returning
 * @param requestor ModuleClassLoader with which to try loading
 * @param seenModules Set&lt;String&gt; moduleIds that have been tried already
 * @return Class that has been loaded
 * @throws ClassNotFoundException if no class found
 */
protected synchronized Class<?> loadClass(final String name, final boolean resolve,
        final ModuleClassLoader requestor, Set<String> seenModules) throws ClassNotFoundException {

    if (log.isTraceEnabled()) {
        log.trace("Loading " + name + " " + getModule() + ", seenModules: " + seenModules + ", requestor: "
                + requestor + ", resolve? " + resolve);
        StringBuilder output = new StringBuilder();
        for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
            if (element.getClassName().contains("openmrs")) {
                output.append("+ ");
            }
            output.append(element);
            output.append("\n");
        }
        log.trace("Stacktrace: " + output.toString());
    }

    // Check if we already tried this class loader
    if ((seenModules != null) && seenModules.contains(getModule().getModuleId())) {
        throw new ClassNotFoundException("Can't load class " + name + " from module "
                + getModule().getModuleId() + ". It has been tried before.");
    }

    // Make sure the module is started
    if ((this != requestor) && !ModuleFactory.isModuleStarted(getModule())) {
        String msg = "Can't load class " + name + ", because module " + getModule().getModuleId()
                + " is not yet started.";
        log.warn(msg);

        throw new ClassNotFoundException(msg);
    }

    // Check if the class has already been loaded by this class loader
    Class<?> result = findLoadedClass(name);

    // Try loading the class with this class loader 
    if (result == null) {
        try {
            result = findClass(name);
        } catch (ClassNotFoundException e) {
            // Continue trying...
        }
    }

    // We were able to "find" a class
    if (result != null) {
        checkClassVisibility(result, requestor);

        return result;
    }

    // Look through this module's imports to see if the class
    // can be loaded from them.

    if (seenModules == null) {
        seenModules = new HashSet<String>();
    }

    // Add this module to the list of modules we've tried already
    seenModules.add(getModule().getModuleId());

    List<Module> importedModules = new ArrayList<Module>();
    if (requiredModules != null) {
        Collections.addAll(importedModules, requiredModules);
    }
    if (awareOfModules != null) {
        Collections.addAll(importedModules, awareOfModules);
    }

    for (Module importedModule : importedModules) {
        if (seenModules.contains(importedModule.getModuleId())) {
            continue;
        }

        ModuleClassLoader moduleClassLoader = ModuleFactory.getModuleClassLoader(importedModule);

        // Module class loader may be null if module has not been started yet
        if (moduleClassLoader != null) {
            try {
                result = moduleClassLoader.loadClass(name, resolve, requestor, seenModules);

                return result;
            } catch (ClassNotFoundException e) {
                // Continue trying...
            }
        }
    }

    throw new ClassNotFoundException(name);
}

From source file:org.springframework.boot.SpringApplication.java

private Class<?> deduceMainApplicationClass() {
    try {/*w w  w.  ja  v  a 2s .  c  om*/
        StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
        for (StackTraceElement stackTraceElement : stackTrace) {
            if ("main".equals(stackTraceElement.getMethodName())) {
                return Class.forName(stackTraceElement.getClassName());
            }
        }
    } catch (ClassNotFoundException ex) {
        // Swallow and continue
    }
    return null;
}

From source file:org.kuali.kfs.module.purap.service.impl.ElectronicInvoiceHelperServiceImpl.java

/**
 * @param element/*ww w .j  a  v a  2s  .co m*/
 * @return String describing the given StackTraceElement
 */
private static String describeStackTraceElement(StackTraceElement element) {
    StringBuffer description = new StringBuffer();
    if (element == null) {
        description.append("invalid (null) element");
    }
    description.append(element.getClassName());
    description.append(".");
    description.append(element.getMethodName());
    description.append("(");
    description.append(element.getFileName());
    description.append(":");
    description.append(element.getLineNumber());
    description.append(")");

    return description.toString();
}

From source file:com.rapidminer.tools.Tools.java

public static File findSourceFile(StackTraceElement e) {
    try {/*from w  w w. j  a  va2 s. c  o  m*/
        Class<?> clazz = Class.forName(e.getClassName());
        while (clazz.getDeclaringClass() != null) {
            clazz = clazz.getDeclaringClass();
        }
        String filename = clazz.getName().replace('.', File.separatorChar);
        return FileSystemService.getSourceFile(filename + ".java");
    } catch (Throwable t) {
    }
    String filename = e.getClassName().replace('.', File.separatorChar);
    return FileSystemService.getSourceFile(filename + ".java");
}

From source file:org.batoo.jpa.benchmark.BenchmarkTest.java

private void measureTime(long worked, ThreadInfo threadInfo) {
    TimeElement child = this.element;
    boolean gotStart = false;
    boolean last = false;

    boolean inDb = false;
    if (threadInfo == null) {
        return;//  w w  w.j  av a  2 s .  com
    }

    for (int i = threadInfo.getStackTrace().length - 1; i >= 0; i--) {
        final StackTraceElement stElement = threadInfo.getStackTrace()[i];
        if (this.isInDb(stElement)) {
            inDb = true;
            break;
        }
    }

    for (int i = threadInfo.getStackTrace().length - 1; i >= 0; i--) {
        final StackTraceElement stElement = threadInfo.getStackTrace()[i];

        if (!gotStart && !stElement.getMethodName().startsWith("singleTest")) {
            continue;
        }

        gotStart = true;

        final String key = BenchmarkTest.SUMMARIZE ? //
                stElement.getClassName() + "." + stElement.getMethodName() : //
                stElement.getClassName() + "." + stElement.getMethodName() + "." + stElement.getLineNumber();

        child = child.get(key);
        TimeElement child2 = this.elements.get(key);
        if (child2 == null) {
            this.elements.put(key, child2 = new TimeElement(key));
        }

        if (this.isInDb(stElement) || (i == 0)) {
            child.addTime(worked, true, inDb);
            child2.addTime(worked, true, inDb);
            last = true;
        } else {
            child.addTime(worked, false, inDb);
            child2.addTime(worked, false, inDb);
        }

        if (last) {
            break;
        }
    }
}

From source file:org.nuclos.server.ruleengine.ejb3.RuleEngineFacadeBean.java

private int getErrorLineNumber(Exception ex, int iHeaderLinesCount) {
    int iErrorLineNumber = 0;
    for (StackTraceElement stackElement : ex.getStackTrace()) {
        if (stackElement.getClassName().startsWith("Rule_")) {
            iErrorLineNumber = stackElement.getLineNumber();
            break;
        }//from   w w w .ja  va  2  s .c  o m
    }
    return iErrorLineNumber > 0 ? (iErrorLineNumber - iHeaderLinesCount) : 0;
}

From source file:org.zywx.wbpalmstar.engine.EBrowserView.java

protected void printThreadStackTrace() {
    StackTraceElement[] stak = Thread.currentThread().getStackTrace();
    String s = "";
    int len = stak.length;
    for (int i = 0; i < len; ++i) {
        StackTraceElement one = stak[i];
        String className = one.getClassName();
        String methodName = one.getMethodName();
        int line = one.getLineNumber();
        String x = s + className + "." + methodName + " [" + line + "]";
        x.charAt(0);//from w  w w .ja v  a2s.co m
        if (i == 0 || i == 1 || i == 2) {
            s += " ";
        }
    }
}

From source file:org.csploit.android.core.UpdateService.java

@Override
protected void onHandleIntent(Intent intent) {
    action what_to_do = (action) intent.getSerializableExtra(ACTION);
    boolean exitForError = true;

    if (what_to_do == null) {
        Logger.error("received null action");
        return;//from   w ww  .  j  a va 2s  .c  om
    }

    mRunning = true;

    switch (what_to_do) {
    case apk_update:
        mCurrentTask = mApkInfo;
        break;
    case core_update:
        mCurrentTask = mCoreInfo;
        break;
    case ruby_update:
        mCurrentTask = mRubyInfo;
        break;
    case msf_update:
        mCurrentTask = mMsfInfo;
        break;
    case gems_update:
        mCurrentTask = new ArchiveMetadata();
        break;
    }

    try {
        setupNotification();

        synchronized (mCurrentTask) {
            mCurrentTask.errorOccurred = true;
            if (!haveLocalFile())
                downloadFile();

            if (what_to_do == action.core_update)
                System.shutdownCoreDaemon();

            extract();

            if (what_to_do == action.msf_update)
                installGems();
            else if (what_to_do == action.gems_update)
                updateGems();
            else if (what_to_do == action.core_update)
                System.initCore();

            deleteTemporaryFiles();
            createVersionFile();

            mCurrentTask.errorOccurred = exitForError = false;
        }

        sendDone(what_to_do);
    } catch (SecurityException e) {
        sendError(what_to_do, R.string.bad_permissions);
        Logger.warning(e.getClass().getName() + ": " + e.getMessage());
    } catch (KeyException e) {
        sendError(what_to_do, R.string.checksum_failed);
        Logger.warning(e.getClass().getName() + ": " + e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        sendError(what_to_do, R.string.error_occured);
        System.errorLogging(e);
    } catch (CancellationException e) {
        sendError(what_to_do, R.string.update_cancelled);
        Logger.warning(e.getClass().getName() + ": " + e.getMessage());
    } catch (IOException e) {
        sendError(what_to_do, R.string.error_occured);
        System.errorLogging(e);
    } catch (RuntimeException e) {
        sendError(what_to_do, R.string.error_occured);

        StackTraceElement[] stack = e.getStackTrace();
        StackTraceElement frame = e.getStackTrace()[0];

        for (StackTraceElement f : stack) {
            if (f.getClassName().startsWith("org.csploit.android")) {
                frame = f;
                break;
            }
        }

        Logger.error(String.format("%s: %s [%s:%d]", e.getClass().getName(), e.getMessage(),
                frame.getFileName(), frame.getLineNumber()));
    } catch (InterruptedException e) {
        sendError(what_to_do, R.string.error_occured);
        System.errorLogging(e);
    } catch (ChildManager.ChildNotStartedException e) {
        sendError(what_to_do, R.string.error_occured);
        System.errorLogging(e);
    } catch (ChildManager.ChildDiedException e) {
        sendError(what_to_do, R.string.error_occured);
        System.errorLogging(e);
    } catch (System.SuException e) {
        sendError(what_to_do, R.string.only_4_root);
    } catch (System.DaemonException e) {
        sendError(what_to_do, R.string.heart_attack);
        Logger.error(e.getMessage());
    } finally {
        if (exitForError) {
            if (what_to_do == action.msf_update || what_to_do == action.gems_update)
                clearGemsCache();
            if (what_to_do != action.core_update)
                wipe();
        }
        stopSelf();
        mRunning = false;
    }
}