Skip to content

Commit f108896

Browse files
Fix case where an exception (indirectly) supresses itself
1 parent de4ff9c commit f108896

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/com/amazonaws/encryptionsdk/MasterKeyProvider.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ protected AwsCryptoException buildCannotDecryptDksException(List<? extends Throw
102102
if (t == null || t.isEmpty()) {
103103
return new CannotUnwrapDataKeyException("Unable to decrypt any data keys");
104104
} else {
105-
final CannotUnwrapDataKeyException ex = new CannotUnwrapDataKeyException("Unable to decrypt any data keys",
106-
t.get(0));
105+
CannotUnwrapDataKeyException ex = null;
107106
for (final Throwable e : t) {
108-
ex.addSuppressed(e);
107+
if (ex == null) {
108+
ex = new CannotUnwrapDataKeyException("Unable to decrypt any data keys", e);
109+
} else {
110+
ex.addSuppressed(e);
111+
}
109112
}
110113
return ex;
111114
}

0 commit comments

Comments
 (0)