@Override
  public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
    synchronized (getClassLoadingLock(name)) {
      Class<?> loadedClass = findLoadedClass(name);
      if (loadedClass != null) {
        return loadedClass;
      }
      if (isClosed) {
        throw new ClassNotFoundException("This ClassLoader is closed");
      }
      if (config.shouldAcquire(name)) {
        loadedClass =
            PerfStatsCollector.getInstance()
                .measure("load sandboxed class", () -> maybeInstrumentClass(name));
      } else {
        loadedClass = getParent().loadClass(name);
      }

      if (resolve) {
        resolveClass(loadedClass);
      }

      return loadedClass;
    }
  }
@Test
  public void shouldDumpClassesWhenConfigured() throws Exception {
    Path tempDir = Files.createTempDirectory("SandboxClassLoaderTest");
    System.setProperty("robolectric.dumpClassesDirectory", tempDir.toAbsolutePath().toString());
    ClassLoader classLoader = new SandboxClassLoader(configureBuilder().build());
    classLoader.loadClass(AnExampleClass.class.getName());
    try (Stream<Path> stream = Files.list(tempDir)) {
      List<Path> files = stream.collect(Collectors.toList());
      assertThat(files).hasSize(1);
      assertThat(files.get(0).toAbsolutePath().toString())
          .containsMatch("org.robolectric.testing.AnExampleClass-robo-instrumented-\\d+.class");
      Files.delete(files.get(0));
    } finally {
      Files.delete(tempDir);
      System.clearProperty("robolectric.dumpClassesDirectory");
    }
  }