forked from loafle/openapi-generator-original
Replace Class.newInstance() with Constructor.newInstance() (#1635)
This commit is contained in:
parent
c4f0521e10
commit
7e3e9dba11
@ -45,7 +45,7 @@ public class CodegenConfigLoader {
|
||||
|
||||
// else try to load directly
|
||||
try {
|
||||
return (CodegenConfig) Class.forName(name).newInstance();
|
||||
return (CodegenConfig) Class.forName(name).getDeclaredConstructor().newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new GeneratorNotFoundException("Can't load config class with name '".concat(name) + "'\nAvailable:\n" + availableConfigs.toString(), e);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -35,7 +36,7 @@ public final class CodegenModelFactory {
|
||||
throw new IllegalArgumentException(implementation.getSimpleName() + " doesn't extend " + type.getDefaultImplementation().getSimpleName());
|
||||
}
|
||||
try {
|
||||
implementation.newInstance();
|
||||
implementation.getDeclaredConstructor().newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
@ -46,8 +47,8 @@ public final class CodegenModelFactory {
|
||||
public static <T> T newInstance(CodegenModelType type) {
|
||||
Class<?> classType = typeMapping.get(type);
|
||||
try {
|
||||
return (T) (classType != null ? classType : type.getDefaultImplementation()).newInstance();
|
||||
} catch (IllegalAccessException | InstantiationException e) {
|
||||
return (T) (classType != null ? classType : type.getDefaultImplementation()).getDeclaredConstructor().newInstance();
|
||||
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user