From 672acd38d0d7f55519c04428bf179f1f9256f7d5 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 15 Aug 2021 15:40:31 +0200 Subject: [PATCH] ProviderFactory: Avoid accessing subclass in parent class initialization --- .../org/pgpainless/provider/ProviderFactory.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/provider/ProviderFactory.java b/pgpainless-core/src/main/java/org/pgpainless/provider/ProviderFactory.java index f24f30c0..99a801f9 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/provider/ProviderFactory.java +++ b/pgpainless-core/src/main/java/org/pgpainless/provider/ProviderFactory.java @@ -19,7 +19,7 @@ import java.security.Provider; public abstract class ProviderFactory { - private static ProviderFactory FACTORY = new BouncyCastleProviderFactory(); + private static ProviderFactory FACTORY; protected abstract Provider _getProvider(); protected abstract String _getProviderName(); @@ -28,12 +28,19 @@ public abstract class ProviderFactory { ProviderFactory.FACTORY = factory; } + public static ProviderFactory getFactory() { + if (FACTORY == null) { + FACTORY = new BouncyCastleProviderFactory(); + } + return FACTORY; + } + public static Provider getProvider() { - return ProviderFactory.FACTORY._getProvider(); + return ProviderFactory.getFactory()._getProvider(); } public static String getProviderName() { - return ProviderFactory.FACTORY._getProviderName(); + return ProviderFactory.getFactory()._getProviderName(); } }