openjdk/jdk · critical

java.lang.instrument/-javaagent: initialization of native ag

Error message

java.lang.instrument/-javaagent: initialization of native agent failed.\n

What it means

createNewJPLISAgent() returned the generic JPLIS_INIT_ERROR_FAILURE — native agent initialization failed for a reason other than allocation or agent-class absence (those have their own messages). The launcher prints this line and returns JNI_ERR, aborting startup. The specific native cause happened inside JPLIS initialization (e.g. setting up the transform/JNI machinery) and is only visible with native debugging.

Source

Thrown at src/java.instrument/share/native/libinstrument/InvocationAdapter.c:273

        free(premainClass);
    }

    if (initerror != JPLIS_INIT_ERROR_NONE) {
        free(jarfile);
    }
    if (options != NULL) free(options);

    switch (initerror) {
    case JPLIS_INIT_ERROR_NONE:
      result = JNI_OK;
      break;
    case JPLIS_INIT_ERROR_CANNOT_CREATE_NATIVE_AGENT:
      result = JNI_ERR;
      fprintf(stderr, "java.lang.instrument/-javaagent: cannot create native agent.\n");
      break;
    case JPLIS_INIT_ERROR_FAILURE:
      result = JNI_ERR;
      fprintf(stderr, "java.lang.instrument/-javaagent: initialization of native agent failed.\n");
      break;
    case JPLIS_INIT_ERROR_ALLOCATION_FAILURE:
      result = JNI_ERR;
      fprintf(stderr, "java.lang.instrument/-javaagent: allocation failure.\n");
      break;
    case JPLIS_INIT_ERROR_AGENT_CLASS_NOT_SPECIFIED:
      result = JNI_ERR;
      fprintf(stderr, "-javaagent: agent class not specified.\n");
      break;
    default:
      result = JNI_ERR;
      fprintf(stderr, "java.lang.instrument/-javaagent: unknown error\n");
      break;
    }
    return result;
}

/*

View on GitHub (pinned to 88dfb74bbe)

Solutions

  1. Verify the JDK installation is intact and single-version: reinstall the JDK and ensure JAVA_HOME/PATH point at it
  2. If embedding the JVM, verify you invoke with matching JNI libraries and a properly created VM before agent options are processed
  3. Check OS logs (SELinux/auditd, antivirus) for denials against libinstrument.so / jvm.dll
  4. Try the same agent on a stock launcher of the exact same JDK version to isolate embedding/tooling issues
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: A later phase of -javaagent initialization failing: JNI environment setup, capability registration (Can-Retransform-Classes processing), or internal state transitions returning failure. Typically surfaces with unusual JVM configurations, broken JNI environments in embedded launchers, or JDK/libinstrument version mismatches (e.g. a launcher from one JDK invoking another release's JVM with agent options).

Common situations: Mixed-JDK tooling where the java launcher and the runtime libinstrument differ; JNI-embedded JVMs passing agent options; corrupted JDK installs (truncated/mismatched libs); OS-level interference (antivirus hooking, SELinux denials on the instrument library).

Related errors


AI-assisted analysis of openjdk/jdk@88dfb74bbe (2026-08-14). Data as JSON: /api/errors/ba3f6229c8fa061a. Report an issue: GitHub.