JDK 15: Illegal reflective access to java.time classes
See original GitHub issueJDK 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:
- Created 3 years ago
- Reactions:1
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Note that it is recommended to prefer
TypeAdapter
overJsonSerializer
andJsonDeserializer
since it reads the JSON data in a streaming way instead of parsing it as an in-memory representation ofJsonElement
s. The code for it will be pretty similar to your current adapter.Can probably be closed as duplicate of #1059.