Fixes compatibility issues with Java 10

Use non-deprecated methods still compatible with Java 8. These mostly
just propagate Exceptions up when instantiating constructors when using
the database functions.

Reverted POM back to Java 8 so that compiled code will work on Java 8 as
well.
This commit is contained in:
tastybento 2018-08-31 07:44:47 -07:00
parent 95f8c81963
commit 10db4230b0
8 changed files with 32 additions and 20 deletions

View File

@ -43,7 +43,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.10</java.version>
<java.version>1.8</java.version>
<powermock.version>1.7.4</powermock.version>
</properties>

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.api.addons;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
@ -35,7 +36,7 @@ public class AddonClassLoader extends URLClassLoader {
MalformedURLException,
InvalidDescriptionException,
InstantiationException,
IllegalAccessException {
IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
super(new URL[]{path.toURI().toURL()}, parent);
loader = addonsManager;
@ -58,7 +59,7 @@ public class AddonClassLoader extends URLClassLoader {
throw new InvalidAddonInheritException("Main class doesn't not extends super class 'Addon'");
}
addon = addonClass.newInstance();
addon = addonClass.getDeclaredConstructor().newInstance();
addon.setDescription(asDescription(data));
// Set permissions
if (data.isConfigurationSection("permissions")) {

View File

@ -41,7 +41,8 @@ public class Config<T> {
try {
result = handler.loadObjects();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | ClassNotFoundException | IntrospectionException e) {
| InvocationTargetException | ClassNotFoundException | IntrospectionException
| NoSuchMethodException | SecurityException e) {
logger.severe(() -> "Could not load config! Error: " + e.getMessage());
}
return result;
@ -56,7 +57,7 @@ public class Config<T> {
try {
return handler.loadObject(uniqueId);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| ClassNotFoundException | IntrospectionException e) {
| ClassNotFoundException | IntrospectionException | NoSuchMethodException | SecurityException e) {
logger.severe(() -> "Could not load config object! " + e.getMessage());
}

View File

@ -48,16 +48,22 @@ public abstract class AbstractDatabaseHandler<T> {
/**
* Loads all the records in this table and returns a list of them
* @return list of <T>
* @throws SecurityException
* @throws NoSuchMethodException
* @throws IllegalArgumentException
*/
public abstract List<T> loadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException;
public abstract List<T> loadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException;
/**
* Creates a <T> filled with values from the corresponding
* database file
* @param uniqueId - unique ID
* @return <T>
* @throws SecurityException
* @throws NoSuchMethodException
* @throws IllegalArgumentException
*/
public abstract T loadObject(String uniqueId) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException;
public abstract T loadObject(String uniqueId) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException;
/**
* Save T into the corresponding database

View File

@ -49,7 +49,8 @@ public class Database<T> {
try {
result = handler.loadObjects();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | ClassNotFoundException | IntrospectionException e) {
| InvocationTargetException | ClassNotFoundException | IntrospectionException
| NoSuchMethodException | SecurityException e) {
logger.severe(() -> "Could not load objects from database! Error: " + e.getMessage());
}
return result;
@ -65,7 +66,7 @@ public class Database<T> {
try {
result = handler.loadObject(uniqueId);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| ClassNotFoundException | IntrospectionException e) {
| ClassNotFoundException | IntrospectionException | NoSuchMethodException | SecurityException e) {
logger.severe(() -> "Could not load object from database! " + e.getMessage());
}
return result;

View File

@ -25,7 +25,7 @@ public class ConfigHandler<T> extends FlatFileDatabaseHandler<T> {
saveObject(instance);
}
public T loadSettings(String uniqueId, T dbConfig) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException {
public T loadSettings(String uniqueId, T dbConfig) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException {
if (dbConfig == null) {
return loadObject(uniqueId);
}

View File

@ -72,7 +72,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
* @see world.bentobox.bentobox.database.AbstractDatabaseHandler#loadObject(java.lang.String)
*/
@Override
public T loadObject(String key) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException {
public T loadObject(String key) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException {
// Objects are loaded from a folder named after the simple name of the class being stored
String path = DATABASE_FOLDER_NAME + File.separator + dataObject.getSimpleName();
// This path and key can be overridden by the StoreAt annotation in the code
@ -97,7 +97,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
* @see world.bentobox.bentobox.database.AbstractDatabaseHandler#loadObjects()
*/
@Override
public List<T> loadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException {
public List<T> loadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, NoSuchMethodException, SecurityException {
// In this case, all the objects of a specific type are being loaded.
List<T> list = new ArrayList<>();
// Look for any files that end in .yml in the folder
@ -135,10 +135,13 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
* @param config - YAML config file
*
* @return <T> filled with values
* @throws SecurityException
* @throws NoSuchMethodException
* @throws IllegalArgumentException
*/
private T createObject(YamlConfiguration config) throws InstantiationException, IllegalAccessException, IntrospectionException, InvocationTargetException, ClassNotFoundException {
private T createObject(YamlConfiguration config) throws InstantiationException, IllegalAccessException, IntrospectionException, InvocationTargetException, ClassNotFoundException, IllegalArgumentException, NoSuchMethodException, SecurityException {
// Create a new instance of the dataObject of type T (which can be any class)
T instance = dataObject.newInstance();
T instance = dataObject.getDeclaredConstructor().newInstance();
// Run through all the fields in the object
for (Field field : dataObject.getDeclaredFields()) {
@ -167,7 +170,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// Get the original value to be stored
Object value = config.get(storageLocation);
// Invoke the deserialization on this value
method.invoke(instance, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).deserialize(value));
method.invoke(instance, ((AdapterInterface<?,?>)adapterNotation.value().getDeclaredConstructor().newInstance()).deserialize(value));
// We are done here. If a custom adapter was defined, the rest of this method does not need to be run
continue;
}
@ -354,8 +357,8 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
// A conversion adapter has been defined
try {
config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).serialize(value));
} catch (InstantiationException e) {
config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().getDeclaredConstructor().newInstance()).serialize(value));
} catch (InstantiationException | IllegalArgumentException | NoSuchMethodException | SecurityException e) {
plugin.logError("Could not instatiate adapter " + adapterNotation.value().getName() + " " + e.getMessage());
}
// We are done here

View File

@ -24,12 +24,12 @@ public class MySQLDatabaseConnector implements DatabaseConnector {
public MySQLDatabaseConnector(DatabaseConnectionSettingsImpl dbSettings) {
this.dbSettings = dbSettings;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Class.forName("com.mysql.jdbc.Driver").getDeclaredConstructor().newInstance();
} catch (Exception e) {
Bukkit.getLogger().severe("Could not instantiate JDBC driver! " + e.getMessage());
}
// jdbc:mysql://localhost:3306/Peoples?autoReconnect=true&useSSL=false
connectionUrl = "jdbc:mysql://" + dbSettings.getHost() + ":" + dbSettings.getPort() + "/" + dbSettings.getDatabaseName() + "?autoReconnect=true&useSSL=false&allowMultiQueries=true";
connectionUrl = "jdbc:mysql://" + dbSettings.getHost() + ":" + dbSettings.getPort() + "/" + dbSettings.getDatabaseName()
+ "?autoReconnect=true&useSSL=false&allowMultiQueries=true";
}
@Override