How to fix java module error "Caused by: java.lang.reflect.InaccessibleObjectException: module java.base does not "opens java.util" to unnamed module"

The error message you're seeing, (Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @6d4a82") or  java.lang.reflect.InaccessibleObjectException, is related to module system changes introduced in Java 9 and later versions. It occurs when you try to access a field, method, or class that is not accessible due to module restrictions. In this case, it appears that you're trying to access the private final java.util.Comparator field of a java.util.TreeMap, which is not accessible because the java.base module does not open java.util to unnamed modules.