WICKET-6154 Performance bottleneck when using KeyInSessionSunJceCryptFactory
Reduce the complexity of the method by removing a conditional branch that is not really needed. Note: Security#getProviders() javadoc states that it may return null but the implementation (and the years in usage) show that it actually returns empty array Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/77e1e856 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/77e1e856 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/77e1e856 Branch: refs/heads/WICKET-6183 Commit: 77e1e856b024f79b6e30a4dcc94fc91bf49cb9c8 Parents: c6f53a6 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Sun May 22 10:44:49 2016 +0200 Committer: Andrea Del Bene <[email protected]> Committed: Fri May 27 13:12:16 2016 +0200 ---------------------------------------------------------------------- .../crypt/KeyInSessionSunJceCryptFactory.java | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/77e1e856/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java b/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java index ceedcfc..ce3037e 100644 --- a/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java +++ b/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java @@ -64,21 +64,20 @@ public class KeyInSessionSunJceCryptFactory implements ICryptFactory { this.cryptMethod = Args.notNull(cryptMethod, "Crypt method"); - - if (Security.getProviders("Cipher." + cryptMethod).length > 0) - { - return; // we are good to go! - } - try + if (Security.getProviders("Cipher." + cryptMethod).length == 0) { - // Initialize and add a security provider required for encryption - final Class<?> clazz = Class.forName("com.sun.crypto.provider.SunJCE"); + try + { + // Initialize and add a security provider required for encryption + final Class<?> clazz = Class.forName("com.sun.crypto.provider.SunJCE"); - Security.addProvider((Provider)clazz.newInstance()); - } - catch (Exception ex) - { - throw new RuntimeException("Unable to load SunJCE service provider", ex); + final Provider provider = (Provider) clazz.newInstance(); + Security.addProvider(provider); + } + catch (Exception ex) + { + throw new RuntimeException("Unable to load SunJCE service provider", ex); + } } }
