@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 shouldPerformClassLoadAndInstrumentLoadForInstrumentedClasses() throws Exception {
    ClassLoader classLoader = new SandboxClassLoader(configureBuilder().build());
    Class<?> exampleClass = classLoader.loadClass(AnExampleClass.class.getName());
    assertSame(classLoader, exampleClass.getClassLoader());
    Field roboDataField = exampleClass.getField(ShadowConstants.CLASS_HANDLER_DATA_FIELD_NAME);
    assertNotNull(roboDataField);
    assertThat(Modifier.isPublic(roboDataField.getModifiers())).isTrue();
    assertThat(Modifier.isTransient(roboDataField.getModifiers())).isTrue();

    // Java 9 doesn't allow updates to final fields from outside <init> or <clinit>:
    // https://bugs.openjdk.java.net/browse/JDK-8157181
    // Therefore, these fields need to be nonfinal / be made nonfinal.
    assertThat(Modifier.isFinal(roboDataField.getModifiers())).isFalse();
    assertThat(Modifier.isFinal(exampleClass.getField("STATIC_FINAL_FIELD").getModifiers()))
        .isFalse();
    assertThat(Modifier.isFinal(exampleClass.getField("nonstaticFinalField").getModifiers()))
        .isFalse();
  }