Improved: Remove deprecation warning by removing direct call to Class::newInstance

Class.newInstance() has a flaw, in which any Throwable from the constructor is
thrown unchecked. It was deprecated in Java 9, but not marked for removal.
It shows as a deprecation warning when compiling OfBiz with Java 11.

Thanks: Heinz Kabutz for reporting and initially committing 0e6732b. This
completes in plugins and all will we backported
This commit is contained in:
Jacques Le Roux
2022-04-01 10:41:55 +02:00
parent daa5f74b42
commit 265cc7f83e
@@ -18,6 +18,7 @@
*******************************************************************************/
package org.apache.ofbiz.ws.rs.util;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -298,8 +299,9 @@ public final class OpenApiUtil {
return null;
}
try {
schema = (Schema<?>) schemaClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
schema = (Schema<?>) schemaClass.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| SecurityException e) {
e.printStackTrace();
}
@@ -377,8 +379,9 @@ public final class OpenApiUtil {
continue;
}
try {
schema = (Schema<?>) schemaClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
schema = (Schema<?>) schemaClass.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| SecurityException e) {
e.printStackTrace();
}
if (schemaClass != null) {