Skip to content
Snippets Groups Projects
Commit 6495d823 authored by Niklas Keller's avatar Niklas Keller Committed by Thomas Holenstein
Browse files

Java: Remove e.printStracktrace() in favor of a cause (#207)

parent d0687dbf
No related branches found
No related tags found
No related merge requests found
...@@ -155,28 +155,23 @@ public final class EngineFactory<T_WRAPPER extends EngineWrapper<T_ENGINE>, T_EN ...@@ -155,28 +155,23 @@ public final class EngineFactory<T_WRAPPER extends EngineWrapper<T_ENGINE>, T_EN
} }
public T_ENGINE getInstance(String algorithm) throws GeneralSecurityException { public T_ENGINE getInstance(String algorithm) throws GeneralSecurityException {
for (Provider p : this.policy) { Exception cause = null;
if (tryProvider(algorithm, p)) { for (Provider provider : this.policy) {
return this.instanceBuilder.getInstance(algorithm, p); try {
return this.instanceBuilder.getInstance(algorithm, provider);
} catch (Exception e) {
if (cause == null) {
cause = e;
}
} }
} }
if (letFallback) { if (letFallback) {
return this.instanceBuilder.getInstance(algorithm, null); return this.instanceBuilder.getInstance(algorithm, null);
} }
throw new GeneralSecurityException("No good Provider found."); throw new GeneralSecurityException("No good Provider found.", cause);
} }
private T_WRAPPER instanceBuilder; private T_WRAPPER instanceBuilder;
private List<Provider> policy; private List<Provider> policy;
private boolean letFallback; private boolean letFallback;
private boolean tryProvider(String algorithm, Provider provider) {
try {
this.instanceBuilder.getInstance(algorithm, provider);
return true;
} catch (Exception e) { // Don't care which one specifically.
e.printStackTrace();
return false;
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment