MATLAB function from Java causes Runtime Error (EXCEPTION_ACCESS_VIOLATION)


I'm using MATLAB Engine API for Java, so far basics such as eval and feval functions work without a problem. I even drew an histogram with those. But PutVariable method causes me to have "EXCEPTION_ACCESS_VIOLATION".

Code is:

package connecter;

import java.util.*;  
import java.util.concurrent.ExecutionException;

import com.mathworks.engine.*;

public class MainClass {

    public static void main(String[] args) throws IllegalArgumentException, IllegalStateException, InterruptedException, MatlabExecutionException, MatlabSyntaxException, ExecutionException {

        MatlabEngine matEng = MatlabEngine.startMatlab();
        matEng.putVariable("x", 3.0);

Console gives me the following:

# A fatal error has been detected by the Java Runtime Environment:
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000001b224d20b95, pid=1904, tid=8768
# JRE version: Java(TM) SE Runtime Environment (12.0.2+10) (build 12.0.2+10)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (12.0.2+10, mixed mode, sharing, tiered, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# v  ~StubRoutines::atomic_add_long
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
# An error report file with more information is saved as:
# [Filepath]\hs_err_pid1904.log
Could not load hsdis-amd64.dll; library not loadable; PrintAssembly is disabled
# If you would like to submit a bug report, please visit:

So far I've searched through countless threads but nothing has worked so far. I'm using JavaSE-12 and MATLAB is R2019b.

asked on Stack Overflow Dec 8, 2019 by R. Arda

1 Answer


You're doing it right. This is a bug in Matlab, the JDK, or both. Not much you can do here. Contact support for MathWorks and your JDK vendor and let them know what happened, and talk to your IT department to see if you have a weird machine configuration that might be messing them up.

And try running against a different JDK, like a much lower major version such as JDK 8. Matlab uses old JDK versions, so it's more likely to be tested and work against them.

answered on Stack Overflow Dec 9, 2019 by Andrew Janke

User contributions licensed under CC BY-SA 3.0