Example usage for java.lang UnsupportedClassVersionError toString

List of usage examples for java.lang UnsupportedClassVersionError toString

Introduction

In this page you can find the example usage for java.lang UnsupportedClassVersionError toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:net.sourceforge.pmd.lang.LanguageRegistry.java

private LanguageRegistry() {
    List<Language> languagesList = new ArrayList<>();
    // Use current class' classloader instead of the threads context classloader, see https://github.com/pmd/pmd/issues/1377
    ServiceLoader<Language> languageLoader = ServiceLoader.load(Language.class, getClass().getClassLoader());
    Iterator<Language> iterator = languageLoader.iterator();
    while (iterator.hasNext()) {
        try {/*from   w  w  w . j ava  2  s  . co  m*/
            Language language = iterator.next();
            languagesList.add(language);
        } catch (UnsupportedClassVersionError e) {
            // Some languages require java8 and are therefore only available
            // if java8 or later is used as runtime.
            System.err.println("Ignoring language for PMD: " + e.toString());
        }
    }

    // sort languages by terse name. Avoiding differences in the order of languages
    // across JVM versions / OS.
    Collections.sort(languagesList, new Comparator<Language>() {
        @Override
        public int compare(Language o1, Language o2) {
            return o1.getTerseName().compareToIgnoreCase(o2.getTerseName());
        }
    });

    // using a linked hash map to maintain insertion order
    languages = new LinkedHashMap<>();
    for (Language language : languagesList) {
        languages.put(language.getName(), language);
    }
}