<java> When "EXCEPTION_ACCESS_VIOLATION" appears in awt

Preface

When I tried to use awt for a university java task, I got a lot of errors and struggled for an hour, so I will leave a solution. Please note that this is the first article.

Environment

OS : Windows10 JDK : 15.0.1 JRE : 15.0.1

Since there was such a description in the error statement described later, I refer to it. vm_info: OpenJDK 64-Bit Server VM (15.0.1+9-18) for windows-amd64 JRE (15.0.1+9-18)

I am using Intel iJIDEA Ultimate as an editor, and since there was neither jdk nor jre at the time of installation, I installed the newest one according to the instructions of IDEA.

Symptoms

Source code

AWTGraphics.java


import java.awt.*;

public class AWTGraphics extends Canvas
{
    static final int WORLD_W = 320;
    static final int WORLD_H = 240;

    public void paint(Graphics g)
    {
        g.setColor(Color.red);
        g.drawLine(0, 0, WORLD_W, WORLD_H);
        g.setFont(new Font("Dialog", Font.PLAIN, 20));
        g.drawString("Hello, awt!", 0, WORLD_H / 2);
    }
    public static void main(String[] args)
    {
        Frame frame = new Frame("AWTGraphics");
        frame.setBackground(Color.black);
        AWTGraphics canvas = new AWTGraphics();
        canvas.setPreferredSize(new Dimension(WORLD_W, WORLD_H));
        frame.add(canvas);
        frame.pack();
        frame.setVisible(true);
    }
}
When it can be executed correctly
![スクリーンショット 2021-01-17 224536.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1032962/9a3493cb-102e-6a9c-58b8-9a5c19ebd3b8.png)
Error statement (excerpt)

hs_err_pid4364.log


#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ff83d8902ae, pid=4364, tid=2572
#
# JRE version: OpenJDK Runtime Environment (15.0.1+9) (build 15.0.1+9-18)
# Java VM: OpenJDK 64-Bit Server VM (15.0.1+9-18, mixed mode, sharing, tiered, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# C  [awt.dll+0x902ae]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Since the error sentence is long and not very readable, only the first few lines are listed. I haven't read it properly either.

Apparently IDEA seems to be very good and outputs the stack and memory status in detail as an error log, but It has little to do with it.

Is it here to pay attention to?

# C  [awt.dll+0x902ae]

Apparently, the file in this JRE called "awt.dll + 0x902ae" is doing something wrong. However, since it is a .dll located in the "/ bin" directory of JRE, you probably cannot directly rewrite this file.

Solution ①

It seems that it will be cured if you specify a different character code in the file encoding when executing. In my environment, the default file encoding was UTF-8, so I changed it to Windows-31j (Shift-JIS).

When changing with Intel iJIDEA

IDEA Settings-> File Encodings From here I changed the Global Encoding to Windows-31j. ![スクリーンショット 2021-01-17 230753.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1032962/1160208f-1220-baf3-844e-cbf161db1d21.png)

However, this will result in encoding with Windows-31j when executing all projects, which may be troublesome later. (I don't know the details, but I think it is preferable to encode in UTF-8 unless there is a specific reason.)

In that case, it may be better to change only Project Encoding.

When changing on the command line

I think this is the case in most cases. It's time to hit the java command with bash or cmd. Just add a file encoding option at the end.

With your favorite command line tool


java -Dfile.encoding=windows-31j AWTGraphics 

I think there are several ways to change the file encoding. As you like.

Solution ②

Some people have tried lowering the JRE version as one of the methods. If you can't get rid of it with solution ①, you may want to try it. However, I haven't tried it because I don't know how much the version should be lowered to cure it even after various investigations.

References

https://qiita.com/solabito331/items/fad5a1eea3176aadd9f7

https://teratail.com/questions/260615

https://stackoverflow.com/questions/6448163/a-fatal-error-has-been-detected-by-the-java-runtime-environment-sigsegv-libjvm

https://teratail.com/questions/297104 ↑ This is the method I actually tried and solved.

Recommended Posts

<java> When "EXCEPTION_ACCESS_VIOLATION" appears in awt
When seeking multiple in a Java array
Partization in Java
Changes in Java 11
Rock-paper-scissors in Java
Pi in Java
FizzBuzz in Java
When there are environment variables in Java tests
A note when you want Tuple in Java
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
Combine arrays in Java
"Hello World" in Java
Callable Interface in Java
Comments in Java source
Azure functions in java
Format XML in Java
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Solution when class_cast_exception appears in create_index! Of elasticsearch-rails (7 series)
Use OpenCV in Java
webApi memorandum in java
Type determination in Java
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
POST JSON in Java
What I learned when building a server in Java
Express failure in Java
Create JSON in Java
Date manipulation in Java 8
When you want to dynamically replace Annotation in Java8
What's new in Java 8
Differences in code when using the length system in Java
Use PreparedStatement in Java
What's new in Java 9,10,11
Parallel execution in Java
Initializing HashMap in Java
Resolve CreateProcess error = 206 when running Java in a Windows environment
JMeter Memorandum [Settings when sampling multipart / form-data in Java application]
Things you often use when doing web development in Java
Things to be aware of when writing code in Java
How to dynamically switch JDK when building Java in Gradle
Show detailed error in Logger when running Java on server
Java Object Serialization why & when
Try using RocksDB in Java
Read binary files in Java 1
Avoid Yubaba's error in Java
Get EXIF information in Java
Save Java PDF in Excel
[Neta] Sleep Sort in Java
Edit ini in Java: ini4j