question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JDK 15: Illegal reflective access to java.time classes

See original GitHub issue

JDK 15 produces many Illegal reflective access warnings like following on serializing LocalTime, LocalDateTime, YearMonth, MonthYear and so on:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.gson.internal.reflect.UnsafeReflectionAccessor (file:/home/eldar/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.8.6/9180733b7df8542621dc12e21e87557e8c99b8cb/gson-2.8.6.jar) to field java.time.MonthDay.month
WARNING: Please consider reporting this to the maintainers of com.google.gson.internal.reflect.UnsafeReflectionAccessor
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Code example

Gson gson = new GsonBuilder().create();
System.out.println(gson.toJson(LocalDate.now()));
System.out.println(gson.toJson(LocalDateTime.now()));
System.out.println(gson.toJson(YearMonth.now()));
System.out.println(gson.toJson(MonthDay.now()));

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
Marcono1234commented, Oct 21, 2020

Note that it is recommended to prefer TypeAdapter over JsonSerializer and JsonDeserializer since it reads the JSON data in a streaming way instead of parsing it as an in-memory representation of JsonElements. The code for it will be pretty similar to your current adapter.

0reactions
Marcono1234commented, Jul 29, 2022

Can probably be closed as duplicate of #1059.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A peek into Java 17: Encapsulating the Java runtime internals
WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by ReflBytecodeName ...
Read more >
Java 9 Illegal Reflective Access Warning - Baeldung
Before Java 9, the Java Reflection API has a superpower: It could gain access to the non-public class members without limitation.
Read more >
An illegal reflective access operation has occurred when ...
You will see An illegal reflective access operation has occurred warning when installing and using AM (including Amster and ssoadm tools), Java ......
Read more >
What is an illegal reflective access? - java - Stack Overflow
May provide a means to invoke its run-time system with one or more packages of one or more of its modules open to...
Read more >
Illegal access in Java 16 A.K.A. 'My program crashes!'
Please note it doesn't raise a warning about any “reflective access operation”, but “illegal reflective access operation”. Using reflection on ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found