https://pantsbuild.org/ logo
#general
Title
# general
w

witty-crayon-22786

07/28/2017, 5:58 PM
Copy code
try {
      Class<?> clazz = getClass().getClassLoader().loadClass(className);
      if (Util.isTestClass(clazz)) {
        if (!specs.containsKey(clazz)) {
          Spec newSpec = new Spec(clazz);
          specs.put(clazz, newSpec);
        }
        return Optional.of(specs.get(clazz));
      }
      return Optional.absent();
    } catch (ClassNotFoundException | NoClassDefFoundError e) {
      throw new SpecException(specString,
          String.format("Class %s not found in classpath.", className), e);
    } catch (LinkageError e) {
      // Any of a number of runtime linking errors can occur when trying to load a class,
      // fail with the test spec so the class failing to link is known.
      throw new SpecException(specString,
          String.format("Error linking %s.", className), e);
      // See the comment below for justification.
    } catch (RuntimeException e) {
      // The class may fail with some variant of RTE in its static initializers, trap these
      // and dump the bad spec in question to help narrow down issue.
      throw new SpecException(specString,
          String.format("Error initializing %s.",className), e);
    }