---
title: "CWE-111: Direct Use of Unsafe JNI"
url: https://radicalnotion.ai/cwe/cwe-111
type: cwe
description: "When a Java application uses the Java Native Interface (JNI) to call code written in another programming language, it can expose the application to weaknesses in that code, even if those weaknesses cannot occur in Java."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-111: Direct Use of Unsafe JNI

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 2
- **Of those, in CISA KEV:** 0
- **New in 2026:** 0
- **CWE catalog version:** 4.21

## Description

When a Java application uses the Java Native Interface (JNI) to call code written in another programming language, it can expose the application to weaknesses in that code, even if those weaknesses cannot occur in Java.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | Many safety features that programmers may take for granted do not apply for native code. The languages used to implement native code may be more susceptible to buffer overflows and other attacks. Native code is unprotected by the security features enforced by the runtime environment, such as strong typing and array bounds checking. |

## Applicable platforms

**Languages:** Java (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Access Control | Bypass Protection Mechanism | - |

## Potential mitigations

### Implementation

Implement error handling around the JNI call.

### Implementation (Refactoring)

Do not use JNI calls if the native library can't be trusted.

### Implementation (Refactoring)

Be reluctant to use JNI calls. A Java API equivalent may exist.

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

The following code defines a class named Echo. The class declares one native method (defined below), which uses C to echo commands entered on the console back to the user. The following C code defines the native method implemented in the Echo class:

Bad code:

```java
class Echo {

    public native void runEcho();
    static {

        System.loadLibrary("echo");
    }
    public static void main(String[] args) {

        new Echo().runEcho();
    }
}
```

Bad code:

```c
#include <jni.h>
#include "Echo.h"//the java class above compiled with javah
#include <stdio.h>

JNIEXPORT void JNICALL
Java_Echo_runEcho(JNIEnv *env, jobject obj)
{
    char buf[64];
    gets(buf);
    printf(buf);
}
```

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2018-12549 | JDK: missing null check when accelerating Unsafe calls | critical | 9.8 | - | No | 2019-02-11 |
| CVE-2016-9160 | Improper Restriction of Operations within the Bounds of a Memory Buffer in Siemens SIMATIC WinCC and SIMATIC PCS 7 ActiveX | high | 8.1 | - | No | 2016-12-17 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-20](https://radicalnotion.ai/cwe/cwe-20) | Improper Input Validation |
| Parent | [CWE-695](https://radicalnotion.ai/cwe/cwe-695) | Use of Low-Level Functionality |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| 7 Pernicious Kingdoms | Unsafe JNI | - | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Define wrappers around native methods | SEC08-J | - |
| SEI CERT Oracle Coding Standard for Java | Safely invoke standard APIs that perform tasks using the immediate caller's class loader instance (loadLibrary) | JNI01-J | - |
| SEI CERT Oracle Coding Standard for Java | Define wrappers around native methods | JNI00-J | Imprecise |
| Software Fault Patterns | Use of an improper API | SFP3 | - |

## Frequently asked questions

### What is CWE-111?

When a Java application uses the Java Native Interface (JNI) to call code written in another programming language, it can expose the application to weaknesses in that code, even if those weaknesses cannot occur in Java.

### What CVEs are caused by CWE-111?

2 recorded CVEs are attributed to CWE-111, including CVE-2018-12549 and CVE-2016-9160.

### How do you prevent CWE-111?

Implement error handling around the JNI call.

### How is CWE-111 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-111?

Exploiting CWE-111 can lead to: Bypass Protection Mechanism.

### Is CWE-111 actively exploited?

2 recorded CVEs are caused by CWE-111; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/111.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-111). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
