module java.base does not "opens java.net" to unnamed module

105 views
Skip to first unread message

Nico Hirdes

unread,
Jan 13, 2023, 4:35:03 AM1/13/23
to Ebean ORM
Hello
What does this message mean? I dont know how to fix it.
It occures while connecting to my database via Ebean on Java.

[03:22:59] [Server thread/INFO]: | Unable to make field private static volatile boolean java.net.URLConnection.defaultUseCaches accessible: module java.base does not "opens java.net" to unnamed module @5e9f7335




The server is geting installed by this:

public static EbeanServer getServer(IDatabaseConfiguration configuration) {

DatabaseHandler database = new DatabaseHandler(MinecraftValley.plugin.getClass().getClassLoader()) {
protected List<Class<?>> getDatabaseClasses() {
List<Class<?>> list = new ArrayList<>();
list.add(User.class);
return list;
}
};
database.initializeDatabase("com.mysql.jdbc.Driver", String.format("jdbc:mysql://%s:%s/%s", configuration.getHostname(), configuration.getPort(), configuration.getDatabase()),
configuration.getUsername(), configuration.getPassword(), "SERIALIZABLE", false, false);
return database.getDatabase();


Thanks alot for help!

Nico Hirdes

unread,
Jan 13, 2023, 5:55:57 AM1/13/23
to Ebean ORM
private void loadDatabase() {
//Declare a few local variables for later use
ClassLoader currentClassLoader = null;
Field cacheField = null;
boolean cacheValue = true;

try {
//Store the current ClassLoader, so it can be reverted later
currentClassLoader = Thread.currentThread().getContextClassLoader();

//Set the ClassLoader to Plugin ClassLoader
Thread.currentThread().setContextClassLoader(classLoader);

//Get a reference to the private static "defaultUseCaches"-field in URLConnection
cacheField = HttpURLConnection.class.getDeclaredField("defaultUseCaches");

//Make it accessible, store the default value and set it to false
cacheField.setAccessible(true);
cacheValue = cacheField.getBoolean(null);
cacheField.setBoolean(null, false);

//Setup Ebean based on the configuration
ebeanServer = EbeanServerFactory.create(serverConfig);
} catch (Exception ex) {
throw new RuntimeException("Failed to create a new instance of the EbeanServer", ex);
} finally {
//Revert the ClassLoader back to its original value
if (currentClassLoader != null) {
Thread.currentThread().setContextClassLoader(currentClassLoader);
}

//Revert the "defaultUseCaches"-field in URLConnection back to its original value
try {
if (cacheField != null) {
cacheField.setBoolean(null, cacheValue);
}
} catch (Exception e) {
System.out.println("Failed to revert the \"defaultUseCaches\"-field back to its original value, URLConnection-caching remains disabled.");
}
}
}


other code 

Rob Bygrave

unread,
Feb 13, 2023, 3:00:45 PM2/13/23
to Ebean ORM
When I see "Unnamed module" that typically means a module created for running tests.

It looks to me like this application is using module-path for running tests and that is not allowing that reflective access. You could try to use classpath instead of module path?
Reply all
Reply to author
Forward
0 new messages