fix: set constructor accessible before invocation

This commit is contained in:
LordMZTE 2023-05-27 19:04:20 +02:00
parent 1d000d813c
commit 0f712a14c1
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
2 changed files with 9 additions and 2 deletions

View file

@ -3,6 +3,7 @@ import org.gradle.api.JavaVersion.VERSION_1_8
val specTitle = "JAlec"
val artifact = specTitle.lowercase()
group = "net.anvilcraft"
version = "0.1.1"
plugins {
id("java")

View file

@ -1,5 +1,7 @@
package net.anvilcraft.alec.jalec.strategies.implementations;
import java.lang.reflect.Constructor;
import net.anvilcraft.alec.jalec.IAlecException;
import net.anvilcraft.alec.jalec.factories.AlecCriticalRuntimeErrorExceptionFactory;
import net.anvilcraft.alec.jalec.strategies.interfaces.IAlecExceptionContructionStrategy;
@ -9,8 +11,12 @@ public class StandardConstructorAlecExceptionConstructionStrategy<E extends IAle
@Override
public E constructAlecException(String message, Throwable cause, Class<E> alecExceptionClass) {
try {
return alecExceptionClass.getConstructor(String.class, Throwable.class)
.newInstance(message, cause);
Constructor<E> constructor
= alecExceptionClass.getConstructor(String.class, Throwable.class);
constructor.setAccessible(true);
return constructor.newInstance(message, cause);
} catch (Exception e) {
throw AlecCriticalRuntimeErrorExceptionFactory.PLAIN.createAlecExceptionWithCause(
e, "Error while constructing ALEC exception"