#3126: Use suppliers instead of reflection for native impl generation.

This commit is contained in:
Janmm14
2021-06-26 00:01:30 +00:00
committed by GitHub
parent a8b2f5268d
commit cb738188de
6 changed files with 17 additions and 16 deletions

View File

@@ -6,18 +6,19 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.function.Supplier;
import net.md_5.bungee.jni.cipher.BungeeCipher;
public final class NativeCode<T>
{
private final String name;
private final Class<? extends T> javaImpl;
private final Class<? extends T> nativeImpl;
private final Supplier<? extends T> javaImpl;
private final Supplier<? extends T> nativeImpl;
//
private boolean loaded;
public NativeCode(String name, Class<? extends T> javaImpl, Class<? extends T> nativeImpl)
public NativeCode(String name, Supplier<? extends T> javaImpl, Supplier<? extends T> nativeImpl)
{
this.name = name;
this.javaImpl = javaImpl;
@@ -26,13 +27,7 @@ public final class NativeCode<T>
public T newInstance()
{
try
{
return ( loaded ) ? nativeImpl.getDeclaredConstructor().newInstance() : javaImpl.getDeclaredConstructor().newInstance();
} catch ( ReflectiveOperationException ex )
{
throw new RuntimeException( "Error getting instance", ex );
}
return ( loaded ) ? nativeImpl.get() : javaImpl.get();
}
public boolean load()

View File

@@ -25,9 +25,15 @@ public class JavaCipher implements BungeeCipher
}
}
public JavaCipher() throws GeneralSecurityException
public JavaCipher()
{
this.cipher = Cipher.getInstance( "AES/CFB8/NoPadding" );
try
{
this.cipher = Cipher.getInstance( "AES/CFB8/NoPadding" );
} catch ( GeneralSecurityException ex )
{
throw new RuntimeException( ex );
}
}
@Override