Replace Class.newInstance() with getDeclaredConstructor().newInstance() (#5600)
Co-authored-by: 吴晟 Wu Sheng <wu.sheng@foxmail.com>
This commit is contained in:
parent
7c69ea889e
commit
772f1d2e82
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.skywalking.apm.commons.datacarrier.consumer;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.apache.skywalking.apm.commons.datacarrier.buffer.Channels;
|
||||
|
||||
|
|
@ -58,13 +59,17 @@ public class ConsumeDriver<T> implements IDriver {
|
|||
|
||||
private IConsumer<T> getNewConsumerInstance(Class<? extends IConsumer<T>> consumerClass) {
|
||||
try {
|
||||
IConsumer<T> inst = consumerClass.newInstance();
|
||||
IConsumer<T> inst = consumerClass.getDeclaredConstructor().newInstance();
|
||||
inst.init();
|
||||
return inst;
|
||||
} catch (InstantiationException e) {
|
||||
throw new ConsumerCannotBeCreatedException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new ConsumerCannotBeCreatedException(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new ConsumerCannotBeCreatedException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new ConsumerCannotBeCreatedException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ public class MakeWrapperInterceptor implements StaticMethodsAroundInterceptor {
|
|||
int ix = 0;
|
||||
for (Method m : ms.values())
|
||||
wc.getField("mts" + ix++).set(null, m.getParameterTypes());
|
||||
return (Wrapper) wc.newInstance();
|
||||
return (Wrapper) wc.getDeclaredConstructor().newInstance();
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ public class MakeWrapperInterceptor implements StaticMethodsAroundInterceptor {
|
|||
int ix = 0;
|
||||
for (Method m : ms.values())
|
||||
wc.getField("mts" + ix++).set(null, m.getParameterTypes());
|
||||
return (Wrapper) wc.newInstance();
|
||||
return (Wrapper) wc.getDeclaredConstructor().newInstance();
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue