Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

JNA 5.13.0: C++ Side Mutex Creation Fails with "Invalid Memory" Error

Open
#1,670 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp, java
Domain
tooling

Research direction

Start by reproducing the Java JNA call to the MSVC-built C++ library using the provided createMutex example, then inspect the Java/native boundary and the mutex construction or locking point where invalid memory is reported. Done means identifying the cause of the invalid memory access and confirming a corrected interaction on Windows 10.

Written by the indexing model from the issue text.

Description

Description:

When using JNA 5.13.0 to interface with a C++ library, an issue arises where attempting to create a mutex on the C++ side results in an "invalid memory" error. This issue occurs consistently whenever the mutex creation is attempted. Below are the details of the environment and the problem:

Environment:

  • Java Version: 1.8.0_361 (Oracle JDK)
  • JNA Version: 5.13.0(5.17.0 same err)
  • Operating System: [Windows 10]
  • C++ Compiler/Environment: [MSVC]

Problem Description:
The Java application uses JNA to interact with a native C++ library.
On the C++ side, when attempting to create a std::mutex (or any other type of mutex), the program throws an error related to invalid memory access.
The error message or behavior indicates that the memory allocation or usage for the mutex is corrupted or invalid.

Example Code:

Java Side:

public interface MyLibrary extends Library {
    MyLibrary INSTANCE = Native.load("mylibrary", MyLibrary.class);

    void createMutex();
}

public class Main {
    public static void main(String[] args) {
        MyLibrary.INSTANCE.createMutex();
    }
}

C++ Side:

#include <mutex>
extern "C" {
    void createMutex() {
        std::mutex mtx; // Attempting to create a mutex
        mtx.lock();      // Error occurs here or during construction
        mtx.unlock();
    }
}

Error
java.lang.Error: Invalid memory access

Dominant language
Java
Stars
8.9k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from java-native-access/jna

All issues in java-native-access/jna

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.